summaryrefslogtreecommitdiffstats
path: root/models/user_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/user_test.go')
-rw-r--r--models/user_test.go21
1 files changed, 7 insertions, 14 deletions
diff --git a/models/user_test.go b/models/user_test.go
index 224acd5f3c..69cb21b975 100644
--- a/models/user_test.go
+++ b/models/user_test.go
@@ -220,8 +220,7 @@ func TestEmailNotificationPreferences(t *testing.T) {
func TestHashPasswordDeterministic(t *testing.T) {
b := make([]byte, 16)
- rand.Read(b)
- u := &User{Salt: string(b)}
+ u := &User{}
algos := []string{"argon2", "pbkdf2", "scrypt", "bcrypt"}
for j := 0; j < len(algos); j++ {
u.PasswdHashAlgo = algos[j]
@@ -231,19 +230,15 @@ func TestHashPasswordDeterministic(t *testing.T) {
pass := string(b)
// save the current password in the user - hash it and store the result
- u.HashPassword(pass)
+ u.SetPassword(pass)
r1 := u.Passwd
// run again
- u.HashPassword(pass)
+ u.SetPassword(pass)
r2 := u.Passwd
- // assert equal (given the same salt+pass, the same result is produced) except bcrypt
- if u.PasswdHashAlgo == "bcrypt" {
- assert.NotEqual(t, r1, r2)
- } else {
- assert.Equal(t, r1, r2)
- }
+ assert.NotEqual(t, r1, r2)
+ assert.True(t, u.ValidatePassword(pass))
}
}
}
@@ -252,12 +247,10 @@ func BenchmarkHashPassword(b *testing.B) {
// BenchmarkHashPassword ensures that it takes a reasonable amount of time
// to hash a password - in order to protect from brute-force attacks.
pass := "password1337"
- bs := make([]byte, 16)
- rand.Read(bs)
- u := &User{Salt: string(bs), Passwd: pass}
+ u := &User{Passwd: pass}
b.ResetTimer()
for i := 0; i < b.N; i++ {
- u.HashPassword(pass)
+ u.SetPassword(pass)
}
}