Skip to content

Commit 1c30951

Browse files
committed
test(auth): set KeyHash in singleflight fixture for constant-time check
ValidateUserAPIKey now runs subtle.ConstantTimeCompare(key.KeyHash, keyHash) after the DB fetch. The TestValidateUserAPIKey_LastUsedSingleflight fixture omitted KeyHash, so the empty stored hash failed the compare and the function returned early before the background UpdateAPIKeyLastUsed ran, breaking the mock's Once expectation. Real DB rows always carry KeyHash, so the fixture must set it to represent the actual validated path.
1 parent 148c0a5 commit 1c30951

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎internal/auth/service_security_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ func TestValidateUserAPIKey_LastUsedSingleflight(t *testing.T) {
244244
ID: keyID,
245245
UserID: user.ID,
246246
IsActive: true,
247+
KeyHash: keyHash,
247248
KeyPrefix: rawKey[:8],
248249
}
249250

0 commit comments

Comments
 (0)