package broker import ( "testing" ) // Which bus the mesh is on is one fact, and being told about both is refused. // // The controller's own credential arrives in its address, and has to be readable out of it — its user // is created by the installer at a bootstrap password, before the controller exists to mint one. func TestACredentialIsReadOutOfABusAddress(t *testing.T) { for _, c := range []struct{ in, user, password, bare string }{ {"nats://controller:secret@127.0.0.1:4222", "controller", "secret", "nats://127.0.0.1:4222"}, {"controller:secret@127.0.0.1:4222", "controller", "secret", "127.0.0.1:4222"}, {"nats://127.0.0.1:4222", "", "", "nats://127.0.0.1:4222"}, {"127.0.0.1:4222", "", "", "127.0.0.1:4222"}, // A password containing an at-sign: split on the last one, or the address becomes part of the // credential and the connection goes somewhere nobody named. {"nats://controller:a@b@127.0.0.1:4222", "controller", "a@b", "nats://127.0.0.1:4222"}, } { user, password, bare := CredentialIn(c.in) if user != c.user || password != c.password || bare != c.bare { t.Errorf("%q read as %q/%q at %q; wanted %q/%q at %q", c.in, user, password, bare, c.user, c.password, c.bare) } } }