mirror of
https://github.com/pushbits/server.git
synced 2025-05-23 05:46:34 +02:00
Consider the prefix when testing token length
This commit is contained in:
parent
500a8cd4b0
commit
be99411b1b
2 changed files with 9 additions and 9 deletions
|
@ -8,20 +8,22 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
minTokenLength = 14
|
||||
minRandomChars = 14
|
||||
)
|
||||
|
||||
func isGoodToken(assert *assert.Assertions, require *require.Assertions, token string, compat bool) {
|
||||
tokenLength := len(token)
|
||||
|
||||
if compat {
|
||||
assert.Equal(len(token), compatTokenLength, "Unexpected compatibility token length")
|
||||
assert.Equal(tokenLength, compatTokenLength, "Unexpected compatibility token length")
|
||||
} else {
|
||||
assert.Equal(len(token), regularTokenLength, "Unexpected regular token length")
|
||||
assert.Equal(tokenLength, regularTokenLength, "Unexpected regular token length")
|
||||
}
|
||||
|
||||
assert.GreaterOrEqual(len(token), minTokenLength, "Token is too short to give sufficient entropy")
|
||||
randomChars := tokenLength - len(applicationTokenPrefix)
|
||||
assert.GreaterOrEqual(randomChars, minRandomChars, "Token is too short to give sufficient entropy")
|
||||
|
||||
prefix := token[0:len(applicationTokenPrefix)]
|
||||
|
||||
assert.Equal(prefix, applicationTokenPrefix, "Invalid token prefix")
|
||||
|
||||
for _, c := range []byte(token) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue