You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setting_test.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package hash
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestCheckSettingPasswordHashAlgorithm(t *testing.T) {
  9. t.Run("pbkdf2 is pbkdf2_v2", func(t *testing.T) {
  10. pbkdf2v2Config, pbkdf2v2Algo := SetDefaultPasswordHashAlgorithm("pbkdf2_v2")
  11. pbkdf2Config, pbkdf2Algo := SetDefaultPasswordHashAlgorithm("pbkdf2")
  12. assert.Equal(t, pbkdf2v2Config, pbkdf2Config)
  13. assert.Equal(t, pbkdf2v2Algo.Specification, pbkdf2Algo.Specification)
  14. })
  15. for a, b := range aliasAlgorithmNames {
  16. t.Run(a+"="+b, func(t *testing.T) {
  17. aConfig, aAlgo := SetDefaultPasswordHashAlgorithm(a)
  18. bConfig, bAlgo := SetDefaultPasswordHashAlgorithm(b)
  19. assert.Equal(t, bConfig, aConfig)
  20. assert.Equal(t, aAlgo.Specification, bAlgo.Specification)
  21. })
  22. }
  23. t.Run("pbkdf2_v2 is the default when default password hash algorithm is empty", func(t *testing.T) {
  24. emptyConfig, emptyAlgo := SetDefaultPasswordHashAlgorithm("")
  25. pbkdf2v2Config, pbkdf2v2Algo := SetDefaultPasswordHashAlgorithm("pbkdf2_v2")
  26. assert.Equal(t, pbkdf2v2Config, emptyConfig)
  27. assert.Equal(t, pbkdf2v2Algo.Specification, emptyAlgo.Specification)
  28. })
  29. }