Update build configuration and improve token handling
Build and Test / verify (push) Failing after 1m22s

- Change CI container image to debian:trixie-slim and set GOPROXY.
- Update Go version to 1.26 in Dockerfile and go.mod.
- Refactor token validation to use SHA-256 hashes instead of plain tokens.
- Add network policy to restrict access to the service.
- Enhance README with new configuration details and usage examples.
- Add tests for new token hash validation logic.
This commit is contained in:
2026-07-11 22:08:56 +02:00
parent ea4aac6641
commit 1acdbb5519
8 changed files with 195 additions and 57 deletions
+19 -2
View File
@@ -1,11 +1,20 @@
package auth
import "testing"
import (
"crypto/sha256"
"fmt"
"testing"
)
func hashHex(token string) string {
sum := sha256.Sum256([]byte(token))
return fmt.Sprintf("%x", sum[:])
}
func TestValidator_IsValid(t *testing.T) {
t.Parallel()
validator, err := NewValidator([]string{"token-one", "token-two", "token-three"})
validator, err := NewValidator([]string{hashHex("token-one"), hashHex("token-two"), hashHex("token-three")})
if err != nil {
t.Fatalf("NewValidator() error = %v", err)
}
@@ -45,6 +54,14 @@ func TestNewValidator_EmptyTokenSet(t *testing.T) {
}
}
func TestNewValidator_InvalidHash(t *testing.T) {
t.Parallel()
if _, err := NewValidator([]string{"not-a-hash"}); err == nil {
t.Fatal("NewValidator(invalid hash) expected error, got nil")
}
}
func TestParseBearerToken(t *testing.T) {
t.Parallel()