mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-17 23:31:55 +01:00
338d819b58
(cherry picked from commit3ea0b287d7
) (cherry picked from commitdb8392a8ac
) (cherry picked from commitbd2a5fa292
) (cherry picked from commit2436acb3d9
) (cherry picked from commit62f50e1c52
) (cherry picked from commitdba1892521
) (cherry picked from commit4b58e3b6d4
) (cherry picked from commit1247056856
) (cherry picked from commitafbaea7009
) (cherry picked from commitdcd4813d96
) (cherry picked from commitb51dc963d1
) (cherry picked from commit611e895efd
) (cherry picked from commitfd492a03f5
) (cherry picked from commit2c99991f44
) (cherry picked from commit7426c1edb4
) (cherry picked from commit373244f8b2
) (cherry picked from commit4f6efecdb9
) (cherry picked from commit61d500808e
) (cherry picked from commit65f8384b63
) (cherry picked from commit12ed28e734
) (cherry picked from commitec6cdc9e1a
) (cherry picked from commit08653ba051
) (cherry picked from commitd5847c87cb
) (cherry picked from commit640a96e19b
) (cherry picked from commit46177814a9
) (cherry picked from commitb0098f5a80
) (cherry picked from commitce5ddeeca9
) (cherry picked from commit5736fa1025
) (cherry picked from commitc43ca210fc
) (cherry picked from commit7f92906bf3
) (cherry picked from commitf726525d2d
) (cherry picked from commitdb86c93b0b
) (cherry picked from commit6751bd93c3
) (cherry picked from commit9dc354e0bc
) (cherry picked from commite50ba1dbfd
) (cherry picked from commit18f7944032
) (cherry picked from commit51db3f3e4d
) (cherry picked from commit13d82d966c
)
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
// 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)
|
|
})
|
|
}
|
|
|
|
t.Run("pbkdf2_hi is the default when default password hash algorithm is empty", func(t *testing.T) {
|
|
emptyConfig, emptyAlgo := SetDefaultPasswordHashAlgorithm("")
|
|
pbkdf2hiConfig, pbkdf2hiAlgo := SetDefaultPasswordHashAlgorithm("pbkdf2_hi")
|
|
|
|
assert.Equal(t, pbkdf2hiConfig, emptyConfig)
|
|
assert.Equal(t, pbkdf2hiAlgo.Specification, emptyAlgo.Specification)
|
|
})
|
|
}
|