test(security): match the email code only as a whole number

The email binding audit test failed now and then because it searched the
whole audit JSON for the six-digit code. Audit event and request IDs start
with a long run of time digits, so a random code sometimes appeared inside
one of them. Treat only a code that no other digit touches as a leak.
This commit is contained in:
CaIon
2026-10-20 22:43:11 +08:00
parent f9a0634f84
commit 120dbeafb1
+3 -1
View File
@@ -645,7 +645,9 @@ func TestSecurityAccountEmailConfirmationAndAudit(t *testing.T) {
require.NoError(t, err)
assert.Contains(t, string(encoded), "user.binding_bind")
assert.NotContains(t, string(encoded), flow.FlowToken)
assert.NotContains(t, string(encoded), newCode)
// Audit event and request IDs are long runs of time digits that can
// contain the six-digit code by chance; only the whole code is a leak.
assert.NotRegexp(t, `(^|\D)`+newCode+`(\D|$)`, string(encoded))
})
}
}