@@ -10277,7 +10277,7 @@ func TestLeafNodesDisableRemote(t *testing.T) {
10277
10277
require_Equal (t , string (msg .Data ), "hello4" )
10278
10278
}
10279
10279
10280
- func TestLeafNodeIsolatedLeafSubjectPropagation (t * testing.T ) {
10280
+ func TestLeafNodeIsolatedLeafSubjectPropagationGlobal (t * testing.T ) {
10281
10281
for tname , isolated := range map [string ]bool {
10282
10282
"Isolated" : true ,
10283
10283
"Normal" : false ,
@@ -10326,6 +10326,221 @@ func TestLeafNodeIsolatedLeafSubjectPropagation(t *testing.T) {
10326
10326
checkLeafNodeConnectedCount (t , sp1 , 1 )
10327
10327
checkLeafNodeConnectedCount (t , sp2 , 1 )
10328
10328
10329
+ // We expect that the hub side will have answered the request from the spoke for
10330
+ // isolation if needed, but the spokes themselves will not themselves isolate
10331
+ // subscription interest in the other direction unless also configured to do so.
10332
+ for _ , c := range sh .leafs {
10333
+ require_Equal (t , c .leaf .isolated , isolated )
10334
+ }
10335
+ for _ , c := range sp1 .leafs {
10336
+ require_False (t , c .leaf .isolated )
10337
+ }
10338
+ for _ , c := range sp2 .leafs {
10339
+ require_False (t , c .leaf .isolated )
10340
+ }
10341
+
10342
+ nch := natsConnect (t , sh .ClientURL (), nats .UserInfo ("HA" , "pwd" ))
10343
+ nc1 := natsConnect (t , sp1 .ClientURL (), nats .UserInfo ("A" , "pwd" ))
10344
+
10345
+ // Create a north-south subscription on the hub that should be visible to both spokes.
10346
+ nssub , err := nch .SubscribeSync ("northsouth" )
10347
+ require_NoError (t , err )
10348
+ checkSubInterest (t , sh , "HA" , "northsouth" , time .Second ) // Visible to the hub.
10349
+ checkSubInterest (t , sp1 , "A" , "northsouth" , time .Second ) // Visible to both spokes.
10350
+ checkSubInterest (t , sp2 , "A" , "northsouth" , time .Second ) // Visible to both spokes.
10351
+
10352
+ // The spoke subscriptions should be visible to the hub in all cases, but only
10353
+ // visible to other spokes if they are not isolated.
10354
+ ewsub , err := nc1 .SubscribeSync ("eastwest" )
10355
+ require_NoError (t , err )
10356
+ checkSubInterest (t , sh , "HA" , "eastwest" , time .Second ) // Visible to the hub.
10357
+ checkSubInterest (t , sp1 , "A" , "eastwest" , time .Second ) // Visible to the spoke with the sub.
10358
+ if isolated {
10359
+ checkSubNoInterest (t , sp2 , "A" , "eastwest" , time .Second ) // Not visible to the other spoke.
10360
+ } else {
10361
+ checkSubInterest (t , sp2 , "A" , "eastwest" , time .Second ) // Visible to the other spoke.
10362
+ }
10363
+ require_NoError (t , ewsub .Unsubscribe ())
10364
+ checkSubNoInterest (t , sh , "HA" , "eastwest" , time .Second )
10365
+ checkSubNoInterest (t , sp1 , "A" , "eastwest" , time .Second )
10366
+ checkSubNoInterest (t , sp2 , "A" , "eastwest" , time .Second )
10367
+
10368
+ // ... but a subscription from the hub should be visible to both.
10369
+ require_NoError (t , nssub .Unsubscribe ())
10370
+ checkSubNoInterest (t , sh , "HA" , "northsouth" , time .Second )
10371
+ checkSubNoInterest (t , sp1 , "A" , "northsouth" , time .Second )
10372
+ checkSubNoInterest (t , sp2 , "A" , "northsouth" , time .Second )
10373
+ })
10374
+ }
10375
+ }
10376
+
10377
+ func TestLeafNodeIsolatedLeafSubjectPropagationRequestIsolation (t * testing.T ) {
10378
+ for tname , isolated := range map [string ]bool {
10379
+ "Isolated" : true ,
10380
+ "Normal" : false ,
10381
+ } {
10382
+ t .Run (tname , func (t * testing.T ) {
10383
+ hubTmpl := `
10384
+ port: -1
10385
+ server_name: "%s"
10386
+ accounts {
10387
+ HA { users: [{user: HA, password: pwd}] }
10388
+ }
10389
+ leafnodes {
10390
+ port: -1
10391
+ }
10392
+ `
10393
+ confH := createConfFile (t , []byte (fmt .Sprintf (hubTmpl , "H1" )))
10394
+ sh , oh := RunServerWithConfig (confH )
10395
+ defer sh .Shutdown ()
10396
+
10397
+ spokeTmpl := `
10398
+ port: -1
10399
+ server_name: "%s"
10400
+ accounts {
10401
+ A { users: [{user: A, password: pwd}] }
10402
+ }
10403
+ leafnodes {
10404
+ remotes [
10405
+ {
10406
+ url: "nats://HA:[email protected] :%d"
10407
+ local: "A"
10408
+ request_isolation: %v
10409
+ }
10410
+ ]
10411
+ }
10412
+ `
10413
+
10414
+ confSP1 := createConfFile (t , []byte (fmt .Sprintf (spokeTmpl , "SP1" , oh .LeafNode .Port , isolated )))
10415
+ sp1 , _ := RunServerWithConfig (confSP1 )
10416
+ defer sp1 .Shutdown ()
10417
+
10418
+ confSP2 := createConfFile (t , []byte (fmt .Sprintf (spokeTmpl , "SP2" , oh .LeafNode .Port , isolated )))
10419
+ sp2 , _ := RunServerWithConfig (confSP2 )
10420
+ defer sp2 .Shutdown ()
10421
+
10422
+ checkLeafNodeConnectedCount (t , sh , 2 )
10423
+ checkLeafNodeConnectedCount (t , sp1 , 1 )
10424
+ checkLeafNodeConnectedCount (t , sp2 , 1 )
10425
+
10426
+ // We expect that the hub side will have answered the request from the spoke for
10427
+ // isolation if needed, but the spokes themselves will not themselves isolate
10428
+ // subscription interest in the other direction unless also configured to do so.
10429
+ for _ , c := range sh .leafs {
10430
+ require_Equal (t , c .leaf .isolated , isolated )
10431
+ }
10432
+ for _ , c := range sp1 .leafs {
10433
+ require_False (t , c .leaf .isolated )
10434
+ }
10435
+ for _ , c := range sp2 .leafs {
10436
+ require_False (t , c .leaf .isolated )
10437
+ }
10438
+
10439
+ nch := natsConnect (t , sh .ClientURL (), nats .UserInfo ("HA" , "pwd" ))
10440
+ nc1 := natsConnect (t , sp1 .ClientURL (), nats .UserInfo ("A" , "pwd" ))
10441
+
10442
+ // Create a north-south subscription on the hub that should be visible to both spokes.
10443
+ nssub , err := nch .SubscribeSync ("northsouth" )
10444
+ require_NoError (t , err )
10445
+ checkSubInterest (t , sh , "HA" , "northsouth" , time .Second ) // Visible to the hub.
10446
+ checkSubInterest (t , sp1 , "A" , "northsouth" , time .Second ) // Visible to both spokes.
10447
+ checkSubInterest (t , sp2 , "A" , "northsouth" , time .Second ) // Visible to both spokes.
10448
+
10449
+ // The spoke subscriptions should be visible to the hub in all cases, but only
10450
+ // visible to other spokes if they are not isolated.
10451
+ ewsub , err := nc1 .SubscribeSync ("eastwest" )
10452
+ require_NoError (t , err )
10453
+ checkSubInterest (t , sh , "HA" , "eastwest" , time .Second ) // Visible to the hub.
10454
+ checkSubInterest (t , sp1 , "A" , "eastwest" , time .Second ) // Visible to the spoke with the sub.
10455
+ if isolated {
10456
+ checkSubNoInterest (t , sp2 , "A" , "eastwest" , time .Second ) // Not visible to the other spoke.
10457
+ } else {
10458
+ checkSubInterest (t , sp2 , "A" , "eastwest" , time .Second ) // Visible to the other spoke.
10459
+ }
10460
+ require_NoError (t , ewsub .Unsubscribe ())
10461
+ checkSubNoInterest (t , sh , "HA" , "eastwest" , time .Second )
10462
+ checkSubNoInterest (t , sp1 , "A" , "eastwest" , time .Second )
10463
+ checkSubNoInterest (t , sp2 , "A" , "eastwest" , time .Second )
10464
+
10465
+ // ... but a subscription from the hub should be visible to both.
10466
+ require_NoError (t , nssub .Unsubscribe ())
10467
+ checkSubNoInterest (t , sh , "HA" , "northsouth" , time .Second )
10468
+ checkSubNoInterest (t , sp1 , "A" , "northsouth" , time .Second )
10469
+ checkSubNoInterest (t , sp2 , "A" , "northsouth" , time .Second )
10470
+ })
10471
+ }
10472
+ }
10473
+
10474
+ func TestLeafNodeIsolatedLeafSubjectPropagationLocalIsolation (t * testing.T ) {
10475
+ for tname , isolated := range map [string ]bool {
10476
+ "Isolated" : true ,
10477
+ "Normal" : false ,
10478
+ } {
10479
+ t .Run (tname , func (t * testing.T ) {
10480
+ spokeTmpl := `
10481
+ port: -1
10482
+ server_name: "%s"
10483
+ accounts {
10484
+ A { users: [{user: A, password: pwd}] }
10485
+ }
10486
+ leafnodes {
10487
+ port: -1
10488
+ }
10489
+ `
10490
+
10491
+ confSP1 := createConfFile (t , []byte (fmt .Sprintf (spokeTmpl , "SP1" )))
10492
+ sp1 , osp1 := RunServerWithConfig (confSP1 )
10493
+ defer sp1 .Shutdown ()
10494
+
10495
+ confSP2 := createConfFile (t , []byte (fmt .Sprintf (spokeTmpl , "SP2" )))
10496
+ sp2 , osp2 := RunServerWithConfig (confSP2 )
10497
+ defer sp2 .Shutdown ()
10498
+
10499
+ hubTmpl := `
10500
+ port: -1
10501
+ server_name: "%s"
10502
+ accounts {
10503
+ HA { users: [{user: HA, password: pwd}] }
10504
+ }
10505
+ leafnodes {
10506
+ port: -1
10507
+ remotes [
10508
+ {
10509
+ url: "nats://A:[email protected] :%d"
10510
+ local: "HA"
10511
+ isolate: %v
10512
+ hub: true
10513
+ },
10514
+ {
10515
+ url: "nats://A:[email protected] :%d"
10516
+ local: "HA"
10517
+ isolate: %v
10518
+ hub: true
10519
+ }
10520
+ ]
10521
+ }
10522
+ `
10523
+ confH := createConfFile (t , []byte (fmt .Sprintf (hubTmpl , "H1" , osp1 .LeafNode .Port , isolated , osp2 .LeafNode .Port , isolated )))
10524
+ sh , _ := RunServerWithConfig (confH )
10525
+ defer sh .Shutdown ()
10526
+
10527
+ checkLeafNodeConnectedCount (t , sh , 2 )
10528
+ checkLeafNodeConnectedCount (t , sp1 , 1 )
10529
+ checkLeafNodeConnectedCount (t , sp2 , 1 )
10530
+
10531
+ // We expect that the hub side will have answered the request from the spoke for
10532
+ // isolation if needed, but the spokes themselves will not themselves isolate
10533
+ // subscription interest in the other direction unless also configured to do so.
10534
+ for _ , c := range sh .leafs {
10535
+ require_Equal (t , c .leaf .isolated , isolated )
10536
+ }
10537
+ for _ , c := range sp1 .leafs {
10538
+ require_False (t , c .leaf .isolated )
10539
+ }
10540
+ for _ , c := range sp2 .leafs {
10541
+ require_False (t , c .leaf .isolated )
10542
+ }
10543
+
10329
10544
nch := natsConnect (t , sh .ClientURL (), nats .UserInfo ("HA" , "pwd" ))
10330
10545
nc1 := natsConnect (t , sp1 .ClientURL (), nats .UserInfo ("A" , "pwd" ))
10331
10546
0 commit comments