-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
46 lines (37 loc) · 937 Bytes
/
user_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
// SPDX-FileCopyrightText: 2023 M. Shulhan <ms@kilabit.info>
// SPDX-License-Identifier: GPL-3.0-or-later
package karajo
import (
"testing"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
func TestLoadUsers(t *testing.T) {
var (
expUsers = map[string]*User{
`test`: &User{
Name: `test`,
Password: `$2a$10$9XMRfqpnzY2421fwYm5dd.CidJf7dHHWIESeeNGXuajHRf.Lqzy7a`,
},
}
gotUsers map[string]*User
err error
)
gotUsers, err = loadUsers(`testdata/etc/karajo/user.conf`)
if err != nil {
t.Fatal(err)
}
test.Assert(t, `loadUsers`, expUsers, gotUsers)
}
func TestUser_authenticate(t *testing.T) {
var (
u = &User{
Name: `test`,
Password: `$2a$10$9XMRfqpnzY2421fwYm5dd.CidJf7dHHWIESeeNGXuajHRf.Lqzy7a`,
}
got bool
)
got = u.authenticate(`s3cr3t`)
test.Assert(t, `authenticate: invalid`, false, got)
got = u.authenticate(`s3cret`)
test.Assert(t, `authenticate: valid`, true, got)
}