forgejo/modules/auth/password/hash/setting_test.go

39 lines
1.2 KiB
Go
Raw Normal View History

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package hash
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCheckSettingPasswordHashAlgorithm(t *testing.T) {
t.Run("pbkdf2 is pbkdf2_v2", func(t *testing.T) {
pbkdf2v2Config, pbkdf2v2Algo := SetDefaultPasswordHashAlgorithm("pbkdf2_v2")
pbkdf2Config, pbkdf2Algo := SetDefaultPasswordHashAlgorithm("pbkdf2")
assert.Equal(t, pbkdf2v2Config, pbkdf2Config)
assert.Equal(t, pbkdf2v2Algo.Specification, pbkdf2Algo.Specification)
})
for a, b := range aliasAlgorithmNames {
t.Run(a+"="+b, func(t *testing.T) {
aConfig, aAlgo := SetDefaultPasswordHashAlgorithm(a)
bConfig, bAlgo := SetDefaultPasswordHashAlgorithm(b)
assert.Equal(t, bConfig, aConfig)
assert.Equal(t, aAlgo.Specification, bAlgo.Specification)
})
}
[SECURITY] default to pbkdf2 with 320,000 iterations (cherry picked from commit 3ea0b287d74b8fc0dad08b2a539105e1aa1c1e67) (cherry picked from commit db8392a8ac093d4d3760e8bb40c56d8e194d44fb) (cherry picked from commit bd2a5fa2923c320e01faeaa1fdc1ad823c337027) (cherry picked from commit 2436acb3d986bad08aa134e450420fc4a08f5d62) (cherry picked from commit 62f50e1c521c30729781e5cd58882e743bb8b851) (cherry picked from commit dba18925217254d22f76306c0fe1c046c419268e) (cherry picked from commit 4b58e3b6d41f9e42fd34469184a3c7d4c5205c86) (cherry picked from commit 12470568569fec0644319d3d263a82bc7acdc0c3) (cherry picked from commit afbaea700972ddd4cb788d0b6d5e78de5558756a) (cherry picked from commit dcd4813d96f8d4e429914f4c8f951bd25b23afca) (cherry picked from commit b51dc963d1625bd7b9869302ec1ae70bbafb4442) (cherry picked from commit 611e895efd28026fdc4661893172356e76f6c3d0) (cherry picked from commit fd492a03f5335c138e143e784657f7012484bd8c) (cherry picked from commit 2c99991f44a15466339bb82b29d455c66795721b) (cherry picked from commit 7426c1edb4b904424cded473c94c9739fde83ed0) (cherry picked from commit 373244f8b2d449e8811e488e3a3732ba9bc79eaa) (cherry picked from commit 4f6efecdb9d932459dd9f4d7ee393a121a7bbb96) (cherry picked from commit 61d500808e443ce770b06fa1b87728a7785bd387) (cherry picked from commit 65f8384b6361c39d48df95227b047a20977482be) (cherry picked from commit 12ed28e734f79203ad6bf94774008715da6efd21) (cherry picked from commit ec6cdc9e1a9544f4f2b0ad7256ed2a8b15cf5335) (cherry picked from commit 08653ba05119906e066455a3e3913e66c179dbf3) (cherry picked from commit d5847c87cbcf0fd15953fb7aeadd1cece989b6c9) (cherry picked from commit 640a96e19be0c7faedf5aedfd90c15df8dc8f376) (cherry picked from commit 46177814a9ee8596b58055b57bea5441a893de7f) (cherry picked from commit b0098f5a80356757107cc4dd58bf24e2acba6b26) (cherry picked from commit ce5ddeeca9fa39180a2f9630c82007f8e9410867) (cherry picked from commit 5736fa1025681244b8eefef9a14b0715fa37d9a1) (cherry picked from commit c43ca210fcbc2589158df8c2c3036dedb00eaa52) (cherry picked from commit 7f92906bf3c72649dd2668263761ded71cf5ee91) (cherry picked from commit f726525d2dba5e481f758624e62eeaa3d38be564) (cherry picked from commit db86c93b0b7d2c1a7c17fcb6047b3d75873f9bbe) (cherry picked from commit 6751bd93c3faf4be0f29b52b4c41626a244a2a54) (cherry picked from commit 74bb523ac96062f93f20c174dcc9b1dc7ad94b13) (cherry picked from commit 94f9045a81ef58ecb6671d1e8f2ad31a7758ea9a) (cherry picked from commit 5297eac42d905d10060de688963f111cbefe49d4) (cherry picked from commit 57e3c57c519f41a595845be3f2505610ae8ad690) (cherry picked from commit c5cacfee51e2e7846234c9dd9c053b6cdfaf3947)
2023-02-20 23:25:12 +01:00
t.Run("pbkdf2_hi is the default when default password hash algorithm is empty", func(t *testing.T) {
emptyConfig, emptyAlgo := SetDefaultPasswordHashAlgorithm("")
[SECURITY] default to pbkdf2 with 320,000 iterations (cherry picked from commit 3ea0b287d74b8fc0dad08b2a539105e1aa1c1e67) (cherry picked from commit db8392a8ac093d4d3760e8bb40c56d8e194d44fb) (cherry picked from commit bd2a5fa2923c320e01faeaa1fdc1ad823c337027) (cherry picked from commit 2436acb3d986bad08aa134e450420fc4a08f5d62) (cherry picked from commit 62f50e1c521c30729781e5cd58882e743bb8b851) (cherry picked from commit dba18925217254d22f76306c0fe1c046c419268e) (cherry picked from commit 4b58e3b6d41f9e42fd34469184a3c7d4c5205c86) (cherry picked from commit 12470568569fec0644319d3d263a82bc7acdc0c3) (cherry picked from commit afbaea700972ddd4cb788d0b6d5e78de5558756a) (cherry picked from commit dcd4813d96f8d4e429914f4c8f951bd25b23afca) (cherry picked from commit b51dc963d1625bd7b9869302ec1ae70bbafb4442) (cherry picked from commit 611e895efd28026fdc4661893172356e76f6c3d0) (cherry picked from commit fd492a03f5335c138e143e784657f7012484bd8c) (cherry picked from commit 2c99991f44a15466339bb82b29d455c66795721b) (cherry picked from commit 7426c1edb4b904424cded473c94c9739fde83ed0) (cherry picked from commit 373244f8b2d449e8811e488e3a3732ba9bc79eaa) (cherry picked from commit 4f6efecdb9d932459dd9f4d7ee393a121a7bbb96) (cherry picked from commit 61d500808e443ce770b06fa1b87728a7785bd387) (cherry picked from commit 65f8384b6361c39d48df95227b047a20977482be) (cherry picked from commit 12ed28e734f79203ad6bf94774008715da6efd21) (cherry picked from commit ec6cdc9e1a9544f4f2b0ad7256ed2a8b15cf5335) (cherry picked from commit 08653ba05119906e066455a3e3913e66c179dbf3) (cherry picked from commit d5847c87cbcf0fd15953fb7aeadd1cece989b6c9) (cherry picked from commit 640a96e19be0c7faedf5aedfd90c15df8dc8f376) (cherry picked from commit 46177814a9ee8596b58055b57bea5441a893de7f) (cherry picked from commit b0098f5a80356757107cc4dd58bf24e2acba6b26) (cherry picked from commit ce5ddeeca9fa39180a2f9630c82007f8e9410867) (cherry picked from commit 5736fa1025681244b8eefef9a14b0715fa37d9a1) (cherry picked from commit c43ca210fcbc2589158df8c2c3036dedb00eaa52) (cherry picked from commit 7f92906bf3c72649dd2668263761ded71cf5ee91) (cherry picked from commit f726525d2dba5e481f758624e62eeaa3d38be564) (cherry picked from commit db86c93b0b7d2c1a7c17fcb6047b3d75873f9bbe) (cherry picked from commit 6751bd93c3faf4be0f29b52b4c41626a244a2a54) (cherry picked from commit 74bb523ac96062f93f20c174dcc9b1dc7ad94b13) (cherry picked from commit 94f9045a81ef58ecb6671d1e8f2ad31a7758ea9a) (cherry picked from commit 5297eac42d905d10060de688963f111cbefe49d4) (cherry picked from commit 57e3c57c519f41a595845be3f2505610ae8ad690) (cherry picked from commit c5cacfee51e2e7846234c9dd9c053b6cdfaf3947)
2023-02-20 23:25:12 +01:00
pbkdf2hiConfig, pbkdf2hiAlgo := SetDefaultPasswordHashAlgorithm("pbkdf2_hi")
[SECURITY] default to pbkdf2 with 320,000 iterations (cherry picked from commit 3ea0b287d74b8fc0dad08b2a539105e1aa1c1e67) (cherry picked from commit db8392a8ac093d4d3760e8bb40c56d8e194d44fb) (cherry picked from commit bd2a5fa2923c320e01faeaa1fdc1ad823c337027) (cherry picked from commit 2436acb3d986bad08aa134e450420fc4a08f5d62) (cherry picked from commit 62f50e1c521c30729781e5cd58882e743bb8b851) (cherry picked from commit dba18925217254d22f76306c0fe1c046c419268e) (cherry picked from commit 4b58e3b6d41f9e42fd34469184a3c7d4c5205c86) (cherry picked from commit 12470568569fec0644319d3d263a82bc7acdc0c3) (cherry picked from commit afbaea700972ddd4cb788d0b6d5e78de5558756a) (cherry picked from commit dcd4813d96f8d4e429914f4c8f951bd25b23afca) (cherry picked from commit b51dc963d1625bd7b9869302ec1ae70bbafb4442) (cherry picked from commit 611e895efd28026fdc4661893172356e76f6c3d0) (cherry picked from commit fd492a03f5335c138e143e784657f7012484bd8c) (cherry picked from commit 2c99991f44a15466339bb82b29d455c66795721b) (cherry picked from commit 7426c1edb4b904424cded473c94c9739fde83ed0) (cherry picked from commit 373244f8b2d449e8811e488e3a3732ba9bc79eaa) (cherry picked from commit 4f6efecdb9d932459dd9f4d7ee393a121a7bbb96) (cherry picked from commit 61d500808e443ce770b06fa1b87728a7785bd387) (cherry picked from commit 65f8384b6361c39d48df95227b047a20977482be) (cherry picked from commit 12ed28e734f79203ad6bf94774008715da6efd21) (cherry picked from commit ec6cdc9e1a9544f4f2b0ad7256ed2a8b15cf5335) (cherry picked from commit 08653ba05119906e066455a3e3913e66c179dbf3) (cherry picked from commit d5847c87cbcf0fd15953fb7aeadd1cece989b6c9) (cherry picked from commit 640a96e19be0c7faedf5aedfd90c15df8dc8f376) (cherry picked from commit 46177814a9ee8596b58055b57bea5441a893de7f) (cherry picked from commit b0098f5a80356757107cc4dd58bf24e2acba6b26) (cherry picked from commit ce5ddeeca9fa39180a2f9630c82007f8e9410867) (cherry picked from commit 5736fa1025681244b8eefef9a14b0715fa37d9a1) (cherry picked from commit c43ca210fcbc2589158df8c2c3036dedb00eaa52) (cherry picked from commit 7f92906bf3c72649dd2668263761ded71cf5ee91) (cherry picked from commit f726525d2dba5e481f758624e62eeaa3d38be564) (cherry picked from commit db86c93b0b7d2c1a7c17fcb6047b3d75873f9bbe) (cherry picked from commit 6751bd93c3faf4be0f29b52b4c41626a244a2a54) (cherry picked from commit 74bb523ac96062f93f20c174dcc9b1dc7ad94b13) (cherry picked from commit 94f9045a81ef58ecb6671d1e8f2ad31a7758ea9a) (cherry picked from commit 5297eac42d905d10060de688963f111cbefe49d4) (cherry picked from commit 57e3c57c519f41a595845be3f2505610ae8ad690) (cherry picked from commit c5cacfee51e2e7846234c9dd9c053b6cdfaf3947)
2023-02-20 23:25:12 +01:00
assert.Equal(t, pbkdf2hiConfig, emptyConfig)
assert.Equal(t, pbkdf2hiAlgo.Specification, emptyAlgo.Specification)
})
}