-
Notifications
You must be signed in to change notification settings - Fork 0
/
hibp_test.go
77 lines (71 loc) · 1.41 KB
/
hibp_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package hibp
import (
"testing"
"github.com/gofrs/uuid"
)
func Test_asHashes(t *testing.T) {
tests := []struct {
name string
pw string
wantPrefix string
wantSuffix string
}{
{
name: "pass123",
pw: "pass123",
wantPrefix: "aafdc",
wantSuffix: "23870ecbcd3d557b6423a8982134e17927e",
},
{
name: "alk4f2355f2d45d4f",
pw: "alk4f2355f2d45d4f",
wantPrefix: "2084a",
wantSuffix: "389b33471898ad8ee44b47ed98ff2856053",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1 := asHashes(tt.pw)
if got != tt.wantPrefix {
t.Errorf("asHashes() got = %v, wantPrefix %v", got, tt.wantPrefix)
}
if got1 != tt.wantSuffix {
t.Errorf("asHashes() got1 = %v, wantPrefix %v", got1, tt.wantSuffix)
}
})
}
}
func TestIsPwned(t *testing.T) {
validPw, _ := uuid.NewV4()
tests := []struct {
name string
pw string
want bool
wantErr bool
}{
{
name: "pwned password",
pw: "pass123",
want: true,
wantErr: false,
},
{
name: "good password",
pw: validPw.String(),
want: false,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := IsPwned(tt.pw)
if (err != nil) != tt.wantErr {
t.Errorf("IsPwned() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("IsPwned() got = %v, want %v", got, tt.want)
}
})
}
}