test+docs(email): squat-fix coverage and the email-pipeline docs
Add an integration test asserting the guest-until-confirmed squat fix (an email-login account is a reapable guest until the code is confirmed, then durable). Document the branded relay pipeline in ARCHITECTURE (go-mail, TLS by port, no client cert, PUBLIC_BASE_URL anti-injection, per-recipient send throttle, guest-until-confirmed), FUNCTIONAL (+ru), TESTING and the backend README config table (BACKEND_SMTP_* + BACKEND_PUBLIC_BASE_URL).
This commit is contained in:
@@ -244,3 +244,37 @@ func TestEmailLoginFlow(t *testing.T) {
|
||||
t.Errorf("returning login account = %s, want %s", acc2.ID, accountID)
|
||||
}
|
||||
}
|
||||
|
||||
// TestEmailLoginProvisionsGuestUntilConfirmed covers the squat fix: an email-login
|
||||
// account is a guest (reapable, so an abandoned never-confirmed login frees its
|
||||
// address) until the code is confirmed, which promotes it to a durable account.
|
||||
func TestEmailLoginProvisionsGuestUntilConfirmed(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store := account.NewStore(testDB)
|
||||
mailer := &capturingMailer{}
|
||||
svc := account.NewEmailService(store, mailer, "https://erudit-game.ru")
|
||||
email := "squat-" + uuid.NewString() + "@example.com"
|
||||
|
||||
id, err := svc.RequestLoginCode(ctx, email, "", "en")
|
||||
if err != nil {
|
||||
t.Fatalf("request login code: %v", err)
|
||||
}
|
||||
before, err := store.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
t.Fatalf("get before confirm: %v", err)
|
||||
}
|
||||
if !before.IsGuest {
|
||||
t.Error("an unconfirmed email-login account must be a guest so it is reapable")
|
||||
}
|
||||
|
||||
if _, err := svc.LoginWithCode(ctx, email, sixDigit.FindString(mailer.lastBody)); err != nil {
|
||||
t.Fatalf("login: %v", err)
|
||||
}
|
||||
after, err := store.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
t.Fatalf("get after confirm: %v", err)
|
||||
}
|
||||
if after.IsGuest {
|
||||
t.Error("confirming the login must clear the guest flag (promote to durable)")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user