fix(provisioning): hardening — race-safe duplicates, error propagation, email identity, claims validation (issue #59) #72

Merged
amiryahaya merged 1 commit from feat/59-provision-hardening into main 2026-11-06 12:32:12 +01:00
Owner

Closes #59 — the four ponytail round-1 deferred findings (task 1.4 follow-ups), TDD: 6 failing tests first (ProvisionHardeningTests), then green.

#59.1 — race-safe duplicate registration: the unique-violation catch (lost in the task-1.4 rewire) now lives in UserProvisioningService — on violation: clear tracker, re-fetch by DID (email fallback, case-insensitive), apply the suspended/verification-upgrade invariants, and continue. The atomic claim already prevents double-join, so double-clicks/retries land 201/409, never 500.

#59.2 — error propagation: ProvisionUser returns Result<User>; suspended accounts now get 403 "Your account is suspended" and INV-03 mismatches "Email does not match the invitation" instead of the generic invite-code 403. The new tests exposed an extra gap beyond the issue: the legacy existing-user re-registration path bypassed ProvisionInviteeAsync entirely — a suspended account could re-register and consume an invite. Fixed with the same invariant on that path.

#59.3 — email identity: find-by-email is case-insensitive (pre-#59 rows hold mixed case from the old raw-claim writer); null is written instead of "" when a wallet identity has no email (empty strings dodge the Email IS NOT NULL filtered unique-index semantics).

#59.4 — claims validation: shared_claims.email on [SsdidPublic] /register/verify — and the same client-supplied field on accept-with-wallet — is sanitized via MailAddress.TryCreate + ≤160 chars (matching CreateInvitation); an invalid claim is treated as absent. The #33 takeover guard's email lookup is now case-insensitive to stay correct against mixed-case rows.

Suite 847/0/39 Release ×3; coverage gate 84.62% ≥ 80. With this merge, every Phase 1 task (1.1–1.13) is complete — the M1-close gate (issue #65, the first §2.6 ponytail-audit) is next.

Closes #59 — the four ponytail round-1 deferred findings (task 1.4 follow-ups), TDD: 6 failing tests first (`ProvisionHardeningTests`), then green. **#59.1 — race-safe duplicate registration**: the unique-violation catch (lost in the task-1.4 rewire) now lives in `UserProvisioningService` — on violation: clear tracker, re-fetch by DID (email fallback, case-insensitive), apply the suspended/verification-upgrade invariants, and continue. The atomic claim already prevents double-join, so double-clicks/retries land 201/409, never 500. **#59.2 — error propagation**: `ProvisionUser` returns `Result<User>`; suspended accounts now get 403 "Your account is suspended" and INV-03 mismatches "Email does not match the invitation" instead of the generic invite-code 403. The new tests exposed an extra gap beyond the issue: the legacy existing-user re-registration path bypassed `ProvisionInviteeAsync` entirely — **a suspended account could re-register and consume an invite**. Fixed with the same invariant on that path. **#59.3 — email identity**: find-by-email is case-insensitive (pre-#59 rows hold mixed case from the old raw-claim writer); null is written instead of "" when a wallet identity has no email (empty strings dodge the `Email IS NOT NULL` filtered unique-index semantics). **#59.4 — claims validation**: `shared_claims.email` on [SsdidPublic] /register/verify — and the same client-supplied field on accept-with-wallet — is sanitized via `MailAddress.TryCreate` + ≤160 chars (matching CreateInvitation); an invalid claim is treated as absent. The #33 takeover guard's email lookup is now case-insensitive to stay correct against mixed-case rows. Suite 847/0/39 Release ×3; coverage gate 84.62% ≥ 80. **With this merge, every Phase 1 task (1.1–1.13) is complete** — the M1-close gate (issue #65, the first §2.6 ponytail-audit) is next.
fix(provisioning): hardening — race-safe duplicates, error propagation, email identity, claims validation (issue #59)
All checks were successful
API CI / build-and-test (pull_request) Successful in 34m3s
729d9a8de5
TDD: 6 failing tests first (ProvisionHardeningTests), then:

- #59.1 race: unique-violation catch moved into UserProvisioningService —
  on violation clear tracker, re-fetch by DID/email, continue (the atomic
  claim already prevents double-join)
- #59.2 propagation: ProvisionUser returns Result<User>; suspended accounts
  and INV-03 mismatches surface their real errors instead of the generic
  invite-code 403. Suspended check also added to the legacy existing-user
  re-registration path (a suspended account could re-register and consume
  an invite — exposed by the new tests)
- #59.3 email identity: find-by-email case-insensitive (pre-#59 rows may
  hold mixed case); null written instead of "" when a wallet identity has
  no email
- #59.4 claims: shared_claims.email on [SsdidPublic] register/verify (and
  accept-with-wallet) sanitized via MailAddress.TryCreate + <=160 chars,
  invalid claim treated as absent; #33 takeover guard now case-insensitive
Sign in to join this conversation.
No description provided.