This repository was archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathusers_test.go
More file actions
75 lines (67 loc) · 1.33 KB
/
Copy pathusers_test.go
File metadata and controls
75 lines (67 loc) · 1.33 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
package core
import (
"testing"
)
const EMAIL = "user@example.com"
const PASSWD = "password"
const PASSWD_HASH = "randomhash"
const PASSWD_SALT = "randomsalt"
func TestAuth(t *testing.T) {
testSuites := []struct {
password string
active bool
expected bool
}{
{PASSWD, true, true},
{PASSWD, false, false},
{PASSWD + ".", true, false},
}
for _, testData := range testSuites {
user := User{
Active: testData.active,
Email: EMAIL,
}
err := user.CreatePassword(PASSWD)
if err != nil {
t.Fatal(err)
}
result := user.AuthPassword(testData.password)
if result != testData.expected {
t.Fatalf("Expected: %t, got: %t", testData.expected, result)
}
}
}
func TestUserValidation(t *testing.T) {
testSuites := []struct {
user User
expected []ValidationError
}{
{
User{
Active: true,
Email: EMAIL,
Password: []byte(PASSWD_HASH),
Salt: []byte(PASSWD_SALT),
},
[]ValidationError{},
},
{
User{
Active: true,
Email: "notanemail",
Password: []byte(PASSWD_HASH),
Salt: []byte(PASSWD_SALT),
},
[]ValidationError{
ValidationError{
Code: ErrTypeMismatch,
Field: "Email",
},
},
},
}
for index, testData := range testSuites {
result := testData.user.Validate()
testValidation(testData.expected, result, index, t)
}
}