Let a process read the router's record of its module's own ask (issue 1189)

This commit is contained in:
jochen
2026-10-19 04:35:33 +02:00
parent de2d944c2a
commit 94702bcd79
3 changed files with 156 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
package process
import "testing"
// 1189/AC2: given an ask id holding a dot or a wildcard, when read, then it is refused before anything is
// sent — proven on a Conn with no live connection at all: if Ask tried to send, it would panic on the nil
// *nats.Conn instead of returning a clean error.
func TestAskRefusesAnInvalidIDBeforeSendingAnything(t *testing.T) {
c := &Conn{account: Account{Module: "mesh-mail"}}
for _, id := range []string{"", "a.b", "a*", "a>", "ask.1", "ask.*"} {
if _, err := c.Ask("messenger_asks", id); err == nil {
t.Errorf("Ask(%q) was not refused", id)
}
}
}
func TestCheckAskID(t *testing.T) {
for _, id := range []string{"", "a.b", "a*b", "a>b", ".", "*"} {
if err := checkAskID(id); err == nil {
t.Errorf("checkAskID(%q) was accepted", id)
}
}
for _, id := range []string{"ask-1", "a1b2c3", "send_42"} {
if err := checkAskID(id); err != nil {
t.Errorf("checkAskID(%q) was refused: %v", id, err)
}
}
}