-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsha512_256_hasher_test.go
59 lines (47 loc) · 1.56 KB
/
sha512_256_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 TestSHA512_256Hasher_String(t *testing.T) {
salt := "salt"
iter := 1
h := SHA512_256Hasher{Salt: &salt, Iter: &iter}
h.SetPassword("password")
w := string([]byte{0x5, 0x42, 0x18, 0x82, 0x8, 0x71, 0x4e, 0x74, 0xc7, 0x71, 0x7, 0x55, 0x81, 0x68, 0xd7, 0xfe, 0xa6, 0x1d, 0x85, 0xbb, 0xab, 0x7a, 0x5c, 0x88, 0xaf, 0x3c, 0xf6, 0xfa, 0x20, 0x68, 0xb6, 0x1})
g := h.String()
assert.Equal(t, w, g)
h = SHA512_256Hasher{Salt: &salt, Iter: &iter}
assert.Panics(t, assert.PanicTestFunc(func() {
_ = h.String()
}))
}
func TestSHA512_256Hasher_Check(t *testing.T) {
salt := "salt"
iter := 1
h := SHA512_256Hasher{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 TestSHA512_256Hasher_Hash(t *testing.T) {
salt := "salt"
iter := 1
password := []byte{0x5, 0x42, 0x18, 0x82, 0x8, 0x71, 0x4e, 0x74, 0xc7, 0x71, 0x7, 0x55, 0x81, 0x68, 0xd7, 0xfe, 0xa6, 0x1d, 0x85, 0xbb, 0xab, 0x7a, 0x5c, 0x88, 0xaf, 0x3c, 0xf6, 0xfa, 0x20, 0x68, 0xb6, 0x1}
h := SHA512_256Hasher{Salt: &salt, Iter: &iter}
g := h.Hash("password")
assert.Equal(t, password, g)
}
func TestSHA512_256Hasher_Hash_Empty(t *testing.T) {
h := SHA512_256Hasher{}
h.Hash("password")
assert.NotNil(t, h.Iter)
assert.NotNil(t, h.Salt)
}
func TestSHA512_256Hasher_SetPassword(t *testing.T) {
h := SHA512_256Hasher{}
h.SetPassword("password")
assert.NotNil(t, h.Password)
}