forked from aarondl/authboss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_test.go
More file actions
executable file
·109 lines (90 loc) · 2.17 KB
/
context_test.go
File metadata and controls
executable file
·109 lines (90 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package authboss
import "testing"
func TestContext_SaveUser(t *testing.T) {
t.Parallel()
ab := New()
ctx := ab.NewContext()
storer := mockStorer{}
ab.Storer = storer
ctx.User = Attributes{StoreUsername: "joe", StoreEmail: "hello@joe.com", StorePassword: "mysticalhash"}
err := ctx.SaveUser()
if err != nil {
t.Error("Unexpected error:", err)
}
attr, ok := storer["hello@joe.com"]
if !ok {
t.Error("Could not find joe!")
}
for k, v := range ctx.User {
if v != attr[k] {
t.Error(v, "not equal to", ctx.User[k])
}
}
}
func TestContext_LoadUser(t *testing.T) {
t.Parallel()
ab := New()
ctx := ab.NewContext()
attr := Attributes{
"email": "hello@joe.com",
"password": "mysticalhash",
"uid": "what",
"provider": "google",
}
storer := mockStorer{
"joe": attr,
"whatgoogle": attr,
}
ab.Storer = storer
ab.OAuth2Storer = storer
ctx.User = nil
if err := ctx.LoadUser("joe"); err != nil {
t.Error("Unexpected error:", err)
}
if email, err := ctx.User.StringErr("email"); err != nil {
t.Error(err)
} else if email != attr["email"] {
t.Error("Email wrong:", email)
}
if password, err := ctx.User.StringErr("password"); err != nil {
t.Error(err)
} else if password != attr["password"] {
t.Error("Password wrong:", password)
}
ctx.User = nil
if err := ctx.LoadUser("what;google"); err != nil {
t.Error("Unexpected error:", err)
}
if email, err := ctx.User.StringErr("email"); err != nil {
t.Error(err)
} else if email != attr["email"] {
t.Error("Email wrong:", email)
}
if password, err := ctx.User.StringErr("password"); err != nil {
t.Error(err)
} else if password != attr["password"] {
t.Error("Password wrong:", password)
}
}
func TestContext_LoadSessionUser(t *testing.T) {
t.Parallel()
ab := New()
ctx := ab.NewContext()
storer := mockStorer{
"joe": Attributes{"email": "hello@joe.com", "password": "mysticalhash"},
}
ab.Storer = storer
ctx.SessionStorer = mockClientStore{
SessionKey: "joe",
}
err := ctx.LoadSessionUser()
if err != nil {
t.Error("Unexpected error:", err)
}
attr := storer["joe"]
for k, v := range attr {
if v != ctx.User[k] {
t.Error(v, "not equal to", ctx.User[k])
}
}
}