mirror of
https://github.com/pushbits/server.git
synced 2025-04-29 10:16:50 +02:00
Merge branch 'main' into sast
This commit is contained in:
commit
66a2e74241
3 changed files with 15 additions and 14 deletions
6
Makefile
6
Makefile
|
@ -5,16 +5,14 @@ build:
|
|||
|
||||
.PHONY: test
|
||||
test:
|
||||
stdout=$$(gofmt -l . 2>&1); \
|
||||
if [ "$$stdout" ]; then \
|
||||
exit 1; \
|
||||
fi
|
||||
stdout=$$(gofmt -l . 2>&1); if [ "$$stdout" ]; then exit 1; fi
|
||||
go vet ./...
|
||||
gocyclo -over 10 $(shell find . -iname '*.go' -type f)
|
||||
staticcheck ./...
|
||||
go test -v -cover ./...
|
||||
gosec -exclude-dir=tests ./...
|
||||
semgrep --lang=go --config=tests/semgrep
|
||||
@printf '\n%s\n' "> Test successful"
|
||||
|
||||
.PHONY: setup
|
||||
setup:
|
||||
|
|
|
@ -53,5 +53,7 @@ func GenerateApplicationToken(compat bool) string {
|
|||
tokenLength = compatTokenLength
|
||||
}
|
||||
|
||||
tokenLength -= len(applicationTokenPrefix)
|
||||
|
||||
return applicationTokenPrefix + generateRandomString(tokenLength)
|
||||
}
|
||||
|
|
|
@ -1,28 +1,29 @@
|
|||
package authentication
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func isGoodToken(assert *assert.Assertions, require *require.Assertions, token string, compat bool) {
|
||||
prefix := token[0:len(applicationTokenPrefix)]
|
||||
token = token[len(applicationTokenPrefix):]
|
||||
const (
|
||||
minRandomChars = 14
|
||||
)
|
||||
|
||||
// Although constant at the time of writing, this check should prevent future changes from generating insecure tokens.
|
||||
if len(token) < 14 {
|
||||
log.Fatalf("Tokens should have more random characters")
|
||||
}
|
||||
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")
|
||||
}
|
||||
|
||||
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
Reference in a new issue