MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / TestHashOTP_RoundTrip

Function TestHashOTP_RoundTrip

internal/crypto/otp_test.go:11–27  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestHashOTP_RoundTrip(t *testing.T) {
12 const key = "test-jwt-secret"
13 const plain = "123456"
14
15 hashed := HashOTP(plain, key)
16
17 // Hex digest of HMAC-SHA256 is always 64 chars (32 bytes * 2)
18 require.Len(t, hashed, 64)
19 // And must not equal the plaintext
20 assert.NotEqual(t, plain, hashed)
21
22 // Verify with the original plaintext succeeds
23 assert.True(t, VerifyOTPHash(plain, hashed, key))
24 // Verifying with the digest itself MUST fail — otherwise the digest
25 // becomes a usable credential for anyone with DB read access.
26 assert.False(t, VerifyOTPHash(hashed, hashed, key))
27}
28
29func TestHashOTP_Deterministic(t *testing.T) {
30 // Same plaintext + same key must produce the same digest. Otherwise

Callers

nothing calls this directly

Calls 2

HashOTPFunction · 0.85
VerifyOTPHashFunction · 0.85

Tested by

no test coverage detected