Phase 10, part 2: the first owner, from a one-time setup link
A new server prints a link to create its owner (supermarket setup-link makes another); until it's used, every page says the setup isn't finished. One-time links (schema 33) are kept as hashes and used up in one statement; resets and invitations will use them too. The server edition opens Postgres. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -221,3 +221,45 @@ func TestSessions(t *testing.T) {
|
||||
t.Errorf("pruned %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinks(t *testing.T) {
|
||||
d := openDB(t)
|
||||
now := time.Date(2026, 11, 25, 10, 0, 0, 0, time.UTC)
|
||||
a, err := NewLink(d, ResetLink, 7, now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if u, err := PeekLink(d, a, ResetLink, now); err != nil || u != 7 {
|
||||
t.Errorf("peek: %d %v", u, err)
|
||||
}
|
||||
if _, err := PeekLink(d, a, InviteLink, now); !errors.Is(err, ErrBadLink) {
|
||||
t.Error("used for another purpose")
|
||||
}
|
||||
if exp, _ := LinkExpiry(d, ResetLink, 7, now); !exp.Equal(now.Add(time.Hour)) {
|
||||
t.Errorf("expiry %v", exp)
|
||||
}
|
||||
if _, err := UseLink(d, a, ResetLink, now.Add(time.Hour)); !errors.Is(err, ErrBadLink) {
|
||||
t.Error("used after an hour")
|
||||
}
|
||||
b, _ := NewLink(d, ResetLink, 7, now)
|
||||
c, _ := NewLink(d, ResetLink, 7, now) // replaces b
|
||||
if _, err := UseLink(d, b, ResetLink, now); !errors.Is(err, ErrBadLink) {
|
||||
t.Error("replaced link worked")
|
||||
}
|
||||
if u, err := UseLink(d, c, ResetLink, now); err != nil || u != 7 {
|
||||
t.Errorf("use: %d %v", u, err)
|
||||
}
|
||||
if _, err := UseLink(d, c, ResetLink, now); !errors.Is(err, ErrBadLink) {
|
||||
t.Error("used twice")
|
||||
}
|
||||
i, _ := NewLink(d, InviteLink, 8, now)
|
||||
if err := DropLinks(d, InviteLink, 8); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := PeekLink(d, i, InviteLink, now); !errors.Is(err, ErrBadLink) {
|
||||
t.Error("withdrawn link worked")
|
||||
}
|
||||
if _, err := NewLink(d, "other", 1, now); err == nil {
|
||||
t.Error("unknown purpose")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user