-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsha384_hasher_test.go
59 lines (47 loc) · 1.71 KB
/
sha384_hasher_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
package hasher
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSHA384Hasher_String(t *testing.T) {
salt := "salt"
iter := 1
h := SHA384Hasher{Salt: &salt, Iter: &iter}
h.SetPassword("password")
w := string([]byte{0xf4, 0xbd, 0xac, 0x98, 0x60, 0xc0, 0xce, 0xea, 0x69, 0xfb, 0x29, 0xef, 0xbc, 0xe2, 0x4a, 0xdd, 0xca, 0x5c, 0xf1, 0xf8, 0x8, 0x92, 0x5d, 0x94, 0x33, 0xb6, 0x68, 0x52, 0x82, 0x90, 0xd5, 0xd2, 0xc9, 0x8, 0xf, 0x32, 0x34, 0x21, 0x75, 0xb5, 0x12, 0x48, 0x95, 0x68, 0x4d, 0xb8, 0xba, 0x4f})
g := h.String()
assert.Equal(t, w, g)
h = SHA384Hasher{Salt: &salt, Iter: &iter}
assert.Panics(t, assert.PanicTestFunc(func() {
_ = h.String()
}))
}
func TestSHA384Hasher_Check(t *testing.T) {
salt := "salt"
iter := 1
h := SHA384Hasher{Salt: &salt, Iter: &iter}
h.SetPassword("password")
check := h.Check("password")
assert.Truef(t, check, "Passwords are equal")
check = h.Check("password2")
assert.Falsef(t, check, "Passwords are not equal")
}
func TestSHA384Hasher_Hash(t *testing.T) {
salt := "salt"
iter := 1
password := []byte{0xf4, 0xbd, 0xac, 0x98, 0x60, 0xc0, 0xce, 0xea, 0x69, 0xfb, 0x29, 0xef, 0xbc, 0xe2, 0x4a, 0xdd, 0xca, 0x5c, 0xf1, 0xf8, 0x8, 0x92, 0x5d, 0x94, 0x33, 0xb6, 0x68, 0x52, 0x82, 0x90, 0xd5, 0xd2, 0xc9, 0x8, 0xf, 0x32, 0x34, 0x21, 0x75, 0xb5, 0x12, 0x48, 0x95, 0x68, 0x4d, 0xb8, 0xba, 0x4f}
h := SHA384Hasher{Salt: &salt, Iter: &iter}
g := h.Hash("password")
assert.Equal(t, password, g)
}
func TestSHA384Hasher_Hash_Empty(t *testing.T) {
h := SHA384Hasher{}
h.Hash("password")
assert.NotNil(t, h.Iter)
assert.NotNil(t, h.Salt)
}
func TestSHA384Hasher_SetPassword(t *testing.T) {
h := SHA384Hasher{}
h.SetPassword("password")
assert.NotNil(t, h.Password)
}