-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_test.go
54 lines (44 loc) · 1.29 KB
/
auth_test.go
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
package hutplate
import (
"testing"
)
func TestAuth_LoginWithValidCredsAndLogout(t *testing.T) {
hut := SetupLoggingInAndGetHut(t)
hut.Auth.Login("[email protected]", "1234567890")
got := hut.Auth.UserId()
if got != 2 {
t.Errorf("invalid user id expected 2 got %v", got)
}
if !hut.Auth.Check() {
t.Error("user logging in failed")
}
hut.Auth.Logout()
if hut.Auth.Check() {
t.Error("user logout failed")
}
if hut.Auth.UserId() != nil {
t.Error("invalid user id after logout")
}
}
func TestAuth_LoginWithInvalidCreds(t *testing.T) {
hut := SetupLoggingInAndGetHut(t)
hut.Auth.Login("[email protected]", "123456789F")
if hut.Auth.Check() || hut.Auth.UserId() != nil {
t.Error("user logged in even after invalid password")
}
hut.Auth.Login("[email protected]", "1234567890")
if hut.Auth.Check() || hut.Auth.UserId() != nil {
t.Error("user logged in even after invalid email")
}
}
func SetupLoggingInAndGetHut(t *testing.T) Http {
Config.GetUserWithCred = func(credential interface{}) (interface{}, string) {
if credential == "[email protected]" {
// Hash of 1234567890
hashedPassword := "$2a$14$KYv4f668vfwQy/0/OjRWD.cQtXiK1XPF/XMTZXZxyXmHq5ULjqleu"
return 2, hashedPassword
}
return nil, ""
}
return GetARequest(t)
}