54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package auth
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
func TestHashToken_Consistent(t *testing.T) {
|
|
token := "abc123def456"
|
|
hash1 := hashToken(token)
|
|
hash2 := hashToken(token)
|
|
|
|
if hash1 != hash2 {
|
|
t.Errorf("hashToken is not consistent: got %q and %q for the same input", hash1, hash2)
|
|
}
|
|
}
|
|
|
|
func TestHashToken_DifferentInputs(t *testing.T) {
|
|
hash1 := hashToken("token-one")
|
|
hash2 := hashToken("token-two")
|
|
|
|
if hash1 == hash2 {
|
|
t.Errorf("hashToken produced identical hashes for different inputs: %q", hash1)
|
|
}
|
|
}
|
|
|
|
func TestHashToken_ValidHexLength(t *testing.T) {
|
|
hash := hashToken("some-test-token")
|
|
|
|
// SHA-256 produces 32 bytes = 64 hex characters
|
|
if len(hash) != 64 {
|
|
t.Errorf("expected hash length 64, got %d", len(hash))
|
|
}
|
|
|
|
// Verify it is valid hex
|
|
_, err := hex.DecodeString(hash)
|
|
if err != nil {
|
|
t.Errorf("hash is not valid hex: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestHashToken_EmptyInput(t *testing.T) {
|
|
hash := hashToken("")
|
|
|
|
if len(hash) != 64 {
|
|
t.Errorf("expected hash length 64 for empty input, got %d", len(hash))
|
|
}
|
|
|
|
_, err := hex.DecodeString(hash)
|
|
if err != nil {
|
|
t.Errorf("hash of empty input is not valid hex: %v", err)
|
|
}
|
|
}
|