-
Notifications
You must be signed in to change notification settings - Fork 4
/
credential_internal_test.go
44 lines (35 loc) · 1.38 KB
/
credential_internal_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
package passhash
import (
"testing"
)
type invalidWorkFactor struct {
}
func (wf *invalidWorkFactor) Marshal() ([]int, error) {
return []int{}, nil
}
func (wf *invalidWorkFactor) Unmarshal(p []int) error {
return nil
}
func testGetPasswordHashInvalidKdfAndWorkFactorCombo(t *testing.T, kdf Kdf, workFactor WorkFactor) {
salt := []byte("salt")
password := "foobar"
_, err := getPasswordHash(kdf, workFactor, salt, DefaultConfig.KeyLength, password)
if err == nil {
t.Errorf("Kdf %v and WorkFactor %T considered valid combo", kdf, workFactor)
}
}
func TestGetPasswordHashUnsupportedWorkFactor(t *testing.T) {
testGetPasswordHashInvalidKdfAndWorkFactorCombo(t, Pbkdf2Sha256, &invalidWorkFactor{})
}
func TestGetPasswordHashInvalidPbkdf2WorkFactor(t *testing.T) {
testGetPasswordHashInvalidKdfAndWorkFactorCombo(t, Pbkdf2Sha256, &ScryptWorkFactor{})
testGetPasswordHashInvalidKdfAndWorkFactorCombo(t, Pbkdf2Sha256, &BcryptWorkFactor{})
}
func TestGetPasswordHashInvalidBcryptWorkFactor(t *testing.T) {
testGetPasswordHashInvalidKdfAndWorkFactorCombo(t, Bcrypt, &Pbkdf2WorkFactor{})
testGetPasswordHashInvalidKdfAndWorkFactorCombo(t, Bcrypt, &ScryptWorkFactor{})
}
func TestGetPasswordHashInvalidScryptWorkFactor(t *testing.T) {
testGetPasswordHashInvalidKdfAndWorkFactorCombo(t, Scrypt, &Pbkdf2WorkFactor{})
testGetPasswordHashInvalidKdfAndWorkFactorCombo(t, Scrypt, &BcryptWorkFactor{})
}