-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patht_bcrypt_test.go
More file actions
67 lines (59 loc) · 1.64 KB
/
Copy patht_bcrypt_test.go
File metadata and controls
67 lines (59 loc) · 1.64 KB
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
60
61
62
63
64
65
66
67
package crypt
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBcryptOutputs(t *testing.T) {
testcCases := []struct {
name string
have string
}{
{
"ShouldValidatePasswordStandardVariantB",
"$2b$10$3o9IF74Phgdz4Q6j7K7s0unovt.v.7YBLKFyV73pGTd2.tfdz/F8e",
},
{
"ShouldValidatePasswordStandardVariantA",
"$2a$10$3o9IF74Phgdz4Q6j7K7s0unovt.v.7YBLKFyV73pGTd2.tfdz/F8e",
},
{
"ShouldValidatePasswordStandardVariantX",
"$2x$10$3o9IF74Phgdz4Q6j7K7s0unovt.v.7YBLKFyV73pGTd2.tfdz/F8e",
},
{
"ShouldValidatePasswordStandardVariantY",
"$2y$10$3o9IF74Phgdz4Q6j7K7s0unovt.v.7YBLKFyV73pGTd2.tfdz/F8e",
},
{
"ShouldValidatePasswordSHA256VariantB",
"$bcrypt-sha256$v=2,t=2b,r=10$oYmTNJVOBi3hdhUYy4JqOe$jCuMDm.Pw9hhoF/FDC6sOi48yBAoWvC",
},
{
"ShouldValidatePasswordSHA256VariantA",
"$bcrypt-sha256$v=2,t=2a,r=10$oYmTNJVOBi3hdhUYy4JqOe$jCuMDm.Pw9hhoF/FDC6sOi48yBAoWvC",
},
{
"ShouldValidatePasswordSHA256VariantX",
"$bcrypt-sha256$v=2,t=2x,r=10$oYmTNJVOBi3hdhUYy4JqOe$jCuMDm.Pw9hhoF/FDC6sOi48yBAoWvC",
},
{
"ShouldValidatePasswordSHA256VariantY",
"$bcrypt-sha256$v=2,t=2y,r=10$oYmTNJVOBi3hdhUYy4JqOe$jCuMDm.Pw9hhoF/FDC6sOi48yBAoWvC",
},
}
for _, tc := range testcCases {
t.Run(tc.name, func(t *testing.T) {
t.Run("CorrectPassword", func(t *testing.T) {
valid, err := CheckPassword(password, tc.have)
require.NoError(t, err)
assert.True(t, valid)
})
t.Run("IncorrectPassword", func(t *testing.T) {
valid, err := CheckPassword(wrongPassword, tc.have)
require.NoError(t, err)
assert.False(t, valid)
})
})
}
}