mirror of
https://github.com/go-gitea/gitea
synced 2025-07-09 20:17:21 +00:00
Refactor JWT secret generating & decoding code (#29172)
Old code is not consistent for generating & decoding the JWT secrets. Now, the callers only need to use 2 consistent functions: NewJwtSecretWithBase64 and DecodeJwtSecretBase64 And remove a non-common function Base64FixedDecode from util.go
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -234,16 +233,3 @@ func TestToPointer(t *testing.T) {
|
||||
val123 := 123
|
||||
assert.False(t, &val123 == ToPointer(val123))
|
||||
}
|
||||
|
||||
func TestBase64FixedDecode(t *testing.T) {
|
||||
_, err := Base64FixedDecode(base64.RawURLEncoding, []byte("abcd"), 32)
|
||||
assert.ErrorContains(t, err, "invalid base64 decoded length")
|
||||
_, err = Base64FixedDecode(base64.RawURLEncoding, []byte(strings.Repeat("a", 64)), 32)
|
||||
assert.ErrorContains(t, err, "invalid base64 decoded length")
|
||||
|
||||
str32 := strings.Repeat("x", 32)
|
||||
encoded32 := base64.RawURLEncoding.EncodeToString([]byte(str32))
|
||||
decoded32, err := Base64FixedDecode(base64.RawURLEncoding, []byte(encoded32), 32)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, str32, string(decoded32))
|
||||
}
|
||||
|
Reference in New Issue
Block a user