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) } } }