@@ -6539,6 +6539,22 @@ func TestConfigReloadGetLeafNodeOptionsChanges(t *testing.T) {
65396539 LocalAccount : "A" ,
65406540 }
65416541
6542+ addedRemoteDueToDifferentAccount := & RemoteLeafOpts {
6543+ URLs : []* url.URL {u },
6544+ Compression : CompressionOpts {Mode : CompressionS2Fast },
6545+ LocalAccount : "A" ,
6546+ }
6547+ addedRemoteDueToDifferentCreds := & RemoteLeafOpts {
6548+ URLs : []* url.URL {u },
6549+ Compression : CompressionOpts {Mode : CompressionS2Fast },
6550+ Credentials : "credsfile" ,
6551+ }
6552+ addedRemoteDueToDifferentNkey := & RemoteLeafOpts {
6553+ URLs : []* url.URL {u },
6554+ Compression : CompressionOpts {Mode : CompressionS2Fast },
6555+ Credentials : "SUACJN3OSKWWPQXME4JUNFJ3PARXPO657GGNWNU7PK7G3AUQQYHLW26XH4" ,
6556+ }
6557+
65426558 acc1 := & Account {Name : "A1" }
65436559 acc2 := & Account {Name : "A2" }
65446560
@@ -6919,6 +6935,81 @@ func TestConfigReloadGetLeafNodeOptionsChanges(t *testing.T) {
69196935 },
69206936 _EMPTY_ ,
69216937 },
6938+ {
6939+ "remote added due to different account" ,
6940+ func () (* Server , * LeafNodeOpts , * LeafNodeOpts ) {
6941+ ts := & Server {}
6942+ ts .leafRemoteCfgs = maps .Clone (s .leafRemoteCfgs )
6943+ old := & LeafNodeOpts {
6944+ Users : []* User {{Username : "a" , Password : "pwd" }},
6945+ Compression : CompressionOpts {Mode : CompressionS2Fast },
6946+ Remotes : []* RemoteLeafOpts {remote },
6947+ }
6948+ new := & LeafNodeOpts {
6949+ Users : []* User {{Username : "a" , Password : "pwd" }},
6950+ Compression : CompressionOpts {Mode : CompressionS2Fast },
6951+ // At the same time, change tls first for the LeafNodeOpts block.
6952+ TLSHandshakeFirst : true ,
6953+ Remotes : []* RemoteLeafOpts {addedRemoteDueToDifferentAccount },
6954+ }
6955+ return ts , old , new
6956+ },
6957+ & leafNodeOption {
6958+ tlsFirstChanged : true ,
6959+ added : []* RemoteLeafOpts {addedRemoteDueToDifferentAccount },
6960+ },
6961+ _EMPTY_ ,
6962+ },
6963+ {
6964+ "remote added due to different creds" ,
6965+ func () (* Server , * LeafNodeOpts , * LeafNodeOpts ) {
6966+ ts := & Server {}
6967+ ts .leafRemoteCfgs = maps .Clone (s .leafRemoteCfgs )
6968+ old := & LeafNodeOpts {
6969+ Users : []* User {{Username : "a" , Password : "pwd" }},
6970+ Compression : CompressionOpts {Mode : CompressionS2Fast },
6971+ Remotes : []* RemoteLeafOpts {remote },
6972+ }
6973+ new := & LeafNodeOpts {
6974+ Users : []* User {{Username : "a" , Password : "pwd" }},
6975+ Compression : CompressionOpts {Mode : CompressionS2Fast },
6976+ // At the same time, change tls first for the LeafNodeOpts block.
6977+ TLSHandshakeFirst : true ,
6978+ Remotes : []* RemoteLeafOpts {addedRemoteDueToDifferentCreds },
6979+ }
6980+ return ts , old , new
6981+ },
6982+ & leafNodeOption {
6983+ tlsFirstChanged : true ,
6984+ added : []* RemoteLeafOpts {addedRemoteDueToDifferentCreds },
6985+ },
6986+ _EMPTY_ ,
6987+ },
6988+ {
6989+ "remote added due to different nkey" ,
6990+ func () (* Server , * LeafNodeOpts , * LeafNodeOpts ) {
6991+ ts := & Server {}
6992+ ts .leafRemoteCfgs = maps .Clone (s .leafRemoteCfgs )
6993+ old := & LeafNodeOpts {
6994+ Users : []* User {{Username : "a" , Password : "pwd" }},
6995+ Compression : CompressionOpts {Mode : CompressionS2Fast },
6996+ Remotes : []* RemoteLeafOpts {remote },
6997+ }
6998+ new := & LeafNodeOpts {
6999+ Users : []* User {{Username : "a" , Password : "pwd" }},
7000+ Compression : CompressionOpts {Mode : CompressionS2Fast },
7001+ // At the same time, change tls first for the LeafNodeOpts block.
7002+ TLSHandshakeFirst : true ,
7003+ Remotes : []* RemoteLeafOpts {addedRemoteDueToDifferentNkey },
7004+ }
7005+ return ts , old , new
7006+ },
7007+ & leafNodeOption {
7008+ tlsFirstChanged : true ,
7009+ added : []* RemoteLeafOpts {addedRemoteDueToDifferentNkey },
7010+ },
7011+ _EMPTY_ ,
7012+ },
69227013 } {
69237014 t .Run (test .name , func (t * testing.T ) {
69247015 s , old , new := test .genCfg ()
@@ -7122,7 +7213,7 @@ func TestConfigReloadAddRemoveRemoteLeafNodes(t *testing.T) {
71227213 accA := fmt .Sprintf (remoteTmpl , "A" )
71237214 accB := fmt .Sprintf (remoteTmpl , "B" )
71247215 accC := fmt .Sprintf (remoteTmpl , "C" )
7125- conf2 := createConfFile (t , [] byte ( fmt .Sprintf ( tmpl2 , accA , _EMPTY_ , _EMPTY_ ) ))
7216+ conf2 := createConfFile (t , fmt .Appendf ( nil , tmpl2 , accA , _EMPTY_ , _EMPTY_ ))
71267217 s2 , _ := RunServerWithConfig (conf2 )
71277218 defer s2 .Shutdown ()
71287219
@@ -7168,6 +7259,46 @@ func TestConfigReloadAddRemoveRemoteLeafNodes(t *testing.T) {
71687259 checkLeafs (nil )
71697260}
71707261
7262+ func TestConfigReloadRemoteLeafNodeNkeyChange (t * testing.T ) {
7263+ conf1 := createConfFile (t , []byte (`
7264+ listen: "127.0.0.1:-1"
7265+ server_name: "A"
7266+ leaf {
7267+ listen: 127.0.0.1:-1
7268+ authorization: { nkey: UCSTG5CRF5GEJERAFKUUYRODGABTBVWY2NPE4GGKRQVQOH74PIAKTVKO }
7269+ }
7270+ ` ))
7271+ s1 , o1 := RunServerWithConfig (conf1 )
7272+ defer s1 .Shutdown ()
7273+
7274+ tmpl2 := `
7275+ listen: "127.0.0.1:-1"
7276+ server_name: "B"
7277+ leaf {
7278+ reconnect_interval: "50ms"
7279+ remotes: [
7280+ {
7281+ url: "nats-leaf://127.0.0.1:%d"
7282+ nkey: %s
7283+ }
7284+ ]
7285+ }
7286+ `
7287+ conf2 := createConfFile (t , fmt .Appendf (nil , tmpl2 , o1 .LeafNode .Port ,
7288+ "SUAPM67TC4RHQLKBX55NIQXSMATZDOZK6FNEOSS36CAYA7F7TY66LP4BOM" ))
7289+ s2 , _ := RunServerWithConfig (conf2 )
7290+ defer s2 .Shutdown ()
7291+
7292+ // Should not be able to connect...
7293+ time .Sleep (70 * time .Millisecond )
7294+ checkLeafNodeConnectedCount (t , s2 , 0 )
7295+
7296+ reloadUpdateConfig (t , s2 , conf2 , fmt .Sprintf (tmpl2 , o1 .LeafNode .Port ,
7297+ "SUACJN3OSKWWPQXME4JUNFJ3PARXPO657GGNWNU7PK7G3AUQQYHLW26XH4" ))
7298+
7299+ checkLeafNodeConnectedCount (t , s2 , 1 )
7300+ }
7301+
71717302func TestConfigReloadNoPanicOnShutdown (t * testing.T ) {
71727303 tmpl := `
71737304 port: -1
0 commit comments