blob: 54053090453fb1acbbec81d8ac1e7e006fccf547 (
plain)
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
|
// +build all general
package main
import (
"testing"
)
func TestMd5Hash(t *testing.T) {
hash := "f9d08276bc85d30d578e8883f3c7e843"
testHash := Md5Hash("md5hash")
if hash != testHash {
t.Fatal("Expected %s as hash. Got %s.", hash, testHash)
}
}
func TestRandomKey(t *testing.T) {
key := RandomKey()
if len(key) != 40 {
t.Fatal("Expected a key with length of 40. Got %s.", key)
}
}
func TestPassword(t *testing.T) {
testHash, err := HashPassword("password")
if err != nil {
t.Fatal("Hashing password failed.")
}
verify := VerifyPassword("password", testHash)
if !verify {
t.Fatal("Verifying password failed.")
}
testHash, err = HashPassword("")
if err == nil {
t.Fatal("Accepting empty password.")
}
verify = VerifyPassword("", testHash)
if verify {
t.Fatal("Verifying empty password.")
}
}
|