-
Notifications
You must be signed in to change notification settings - Fork 9
/
passwords_test.go
45 lines (33 loc) · 846 Bytes
/
passwords_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
package goauth2_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/inklabs/goauth2"
)
func Test_GeneratePasswordHash(t *testing.T) {
// Given
password := "test123!"
// When
hash := goauth2.GeneratePasswordHash(password)
// Then
isValid := goauth2.VerifyPassword(hash, password)
assert.True(t, isValid)
}
func Test_VerifyPassword(t *testing.T) {
// Given
hash := "$2a$10$kXoIYjFFopkb5hGWTdFum.wuse7u8vyhq/5cJoyqbA9rI1cfR/ow6"
password := "test123!"
// When
isValid := goauth2.VerifyPassword(hash, password)
// Then
assert.True(t, isValid)
}
func Test_VerifyPasswordFails(t *testing.T) {
// Given
hash := "$2a$10$kXoIYjFFopkb5hGWTdFum.wuse7u8vyhq/5cJoyqbA9rI1cfR/ow6"
password := "wrong-password"
// When
isValid := goauth2.VerifyPassword(hash, password)
// Then
assert.False(t, isValid)
}