diff options
author | EpicCoder <EpicCoder@users.noreply.github.com> | 2019-07-07 08:01:01 +0200 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-07-07 02:01:01 -0400 |
commit | 8d9d6aa903baf3662fa31bceb489291564a873d1 (patch) | |
tree | 7a952e1c0fce29af1de19df54fa570e24ff09fcc /models/user_test.go | |
parent | 1b85b248e42a9d45d4dc278d399ddab3edcedfdb (diff) | |
download | gitea-8d9d6aa903baf3662fa31bceb489291564a873d1.tar.gz gitea-8d9d6aa903baf3662fa31bceb489291564a873d1.zip |
Add additional password hash algorithms (closes #5859) (#6023)
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) + } + } } } |