fix(org,files): M2 P1 batch — canonical-root resolver, atomic org-approve, token endpoint PII leak (#92, #93, #94) #116

Merged
amiryahaya merged 2 commits from fix/m2-p1-batch-92-93-94 into main 2026-11-08 08:52:29 +01:00
Owner

Three M1-closure-audit P1 fixes (#84 umbrella), TDD RED->GREEN, 8 new tests:

#92 — /root/contents diverged from /root (B-7 flag missing in sibling)
GetRootFolderContents picked ANY ParentFolderId==null folder (no filter, no order) and auto-created without IsTenantRoot=true — a tenant with a personal root-level folder + canonical root got nondeterministic contents; uploads landed in a different folder than listings served. Fix: new TenantRootFolderResolver (flagged root -> promote earliest pre-flag root -> create flagged) shared by BOTH endpoints — divergence is now structurally impossible.

#93 — org approve could strand a request Approved with no tenant; retry impossible
The status flip committed FIRST, then slug generation could 409 (exhaustion) or SaveChanges could conflict — leaving the request Approved, the founder pointing at a tenant with no Owner row, and a retry hitting 'already decided'. Fix: one transaction around flip + slug + tenant + founder + membership + audit; any failure rolls the flip back (request stays Pending, retry genuinely retries). Audit moved inside the tx (an audit throw no longer 500s a committed approval). Notifications/email remain post-commit best-effort. Tests: slug-exhaustion (101 occupied slugs -> 409 with request still Pending, founder untouched) + injected mid-transaction save failure (AuditService decorator, fires once -> 409 -> retry succeeds end-to-end).

#94 — public /token/ matched short codes and leaked invitee email
The OR clause defeated the endpoint's own full-token-only contract; anyone holding the short code (travels in emails/admin lists) got the invitee Email. Fix: drop the ShortCode clause; /code/ keeps the PII-free preview (guard test included).

Also: AuditService.LogAsync made virtual (test seam). Suite 927/0/39 (Release+Debug) locally. Closes #92, closes #93, closes #94.

Three M1-closure-audit P1 fixes (#84 umbrella), TDD RED->GREEN, 8 new tests: **#92 — /root/contents diverged from /root (B-7 flag missing in sibling)** GetRootFolderContents picked ANY ParentFolderId==null folder (no filter, no order) and auto-created without IsTenantRoot=true — a tenant with a personal root-level folder + canonical root got nondeterministic contents; uploads landed in a different folder than listings served. Fix: new TenantRootFolderResolver (flagged root -> promote earliest pre-flag root -> create flagged) shared by BOTH endpoints — divergence is now structurally impossible. **#93 — org approve could strand a request Approved with no tenant; retry impossible** The status flip committed FIRST, then slug generation could 409 (exhaustion) or SaveChanges could conflict — leaving the request Approved, the founder pointing at a tenant with no Owner row, and a retry hitting 'already decided'. Fix: one transaction around flip + slug + tenant + founder + membership + audit; any failure rolls the flip back (request stays Pending, retry genuinely retries). Audit moved inside the tx (an audit throw no longer 500s a committed approval). Notifications/email remain post-commit best-effort. Tests: slug-exhaustion (101 occupied slugs -> 409 with request still Pending, founder untouched) + injected mid-transaction save failure (AuditService decorator, fires once -> 409 -> retry succeeds end-to-end). **#94 — public /token/ matched short codes and leaked invitee email** The OR clause defeated the endpoint's own full-token-only contract; anyone holding the short code (travels in emails/admin lists) got the invitee Email. Fix: drop the ShortCode clause; /code/ keeps the PII-free preview (guard test included). Also: AuditService.LogAsync made virtual (test seam). Suite 927/0/39 (Release+Debug) locally. Closes #92, closes #93, closes #94.
fix(org,files): M2 P1 batch — canonical-root resolver, atomic org-approve, token endpoint PII leak (#92, #93, #94)
Some checks failed
Security CI / security-scan (pull_request) Successful in 3m34s
API CI / build-and-test (pull_request) Failing after 37m41s
0a50a66b16
#92: GetRootFolderContents picked ANY root-level folder (no IsTenantRoot
filter, no order) and auto-created unflagged roots — uploads could land in
a different folder than listings served. Extract TenantRootFolderResolver
(flagged root -> promote earliest -> create flagged) as the single source
of truth; both /api/folders/root and /root/contents now go through it.

#93: ApproveRequest committed the status flip FIRST, so slug exhaustion or
a save conflict stranded the request as Approved with no tenant — and a
retry hit 'already decided'. One transaction now wraps flip + slug + tenant
+ founder + membership + audit; any failure rolls the flip back so the
request stays Pending and 'please retry' is true. Notifications/email stay
post-commit best-effort.

#94: public /token/ endpoint matched short codes via an OR clause and
served the invitee Email to anyone holding the code. Full tokens only;
short codes keep the PII-free /code/ preview.

AuditService.LogAsync made virtual (test seam for the #93 injected-failure
test). 8 new tests, RED->GREEN: canonical-root selection, auto-create flag,
promote convergence, slug-exhaustion rollback, injected-failure rollback +
retry-succeeds, token-endpoint short-code rejection, full-token preview
guard, code-endpoint PII-free guard. Suite 927/0/39 Release+Debug.
ci: coverage-gate prints failing test blocks, not just log tail
All checks were successful
API CI / build-and-test (pull_request) Successful in 3m41s
Security CI / security-scan (pull_request) Successful in 1m57s
1e9599c07d
The tail-20 diagnostic landed on Redis-testcontainer SKIP noise and hid
which test failed under coverlet (seen on PR #116: coverage leg failed 1
test, name invisible in the job log). Now greps and prints every [FAIL]
block with its assertion + stack.
Sign in to join this conversation.
No description provided.