-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto_test.go
More file actions
57 lines (52 loc) · 989 Bytes
/
crypto_test.go
File metadata and controls
57 lines (52 loc) · 989 Bytes
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
package userauth
import (
"github.com/google/go-cmp/cmp"
"testing"
)
func TestCheckHash(t *testing.T) {
tcs := []struct {
name string
in string
hash string
}{
{
name: "bcrypt",
in: "demo",
hash: "$2y$10$ats.g6F4WE1rSeHFqjTIvOArZ7QwQet14gm.g89iRSR7VsrFZDSJq",
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
got, err := CheckPass(tc.in, tc.hash)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(got, true); diff != "" {
t.Errorf("expec hash to be valid")
}
})
}
}
func TestCheckHashErrs(t *testing.T) {
tcs := []struct {
name string
in string
hash string
err string
}{
{
name: "plaintext",
in: "demo",
hash: "demo",
err: "unknown crypto algorithm",
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
_, err := CheckPass(tc.in, tc.hash)
if diff := cmp.Diff(err.Error(), tc.err); diff != "" {
t.Errorf("unexpected error: \n%s", diff)
}
})
}
}