diff options
Diffstat (limited to 'models/user_test.go')
-rw-r--r-- | models/user_test.go | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/models/user_test.go b/models/user_test.go index 6af9752c9b..10420a143f 100644 --- a/models/user_test.go +++ b/models/user_test.go @@ -147,21 +147,29 @@ func TestHashPasswordDeterministic(t *testing.T) { b := make([]byte, 16) rand.Read(b) u := &User{Salt: string(b)} - for i := 0; i < 50; i++ { - // generate a random password - rand.Read(b) - pass := string(b) - - // save the current password in the user - hash it and store the result - u.HashPassword(pass) - r1 := u.Passwd - - // run again - u.HashPassword(pass) - r2 := u.Passwd - - // assert equal (given the same salt+pass, the same result is produced) - assert.Equal(t, r1, r2) + algos := []string{"pbkdf2", "argon2", "scrypt", "bcrypt"} + for j := 0; j < len(algos); j++ { + u.PasswdHashAlgo = algos[j] + for i := 0; i < 50; i++ { + // generate a random password + rand.Read(b) + pass := string(b) + + // save the current password in the user - hash it and store the result + u.HashPassword(pass) + r1 := u.Passwd + + // run again + u.HashPassword(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) + } + } } } |