forked from aarondl/authboss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthboss_test.go
More file actions
48 lines (40 loc) · 1.01 KB
/
Copy pathauthboss_test.go
File metadata and controls
48 lines (40 loc) · 1.01 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
package authboss
import (
"net/http"
"net/http/httptest"
"os"
"testing"
)
func TestMain(main *testing.M) {
RegisterModule("testmodule", testMod)
Init()
code := main.Run()
os.Exit(code)
}
func TestAuthBossInit(t *testing.T) {
NewConfig()
err := Init()
if err != nil {
t.Error("Unexpected error:", err)
}
}
func TestAuthBossCurrentUser(t *testing.T) {
NewConfig()
Cfg.Storer = mockStorer{"joe": Attributes{"email": "john@john.com", "password": "lies"}}
Cfg.SessionStoreMaker = func(_ http.ResponseWriter, _ *http.Request) ClientStorer {
return mockClientStore{SessionKey: "joe"}
}
Cfg.CookieStoreMaker = func(_ http.ResponseWriter, _ *http.Request) ClientStorer {
return mockClientStore{}
}
if err := Init(); err != nil {
t.Error("Unexpected error:", err)
}
rec := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "localhost", nil)
userStruct := CurrentUserP(rec, req)
us := userStruct.(*mockUser)
if us.Email != "john@john.com" || us.Password != "lies" {
t.Error("Wrong user found!")
}
}