mirror of
https://github.com/pushbits/server.git
synced 2025-05-23 22:06: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
6
Makefile
6
Makefile
|
@ -5,14 +5,12 @@ build:
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
stdout=$$(gofmt -l . 2>&1); \
|
stdout=$$(gofmt -l . 2>&1); if [ "$$stdout" ]; then exit 1; fi
|
||||||
if [ "$$stdout" ]; then \
|
|
||||||
exit 1; \
|
|
||||||
fi
|
|
||||||
go vet ./...
|
go vet ./...
|
||||||
gocyclo -over 10 $(shell find . -iname '*.go' -type f)
|
gocyclo -over 10 $(shell find . -iname '*.go' -type f)
|
||||||
staticcheck ./...
|
staticcheck ./...
|
||||||
go test -v -cover ./...
|
go test -v -cover ./...
|
||||||
|
@printf '\n%s\n' "> Test successful"
|
||||||
|
|
||||||
.PHONY: setup
|
.PHONY: setup
|
||||||
setup:
|
setup:
|
||||||
|
|
|
@ -8,20 +8,22 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
minTokenLength = 14
|
minRandomChars = 14
|
||||||
)
|
)
|
||||||
|
|
||||||
func isGoodToken(assert *assert.Assertions, require *require.Assertions, token string, compat bool) {
|
func isGoodToken(assert *assert.Assertions, require *require.Assertions, token string, compat bool) {
|
||||||
|
tokenLength := len(token)
|
||||||
|
|
||||||
if compat {
|
if compat {
|
||||||
assert.Equal(len(token), compatTokenLength, "Unexpected compatibility token length")
|
assert.Equal(tokenLength, compatTokenLength, "Unexpected compatibility token length")
|
||||||
} else {
|
} 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)]
|
prefix := token[0:len(applicationTokenPrefix)]
|
||||||
|
|
||||||
assert.Equal(prefix, applicationTokenPrefix, "Invalid token prefix")
|
assert.Equal(prefix, applicationTokenPrefix, "Invalid token prefix")
|
||||||
|
|
||||||
for _, c := range []byte(token) {
|
for _, c := range []byte(token) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue