-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsha512_hasher_test.go
59 lines (47 loc) · 1.89 KB
/
sha512_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 TestSHA512Hasher_String(t *testing.T) {
salt := "salt"
iter := 1
h := SHA512Hasher{Salt: &salt, Iter: &iter}
h.SetPassword("password")
w := string([]byte{0x29, 0x8, 0xd2, 0xc2, 0x8d, 0xfc, 0x4, 0x77, 0x41, 0xfc, 0x59, 0xa, 0x2, 0x6f, 0xfa, 0xde, 0x23, 0x7a, 0xb2, 0xba, 0x7e, 0x12, 0x66, 0xf0, 0x10, 0xfe, 0x49, 0xbd, 0xe5, 0x48, 0xb5, 0x98, 0x7a, 0x53, 0x4a, 0x86, 0x65, 0x5a, 0xd, 0x17, 0xf3, 0x36, 0x58, 0x8e, 0x54, 0xc, 0xd6, 0x6f, 0x67, 0x23, 0x4b, 0x15, 0x2b, 0xbb, 0x64, 0x5b, 0x4b, 0xb8, 0x57, 0x58, 0xa1, 0x32, 0x5d, 0x64})
g := h.String()
assert.Equal(t, w, g)
h = SHA512Hasher{Salt: &salt, Iter: &iter}
assert.Panics(t, assert.PanicTestFunc(func() {
_ = h.String()
}))
}
func TestSHA512Hasher_Check(t *testing.T) {
salt := "salt"
iter := 1
h := SHA512Hasher{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 TestSHA512Hasher_Hash(t *testing.T) {
salt := "salt"
iter := 1
password := []byte{0x29, 0x8, 0xd2, 0xc2, 0x8d, 0xfc, 0x4, 0x77, 0x41, 0xfc, 0x59, 0xa, 0x2, 0x6f, 0xfa, 0xde, 0x23, 0x7a, 0xb2, 0xba, 0x7e, 0x12, 0x66, 0xf0, 0x10, 0xfe, 0x49, 0xbd, 0xe5, 0x48, 0xb5, 0x98, 0x7a, 0x53, 0x4a, 0x86, 0x65, 0x5a, 0xd, 0x17, 0xf3, 0x36, 0x58, 0x8e, 0x54, 0xc, 0xd6, 0x6f, 0x67, 0x23, 0x4b, 0x15, 0x2b, 0xbb, 0x64, 0x5b, 0x4b, 0xb8, 0x57, 0x58, 0xa1, 0x32, 0x5d, 0x64}
h := SHA512Hasher{Salt: &salt, Iter: &iter}
g := h.Hash("password")
assert.Equal(t, password, g)
}
func TestSHA512Hasher_Hash_Empty(t *testing.T) {
h := SHA512Hasher{}
h.Hash("password")
assert.NotNil(t, h.Iter)
assert.NotNil(t, h.Salt)
}
func TestSHA512Hasher_SetPassword(t *testing.T) {
h := SHA512Hasher{}
h.SetPassword("password")
assert.NotNil(t, h.Password)
}