feat(identity): confirm the email address with a six-digit code from the message

This commit is contained in:
shira committed 2026-10-10 00:52:46 +03:00
1 parent c94434cd09
commit d365a05c96
87 files changed
+4764 -224

No files matched your search

+30 -8
View File
@@ -50,8 +50,11 @@ const (
// The production default is a minute.
registrationMinInterval = 3 * time.Second
registrationDailyLimit = 3
registrationSecret = "integration-test-identity-key-secret-0123456789"
registrationApplication = "registration_http"
// registrationEmailHourlyLimit is the production default of the login
// limit per address, which code confirmation shares.
registrationEmailHourlyLimit = 10
registrationSecret = "integration-test-identity-key-secret-0123456789"
registrationApplication = "registration_http"
)
var (
@@ -163,6 +166,7 @@ func newRegistrationHarness(ctx context.Context, t *testing.T, env *testEnvironm
}, identity.ConfirmationSettings{
TokenHourlyLimit: 2,
ClientHourlyLimit: clientHourlyLimit,
EmailHourlyLimit: registrationEmailHourlyLimit,
})
if err != nil {
t.Fatalf("NewEmailConfirmation() error = %v", err)
@@ -301,23 +305,41 @@ func (harness *registrationHarness) registerAndSendVerification(
ctx context.Context,
t *testing.T,
email, scenario, password string,
) string {
t.Helper()
link := verificationLinkToken.FindStringSubmatch(harness.registerAndReceiveVerification(ctx, t, email, scenario, password))
if link == nil {
t.Fatal("the received verification message has no token in its link fragment")
}
return link[1]
}
// registerAndReceiveVerification registers the address, delivers the queued
// message through the fixture, and returns the text of the message.
func (harness *registrationHarness) registerAndReceiveVerification(
ctx context.Context,
t *testing.T,
email, scenario, password string,
) string {
t.Helper()
requestCount := len(harness.fixture.Requests())
response := harness.registerBody(t, registrationBody(email, scenario, password, registrationC1), "")
requireAccepted(t, response)
return harness.receiveVerificationText(ctx, t, email, requestCount)
}
// receiveVerificationText drains the sending worker and returns the text of the
// one message the fixture received after requestCount requests.
func (harness *registrationHarness) receiveVerificationText(ctx context.Context, t *testing.T, email string, requestCount int) string {
t.Helper()
if settled := harness.drain(ctx, t); settled != 1 {
t.Fatalf("settled %d deliveries, want 1", settled)
}
received := harness.fixture.Requests()[requestCount:]
if len(received) != 1 || !slices.Equal(received[0].To, []string{email}) {
t.Fatalf("fixture received %d messages for the registration, want one to the registered address", len(received))
t.Fatalf("fixture received %d messages, want one to the registered address", len(received))
}
link := verificationLinkToken.FindStringSubmatch(received[0].Text)
if link == nil {
t.Fatal("the received verification message has no token in its link fragment")
}
return link[1]
return received[0].Text
}
// truncate empties the tables of the flow. CASCADE also empties tables that