-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsha512_224_hasher_test.go
59 lines (47 loc) · 1.52 KB
/
sha512_224_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_224Hasher_String(t *testing.T) {
salt := "salt"
iter := 1
h := SHA512_224Hasher{Salt: &salt, Iter: &iter}
h.SetPassword("password")
w := string([]byte{0x8a, 0x63, 0xce, 0xaa, 0xc7, 0xf7, 0xb6, 0x9, 0x75, 0xd6, 0x1b, 0xc1, 0xb8, 0xb1, 0xc7, 0x6e, 0xc7, 0xde, 0x6c, 0x2, 0x26, 0xb7, 0xaf, 0x60, 0x63, 0x3e, 0xc5, 0xe})
g := h.String()
assert.Equal(t, w, g)
h = SHA512_224Hasher{Salt: &salt, Iter: &iter}
assert.Panics(t, assert.PanicTestFunc(func() {
_ = h.String()
}))
}
func TestSHA512_224Hasher_Check(t *testing.T) {
salt := "salt"
iter := 1
h := SHA512_224Hasher{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_224Hasher_Hash(t *testing.T) {
salt := "salt"
iter := 1
password := []byte{0x8a, 0x63, 0xce, 0xaa, 0xc7, 0xf7, 0xb6, 0x9, 0x75, 0xd6, 0x1b, 0xc1, 0xb8, 0xb1, 0xc7, 0x6e, 0xc7, 0xde, 0x6c, 0x2, 0x26, 0xb7, 0xaf, 0x60, 0x63, 0x3e, 0xc5, 0xe}
h := SHA512_224Hasher{Salt: &salt, Iter: &iter}
g := h.Hash("password")
assert.Equal(t, password, g)
}
func TestSHA512_224Hasher_Hash_Empty(t *testing.T) {
h := SHA512_224Hasher{}
h.Hash("password")
assert.NotNil(t, h.Iter)
assert.NotNil(t, h.Salt)
}
func TestSHA512_224Hasher_SetPassword(t *testing.T) {
h := SHA512_224Hasher{}
h.SetPassword("password")
assert.NotNil(t, h.Password)
}