internal/control/signupverify_test.go

main
gitbay/internal/control/signupverify_test.go

48 lines · 1356 bytes

1 symbol in this file
 1package control
 2
 3import (
 4	"testing"
 5	"time"
 6
 7	"gitbay.org/gitbay/internal/config"
 8	"gitbay.org/gitbay/internal/store"
 9)
10
11// A code minted by `email add` on an active account does not sign in
12// through the signup screen; a pending signup's code does.
13func TestVerifyPendingSignupOnlyPending(t *testing.T) {
14	st, err := store.Open(":memory:")
15	if err != nil {
16		t.Fatal(err)
17	}
18	defer st.Close()
19	if err := st.MigrateUp(); err != nil {
20		t.Fatal(err)
21	}
22
23	active, err := st.CreateUser("alice", false)
24	if err != nil {
25		t.Fatal(err)
26	}
27	if err := st.AddEmail(active, "bob@example.test", "", false); err != nil {
28		t.Fatal(err)
29	}
30	if err := st.CreateEmailToken(active, "bob@example.test", store.HashToken("c0de"), time.Hour); err != nil {
31		t.Fatal(err)
32	}
33	if _, msg := VerifyPendingSignup(config.Config{}, st, "alice", "c0de"); msg == "" {
34		t.Fatal("active account signed in with an email-add code")
35	}
36
37	pending, err := st.RegisterOpen("carol", "carol@example.test", "SHA256:x", "ssh-ed25519", []byte("blob"))
38	if err != nil {
39		t.Fatal(err)
40	}
41	if err := st.CreateEmailToken(pending, "carol@example.test", store.HashToken("f00d"), time.Hour); err != nil {
42		t.Fatal(err)
43	}
44	u, msg := VerifyPendingSignup(config.Config{}, st, "carol", "f00d")
45	if msg != "" || u.ID != pending || u.Pending {
46		t.Fatalf("pending signup: user %+v, msg %q", u, msg)
47	}
48}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form