-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathhasher_test.go
More file actions
37 lines (29 loc) · 783 Bytes
/
hasher_test.go
File metadata and controls
37 lines (29 loc) · 783 Bytes
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
package authboss
import (
"strings"
"testing"
"golang.org/x/crypto/bcrypt"
)
func TestBcryptHasher(t *testing.T) {
t.Parallel()
hasher := NewBCryptHasher(bcrypt.DefaultCost)
hash, err := hasher.GenerateHash("qwerty")
if err != nil {
t.Error(err)
}
if hash == "" {
t.Error("Result Hash must be not empty")
}
if len(hash) != 60 {
t.Error("hash was invalid length", len(hash))
}
if !strings.HasPrefix(hash, "$2a$10$") {
t.Error("hash was wrong", hash)
}
if err := hasher.CompareHashAndPassword(hash, "qwerty"); err != nil {
t.Error("compare-hash-and-password for valid password must be ok", err)
}
if err := hasher.CompareHashAndPassword(hash, "qwerty-invalid"); err == nil {
t.Error("compare-hash-and-password for invalid password must fail")
}
}