From 1815fd11b9634396855d4cb58537dea35b50c455 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 5 Nov 2026 17:04:01 +0100 Subject: [PATCH] =?UTF-8?q?membership:=20CredentialIn=20and=20BareAddress?= =?UTF-8?q?=20go,=20no=20caller=20in=20any=20tree=20(ADR=200635=20=C2=A74;?= =?UTF-8?q?=20issue=201966)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i --- go/membership/membership.go | 30 ------------------------------ go/membership/membership_test.go | 20 -------------------- 2 files changed, 50 deletions(-) diff --git a/go/membership/membership.go b/go/membership/membership.go index 4f957cb..38e225c 100644 --- a/go/membership/membership.go +++ b/go/membership/membership.go @@ -6,7 +6,6 @@ package membership import ( "encoding/json" - "strings" "git.novox.be/novox/mesh-sdk/go/catalogue" ) @@ -172,32 +171,3 @@ type WaitIssued struct { Event string `json:"event"` Subject string `json:"subject"` } - -// CredentialIn reads the credential out of a bus address, `[scheme://]user:password@host:port`, splitting on -// the last at-sign so a password containing one stays whole, and returns the address without it. -func CredentialIn(address string) (user, password, bare string) { - at := strings.LastIndex(address, "@") - if at < 0 { - return "", "", address - } - scheme := "" - rest := address[:at] - if i := strings.Index(rest, "://"); i >= 0 { - scheme, rest = rest[:i+3], rest[i+3:] - } - user, password, _ = strings.Cut(rest, ":") - return user, password, scheme + address[at+1:] -} - -// BareAddress is a bus address with any credential stripped, for something that only needs to know -// whether a server is answering there. -func BareAddress(address string) string { - _, _, bare := CredentialIn(address) - if bare == "" { - return address - } - if strings.Contains(bare, "://") { - return bare - } - return "nats://" + bare -} diff --git a/go/membership/membership_test.go b/go/membership/membership_test.go index e80d346..555f19c 100644 --- a/go/membership/membership_test.go +++ b/go/membership/membership_test.go @@ -8,26 +8,6 @@ import ( "git.novox.be/novox/mesh-sdk/go/catalogue" ) -// A credential is read out of a bus address, and the bare address carries no credential and a scheme. -func TestACredentialIsReadOutOfABusAddress(t *testing.T) { - for _, c := range []struct{ in, user, password, bare, schemed string }{ - {"nats://controller:secret@127.0.0.1:4222", "controller", "secret", "nats://127.0.0.1:4222", "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", "", "", "nats://127.0.0.1:4222", "nats://127.0.0.1:4222"}, - {"127.0.0.1:4222", "", "", "127.0.0.1:4222", "nats://127.0.0.1:4222"}, - // A password containing an at-sign: split on the last one. - {"nats://controller:a@b@127.0.0.1:4222", "controller", "a@b", "nats://127.0.0.1:4222", "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) - } - if got := BareAddress(c.in); got != c.schemed { - t.Errorf("BareAddress(%q) = %q, want %q", c.in, got, c.schemed) - } - } -} - func TestAMembershipIsPublishedAndReadAtTheSubjectDerivedFromTheTwoNames(t *testing.T) { if got := Subject("ace", "route-proxy"); got != "mesh.assignment.ace.route-proxy" { t.Errorf("subject: %q", got)