Files
iam/pkg/schema/invitation_test.go
zooqueenandHanzo Dev 7dc0df21aa Join codes share the mailbox ledger, IAM mints invitation codes, and only the seed marks platform apps
A join code is claimed in the per-mailbox ledger (3 per inviting org, 20 across orgs a day) under the joining org's lock before it is sent, under a fixed subject. POST /v1/iam/invitations mints a 20-character crypto/rand code when none is given and marks it generated; only generated codes skip the per-org gate, so a typed code however strong it looks stays behind it. Names keep combining marks and an inviter without a display name is left out; an address with an empty domain label is not bare. The platform flag is written by the seed alone, on a locked fresh read.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-27 09:37:43 -07:00

82 lines
2.7 KiB
Go
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright 2026 Hanzo AI, Inc.
// SPDX-License-Identifier: MIT OR Apache-2.0
package schema
import "testing"
func TestBareAddress(t *testing.T) {
for s, want := range map[string]bool{
"[email protected]": true,
"[email protected]": true,
`"Hanzo Billing" <[email protected]>`: false,
"<[email protected]>": false,
"[email protected], [email protected]": false,
"a@[email protected]": false,
"[email protected]\r\nBcc: [email protected]": false,
"ada‮@example.com": false,
"ada@localhost": false,
"[email protected].": false,
"[email protected]": false,
"[email protected]": false,
"": false,
} {
if got := BareAddress(s); got != want {
t.Errorf("BareAddress(%q) = %v, want %v", s, got, want)
}
}
}
func TestInviteCode(t *testing.T) {
for code, ok := range map[string]bool{
"K7PQ2M9XRT": true,
"acme_team-2026": true,
"acme-7f3k": false, // nine characters
"AAAAAAAAAAAA": false, // one character, repeated
"ABABABABAB": false, // two
"K7PQ2M9XRT K7": false, // a space
"K7PQ2M9XRT/x": false, // a slash
string(make([]byte, 65)): false,
} {
if err := InviteCode(code); (err == nil) != ok {
t.Errorf("InviteCode(%q) = %v, want ok=%v", code, err, ok)
}
}
}
func TestPlainName(t *testing.T) {
for in, want := range map[string]string{
"Acme Robotics": "Acme Robotics",
"हिन्दी संगठन": "हिन्दी संगठन",
"Cafe\u0301": "Cafe\u0301",
"O'Brien & Sons (UK) - Ltd.": "O'Brien & Sons (UK) - Ltd",
"hanzo-id.example/verify": "hanzo-idexampleverify",
"https://x.example": "httpsxexample",
"[email protected]": "abcom",
"Line\r\nBcc: x": "Line Bcc x",
"<b>Bold</b>": "bBoldb",
"Ada‮Lovelace": "AdaLovelace",
" ": "",
} {
if got := PlainName(in, 60); got != want {
t.Errorf("PlainName(%q) = %q, want %q", in, got, want)
}
}
if got := PlainName("abcdefghij", 4); got != "abcd" {
t.Errorf("cut = %q", got)
}
}
func TestMailbox(t *testing.T) {
for in, want := range map[string]string{
"[email protected]": "[email protected]",
"[email protected]": "[email protected]",
"[email protected]": "[email protected]",
"[email protected]": "[email protected]",
} {
if got := Mailbox(in); got != want {
t.Errorf("Mailbox(%q) = %q, want %q", in, got, want)
}
}
}