Skip to content

Commit 6927c3f

Browse files
fix(plugin-auth)!: a self-serve social creation is admitted only with a provider-verified address under an address-based posture (#35200)
Clause-②: no (narrowing: a creation admitted today is refused; owes one CONTRACT_REVIEW_TIER review before the queue) Metadata-protocol: none Skills-docs: none — no skill under `skills/**` teaches the audience posture or a social-provider sign-in; `content/docs/permissions/authentication.mdx` and `content/docs/deployment/tenancy-modes.mdx` gain the rule in this change. No-card security order (seat `security#1`); there is no issue to close. ## 维护者速读 - 改了什么:`email_domain` 准入模式下,以及 `open` 模式在邮箱验证生效时,经社交登录(`socialProviders`)新建账号,只有在提供方报告邮箱已验证时才准入;否则在准入闸门处以 `403 SELF_REGISTRATION_CLOSED` 拒绝,与 `invite_only` 一致:不建账号、不发会话、不建成员关系。发给该地址的待处理邀请也不放行这种创建。 - 为什么改:执行维护者对本单的裁决:准入建立在邮箱地址之上的模式,社交登录新建账号须由提供方验证该地址;规则按创建类别判定,之后新增的社交提供方自动覆盖,不需逐个登记。 - 风险与回滚:BREAKING(窄化)。在 `email_domain`、或验证生效的 `open` 部署上,依赖「提供方报告未验证邮箱」也能注册的社交登录改为被拒。运营方注册的身份提供方(`oidcProviders`、SSO)、管理员创建、SCIM、全新安装的首个账号、部署声明关闭验证的 `open` 均不变。回滚即 revert 本 PR。 - 先看:`packages/plugins/plugin-auth/src/audience-posture.ts` 的 `decideAudienceAdmission`(���表守卫之后、邀请豁免之前新增的一条判定)与 `admissionRestsOnAddress`;`auth-manager-membership-admission.ts` 向判定传入的三个输入;`invitation-acceptance-verified-address.test.ts` 末尾新增的顶层 describe。 - 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run src/invitation-acceptance-verified-address.test.ts src/audience-posture.test.ts`,预期 2 个文件、125 个用例全绿。 - 需要你做的:无,席位落地(窄化在入队前先有一次 CONTRACT_REVIEW_TIER 审核记录)。 ## What changes **The rule.** Under an audience posture whose admission rests on the address (`email_domain` always; `open` while email verification is in force), a self-serve creation through a social provider is admitted only when the provider verified the address. Otherwise it is refused at the admission gate with `403 SELF_REGISTRATION_CLOSED`, as `invite_only` already refuses it: no account row, no session, no membership. The binding rule and ADR-0093 are unchanged. - `packages/plugins/plugin-auth/src/audience-posture.ts`: `decideAudienceAdmission` gains the rule as one predicate, after the creation-class exemptions, the bootstrap carve-out and the vocabulary guard, and before the invitation carve-out and the posture switch, so every admit after it is covered. Its input gains `method`, `emailVerified` (verified only when it is `true`) and `declaredEmailVerification`, which the decision resolves through `resolveEmailVerificationRequirement`, the resolver the better-auth wiring and the public config already read; absent resolves to the posture default, so under `open` the rule holds unless the deployment declared an explicit `false`. Two module-private helpers: `isSocialProviderCreation` (a `self-serve` creation whose method is `oauth`, which is how a social provider is told apart from an operator-registered `oidcProviders` entry, already classed `provider`) and `admissionRestsOnAddress`. The module doc gains the section "A social provider's word on the address", and the invitation carve-out paragraph names the exception. - `packages/plugins/plugin-auth/src/auth-manager-membership-admission.ts`: `validateAudienceAdmission` hands the decision the vendor's `source.method`, `user.emailVerified` and the live `emailAndPassword.requireEmailVerification`. Nothing else in the gate moves. - `content/docs/permissions/authentication.mdx` (OAuth callback section), `content/docs/deployment/tenancy-modes.mdx` (membership reconciler bullet) and `content/docs/deployment/self-hosting.mdx` (the `email_domain` invitation paragraph and "Email verification under each posture") state the rule. - `.changeset/social-creation-needs-provider-verified-address.md`: `patch` on `@objectstack/plugin-auth`, the two declaration lines, `Skills-docs:`, the ADR-0087 disposition and the BREAKING note with what to do. **Decisions this order left to the PR, and which way each went:** - **The off-allowlist invitation case takes the same refusal.** Under `email_domain`, an address off the allowlist that a pending invitation is addressed to, signing in through a social provider that did not verify it, is now refused like any other unverified social creation, rather than keeping the outcome #34969 pinned for it. Why: the invitation is matched by the very address the provider did not verify, and `invite_only` already refuses an unverified OAuth creation whatever invitation is addressed to it (`invitationProofFor`), so one rule reads the same under every posture and the refusal leaves nothing behind. Nobody is dead-ended: once the provider verifies the address the same person is admitted and accepts the invited role (pinned), and the email-and-password sign-up and the invitation mail's one-step link keep working as before. The same holds for an invitation under `open` with verification in force. - **The bootstrap carve-out stays ahead of the rule**, as it does under `invite_only`: the first account of a fresh install is admitted whatever the provider said (pinned at the decision level). - **The refusal reuses `SELF_REGISTRATION_CLOSED`**, the code `invite_only` already answers this creation with, with its own description naming the posture. No error code is added, so the ADR-0112 ledger does not move. - **An off-allowlist address with no invitation** now meets this refusal rather than `EMAIL_DOMAIN_NOT_ALLOWED` when the provider did not verify it, because the rule sits ahead of the posture switch; with a verified address it still meets `EMAIL_DOMAIN_NOT_ALLOWED`. Every non-social creation keeps its refusal codes. ## Tests All counts below are vitest's own summary lines; red was taken on the unfixed source, green and the ablation on `9f4fd3cd`. - **Red before the fix, on the real engine** (`AuthManager` over `@objectstack/driver-sql` on better-sqlite3, the real `/sign-in/social` door): 10 of the new pins fail and every control passes (`Tests 10 failed | 115 passed (125)`). The red set includes the three real-engine refusal pins (`email_domain` on the allowlist, `open` with verification in force, the off-allowlist invitation case). - **Green after the fix**: `Tests 125 passed (125)` on the two files; `144 passed` across those two plus `presented-invitation.test.ts` and `audience-bootstrap-seam.test.ts`; the whole package `Test Files 285 passed (285)`, `Tests 6014 passed | 10 skipped (6024)`. - **Ablation** (`scripts/ablation-replace.mjs`, wrap mode, with a trap restore): the predicate's first operand replaced so the rule never fires. Mutation proven on disk (anchor x1 -> x0, blob `f2f2b8a4` -> `1879d950`); the run reds exactly the 10 refusal pins (`Tests 10 failed | 115 passed (125)`) while every control stays green; restored blob equals HEAD (`f2f2b8a4`) and `git diff HEAD` is empty. New pins, named by the rule: - `invitation-acceptance-verified-address.test.ts`, new top-level describe "under an address-based audience posture, a self-serve social creation is admitted only with a provider-verified address": refusal under `email_domain` on the allowlist and under `open` with verification in force (403 `SELF_REGISTRATION_CLOSED`, not signed in, and the `sys_user` / `sys_account` / `sys_session` / `sys_member` row counts unchanged); CONTROL: a provider-verified sign-in admits, signs in and binds to the default organization under both; CONTROL: `open` with the deployment's verification declared off admits as before. - Same file, the `email_domain` invitation describe: the off-allowlist invitation case is refused with nothing written and the invitation still pending, then the provider-verified sign-in is admitted and accepts the invited role. - `audience-posture.test.ts`, two new top-level describes: the decision matrix (only `emailVerified === true` counts; `email_domain` whatever the deployment declares; an invitation does not admit; `open` refused while verification is in force; CONTROL rows for `open` with verification off, the `provider` and `operator` classes, every other self-serve method, the bootstrap carve-out and `invite_only`) and the real manager's gate (any social providerId, one configured later included, refused; an `oidcProviders` entry and an `sso-oidc` provider admitted whatever they said; `open` forced vs declared off). ## Acceptance notes - Three existing cases in `invitation-acceptance-verified-address.test.ts` drove a social account whose provider did not verify the address under `open` with verification in force; that creation is now refused. They now run under `open` with the deployment's verification declared off (`OPEN_VERIFICATION_OFF`), the one deployment where such an account is still created, so the accept, decline and listing rules for it stay exercised; their assertions are unchanged. - That file's `deployment()` now boots the self-registration permission set for `open` as well as `email_domain`, because an uninvited sign-up under `open` is granted the declared set; no existing case's outcome depends on it. - The console's callback page maps `SELF_REGISTRATION_CLOSED` to its "not invited" sentence (`ui/apps/console/src/pages/auth/ssoCallbackRefusal.ts`), whose docblock names only the `invite_only` emitter. For this refusal an invitation is not the remedy; the server's description, behind the page's technical details, names the remedy. Not changed here (outside this order's file surface); raised as an open question in the report. - The rule is told by creation class and method, so it covers every `oauth` creation that is not an `oidcProviders` entry, a social provider added later included. Other self-serve methods are unchanged by design: email-and-password keeps its forced verification before a session, and magic link and email OTP prove the mailbox in their own flow. - `auth-manager-auth-instance.ts` is not touched: the forced verification there still reaches `emailAndPassword` only, and the rule lives in the admission decision instead of a per-provider requirement. ## Verification Local subset at `bf6fa3de` (CI runs the full farm): - `pnpm --filter @objectstack/plugin-auth typecheck` (with the package built): exit 0, `check:test-typecheck: OK` with the test-layer debt unchanged. - `pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2`: exit 0, 285 files, 6014 passed, 10 skipped. - The diff-derived gate list (`node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`): 100 families derived from merge base `c480f335`; 99 exit 0, 1 NOT MEASURED: `pnpm check:dual-build-cjs-loads` exit 3 (PREREQUISITE NOT MET, it reads every package's built output and needs a repo-wide `pnpm build`; CI's `Lint & Repo Gates` runs it). Two first runs exited 3 and were re-run after meeting their prerequisite: `node scripts/check-plugin-teardown-shape.mjs --self-test` (its pinned fixture commit fetched into this shallow clone) exit 0, and `pnpm --filter @objectstack/spec run check:skill-examples` (after building `@objectstack/client-react` and its closure) exit 0. `--ran` reconciliation: `100 derived, 99 run, 1 NOT-MEASURED, 0 UNRUN`, every line carrying its exit code. `test:repo` is not run locally (no file of that project is in the diff); CI's `Test Core` runs it. - Dogfood battery on the final head: `bf6fa3de`, closure built (`pnpm --filter '@objectstack/dogfood^...' build`, exit 0), then `pnpm --filter @objectstack/dogfood test` under the verify lock: `VERDICT command-exit 0`, `Test Files 480 passed | 3 skipped (483)`, `Tests 4075 passed | 68 skipped (4143)`. --- _Generated by [Claude Code](https://claude.ai/code/session_01ASNY8VyogmQQgdcx5jLwwc)_ <!-- signed: security#1 · os-mickey · session_01ASNY8VyogmQQgdcx5jLwwc --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 0ca5218 commit 6927c3f

8 files changed

Lines changed: 383 additions & 16 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
fix(plugin-auth)!: a self-serve social creation is admitted only with a provider-verified address under an address-based posture
6+
7+
Clause-②: no (narrowing: a creation admitted today is refused; owes one CONTRACT_REVIEW_TIER review before the queue)
8+
Metadata-protocol: none
9+
Skills-docs: none — no skill under `skills/**` teaches the audience posture or a social-provider sign-in; `content/docs/permissions/authentication.mdx` and `content/docs/deployment/tenancy-modes.mdx` gain the rule in this change.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value or metadata type is added, removed, renamed or re-shaped. The moved answer is an account the admission gate does not create, so there is nothing stored for a migration to rewrite and no tombstone. -->
12+
13+
**BREAKING** for a deployment under the `email_domain` audience posture, or under `open` while email verification is in force, where people create their account by signing in through a social provider that reports the address unverified.
14+
15+
- Under `email_domain`, and under `open` while email verification is in force (the default there; only the deployment can declare it off), a new account through a social provider (`socialProviders`) is created only when the provider reports the address verified. Any other is refused `403 SELF_REGISTRATION_CLOSED` at the admission gate, as `invite_only` already refuses it: no account, no session, no membership. A browser sign-in redirects with `error=SELF_REGISTRATION_CLOSED`.
16+
- A pending invitation addressed to that person does not admit the creation either, under both postures: the invitation is matched by the same address.
17+
- The rule is told by the creation class, not by a list of providers, so a social provider added later is covered without being named.
18+
19+
Unchanged: a social provider that reports the address verified, which is admitted and bound as before; identity providers an operator registers (`oidcProviders` entries and SSO providers); accounts an administrator creates, SCIM provisioning and accounts a boot command provisions; the first account of a fresh install; email-and-password, magic-link and email-OTP sign-ups; `open` with the deployment's email verification declared off; and the `invite_only` posture.
20+
21+
What to do: a person refused this way verifies the address with the social provider and signs in again, or, where the deployment offers it, signs up with email and password and completes the verification mail. An invited person can also open the invitation mail's own link, which verifies the address and accepts in one step.

‎content/docs/deployment/self-hosting.mdx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,12 @@ posture, and while the account's address is unverified it joins no
781781
organization: it joins by accepting the invitation once the address is
782782
verified, and the acceptance writes the membership the invitation names. Verifying the address binds nothing by itself.
783783
An address on the list is admitted by its domain, invitation or not, and the
784-
membership policy binds it at creation as before.
784+
membership policy binds it at creation as before. Both admissions have one
785+
exception: under this posture a sign-in through a social provider creates an
786+
account only when the provider reports the address verified, and is otherwise
787+
refused `403 SELF_REGISTRATION_CLOSED`, whatever the list or an invitation
788+
says ([Authentication](/docs/permissions/authentication#2-handle-callback)).
789+
Once the provider verifies the address, the next sign-in is admitted.
785790

786791
**Accepting, declining and listing an invitation need a verified email
787792
address, on every deployment.** The invitation's `id`, which its link carries,
@@ -861,6 +866,12 @@ on `open`, keep verification on and connect a mail transport.
861866
`emailAndPassword.requireEmailVerification: false` in the stack config. A
862867
sign-up is then signed in at once and no verification mail is sent.
863868

869+
Under `email_domain`, and under `open` while verification is in force, a new
870+
account through a social provider is created only when the provider reports
871+
the address verified; otherwise the sign-in is refused
872+
`403 SELF_REGISTRATION_CLOSED` and nothing is written
873+
([Authentication](/docs/permissions/authentication#2-handle-callback)).
874+
864875
The `open` opt-out is for a deployment with no mail transport that trusts
865876
whoever can reach it, such as a pre-production environment. It is loud and it
866877
has a cost:

‎content/docs/deployment/tenancy-modes.mdx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,11 @@ The reconciler:
250250
invitation addressed to it admitted: that account joins by accepting the
251251
invitation, which needs a verified address
252252
([Self-hosting](/docs/deployment/self-hosting)). Under `email_domain` an
253-
address on the allowlist is admitted by its domain and is bound;
253+
address on the allowlist is admitted by its domain and is bound. A sign-in
254+
through a social provider that did not verify the address creates no
255+
account to bind under `email_domain`, or under `open` while email
256+
verification is in force: the audience gate refuses it
257+
([Authentication](/docs/permissions/authentication));
254258
- binds only to an **unambiguous** target org — that is `tenancy.defaultOrgId()`,
255259
which returns the single-org default organization under `single` and `null`
256260
under any walled **request** (invitations, `add-member` and SSO provisioning

‎content/docs/permissions/authentication.mdx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,19 @@ the callback redirects with `error=account_not_linked`. The platform identity pr
607607
(`objectstack-cloud`) is the one exception, and an unlinked provider never re-links
608608
itself. See [Linking to an existing account](/docs/permissions/sso#linking-to-an-existing-account).
609609

610+
A sign-in that would create a new account through a social provider is judged by the
611+
deployment's audience posture. Under `email_domain`, and under `open` while email
612+
verification is in force (the default; only the deployment can declare it off), the
613+
account is created only when the provider reports the address verified. Otherwise the
614+
sign-in is refused `403 SELF_REGISTRATION_CLOSED` (the callback redirects with
615+
`error=SELF_REGISTRATION_CLOSED`), as it is under `invite_only`, and nothing is written:
616+
no account, no session, no membership. A pending invitation addressed to the person does
617+
not change this, because it is matched by the same address; once the provider verifies
618+
the address, the next sign-in is admitted. The rule covers every provider in
619+
`socialProviders`, a provider added later included. Identity providers an operator
620+
registers (`oidcProviders` entries and SSO providers) are not affected, and neither is
621+
the first account of a fresh install.
622+
610623
---
611624

612625
## Enterprise Authentication Hardening (ADR-0069)

‎packages/plugins/plugin-auth/src/audience-posture.test.ts‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,3 +1128,143 @@ describe('a sign-up admitted by its invitation alone (isAdmittedByInvitationAlon
11281128
expect(alone({ audience: { ...DOMAIN, invalid: { raw: "'bogus'" } } })).toBe(false);
11291129
});
11301130
});
1131+
1132+
describe('a self-serve social creation under an address-based posture is admitted only with a provider-verified address', () => {
1133+
const DOMAIN = audience({ posture: 'email_domain', allowedEmailDomains: ['acme.com'], selfRegistrationPermissionSet: 'portal_user' });
1134+
const OPEN_POSTURE = audience({ posture: 'open', selfRegistrationPermissionSet: 'portal_user' });
1135+
const decide = (over: Partial<Parameters<typeof decideAudienceAdmission>[0]> = {}) =>
1136+
decideAudienceAdmission({
1137+
audience: DOMAIN,
1138+
creationClass: 'self-serve',
1139+
method: 'oauth',
1140+
email: 'user@acme.com',
1141+
hasPendingInvitation: false,
1142+
isBootstrap: false,
1143+
...over,
1144+
});
1145+
const expectRefused = (verdict: ReturnType<typeof decideAudienceAdmission>, label?: string) => {
1146+
expect(verdict.admit, label).toBe(false);
1147+
if (!verdict.admit) expect(verdict.code, label).toBe(SELF_REGISTRATION_CLOSED);
1148+
};
1149+
1150+
it('email_domain: an address on the allowlist is refused unless the provider reported it verified, `true` and nothing else', () => {
1151+
for (const emailVerified of [false, undefined, null, 'true', 1]) expectRefused(decide({ emailVerified }), String(emailVerified));
1152+
expect(decide({ emailVerified: true })).toEqual({ admit: true, grantPermissionSet: true });
1153+
});
1154+
1155+
it('email_domain: verification is in force whatever the deployment declares', () => {
1156+
for (const declaredEmailVerification of [undefined, true, false]) {
1157+
expectRefused(decide({ emailVerified: false, declaredEmailVerification }), String(declaredEmailVerification));
1158+
}
1159+
});
1160+
1161+
it('email_domain: a pending invitation addressed to the creation does not admit it while the provider did not verify the address', () => {
1162+
expectRefused(decide({ email: 'contractor@partner.example', hasPendingInvitation: true, emailVerified: false }));
1163+
expectRefused(decide({ hasPendingInvitation: true, emailVerified: false }));
1164+
expect(decide({ email: 'contractor@partner.example', hasPendingInvitation: true, emailVerified: true })).toEqual({
1165+
admit: true,
1166+
grantPermissionSet: false,
1167+
});
1168+
});
1169+
1170+
it('open: refused while email verification is in force (undeclared or declared true), an invitation included', () => {
1171+
for (const declaredEmailVerification of [undefined, true]) {
1172+
expectRefused(decide({ audience: OPEN_POSTURE, emailVerified: false, declaredEmailVerification }), String(declaredEmailVerification));
1173+
}
1174+
expectRefused(decide({ audience: OPEN_POSTURE, emailVerified: false, hasPendingInvitation: true }));
1175+
expect(decide({ audience: OPEN_POSTURE, emailVerified: true })).toEqual({ admit: true, grantPermissionSet: true });
1176+
});
1177+
1178+
it('CONTROL: open with email verification declared off by the deployment admits as before', () => {
1179+
expect(decide({ audience: OPEN_POSTURE, emailVerified: false, declaredEmailVerification: false })).toEqual({
1180+
admit: true,
1181+
grantPermissionSet: true,
1182+
});
1183+
});
1184+
1185+
it('CONTROL: the operator-registered provider class and the operator class are admitted whatever the provider said', () => {
1186+
for (const aud of [DOMAIN, OPEN_POSTURE]) {
1187+
for (const [creationClass, method] of [['provider', 'oauth'], ['provider', 'sso-oidc'], ['provider', 'sso-saml'], ['operator', 'admin'], ['operator', 'scim']] as const) {
1188+
expect(decide({ audience: aud, creationClass, method, emailVerified: false }), `${aud.posture} ${creationClass} ${method}`).toEqual({
1189+
admit: true,
1190+
grantPermissionSet: false,
1191+
});
1192+
}
1193+
}
1194+
});
1195+
1196+
it('CONTROL: every other self-serve method is judged as before', () => {
1197+
for (const method of ['email-password', 'magic-link', 'email-otp', undefined]) {
1198+
expect(decide({ method, emailVerified: false }), String(method)).toEqual({ admit: true, grantPermissionSet: true });
1199+
expect(decide({ audience: OPEN_POSTURE, method, emailVerified: false }), String(method)).toEqual({ admit: true, grantPermissionSet: true });
1200+
}
1201+
});
1202+
1203+
it('the bootstrap carve-out stays ahead of the rule: the first account of a fresh install is admitted', () => {
1204+
for (const aud of [DOMAIN, OPEN_POSTURE]) {
1205+
expect(decide({ audience: aud, isBootstrap: true, emailVerified: false })).toEqual({ admit: true, grantPermissionSet: false });
1206+
}
1207+
});
1208+
1209+
it('CONTROL: under invite_only the invitation proof carries the rule, and the decision reads as before', () => {
1210+
expectRefused(decide({ audience: audience(), emailVerified: false }));
1211+
expect(decide({ audience: audience(), emailVerified: true, hasPendingInvitation: true })).toEqual({ admit: true, grantPermissionSet: false });
1212+
});
1213+
1214+
it('the refusal names the posture it was judged under', () => {
1215+
for (const aud of [DOMAIN, OPEN_POSTURE]) {
1216+
const verdict = decide({ audience: aud, emailVerified: false });
1217+
expect(verdict.admit).toBe(false);
1218+
if (!verdict.admit) expect(verdict.message).toContain(aud.posture);
1219+
}
1220+
});
1221+
});
1222+
1223+
describe('the admission gate: a self-serve social creation needs a provider-verified address under an address-based posture', () => {
1224+
const nonBootstrapCtx = { context: { adapter: { findOne: async () => ({ id: 'usr_existing' }) } } };
1225+
const gateOf = (manager: AuthManager) => (user: Record<string, unknown>, source: Record<string, unknown>) =>
1226+
(manager as any).validateAudienceAdmission({ user, source: { action: 'create-user', ...source } }, nonBootstrapCtx);
1227+
const social = (providerId = 'google') => ({ method: 'oauth', oauth: { providerId } });
1228+
1229+
it('email_domain: refused unless the provider verified the address, for any social provider; an oidcProviders entry and an SSO provider are admitted whatever they said', async () => {
1230+
const engine = createMemoryEngine();
1231+
seedExistingUser(engine);
1232+
seedPermissionSet(engine, 'portal_user');
1233+
const gate = gateOf(
1234+
makeManager(engine, {
1235+
getTenancy: SINGLE_TENANCY,
1236+
audience: { posture: 'email_domain', allowedEmailDomains: ['acme.com'], selfRegistrationPermissionSet: 'portal_user' },
1237+
oidcProviders: [
1238+
{ providerId: 'okta', clientId: 'x', clientSecret: 'y', discoveryUrl: 'https://idp.example/.well-known/openid-configuration' },
1239+
],
1240+
}),
1241+
);
1242+
expect((await gate({ email: 'jit@acme.com', emailVerified: false }, social()))?.error).toBe(SELF_REGISTRATION_CLOSED);
1243+
expect((await gate({ email: 'jit@acme.com' }, social()))?.error).toBe(SELF_REGISTRATION_CLOSED);
1244+
expect((await gate({ email: 'jit@acme.com', emailVerified: false }, social('a-provider-configured-later')))?.error).toBe(
1245+
SELF_REGISTRATION_CLOSED,
1246+
);
1247+
expect(await gate({ email: 'jit@acme.com', emailVerified: true }, social())).toBeUndefined();
1248+
1249+
expect(await gate({ email: 'jit@acme.com', emailVerified: false }, social('okta'))).toBeUndefined();
1250+
expect(await gate({ email: 'jit@acme.com', emailVerified: false }, { method: 'sso-oidc', sso: { providerId: 'acme' } })).toBeUndefined();
1251+
});
1252+
1253+
it('open: refused while email verification is in force, admitted once the deployment declares it off', async () => {
1254+
const forced = createMemoryEngine();
1255+
seedExistingUser(forced);
1256+
seedPermissionSet(forced, 'portal_user');
1257+
const open = { posture: 'open', selfRegistrationPermissionSet: 'portal_user' };
1258+
const forcedGate = gateOf(makeManager(forced, { getTenancy: SINGLE_TENANCY, audience: open }));
1259+
expect((await forcedGate({ email: 'joiner@anywhere.com', emailVerified: false }, social()))?.error).toBe(SELF_REGISTRATION_CLOSED);
1260+
expect(await forcedGate({ email: 'joiner@anywhere.com', emailVerified: true }, social())).toBeUndefined();
1261+
1262+
const off = createMemoryEngine();
1263+
seedExistingUser(off);
1264+
seedPermissionSet(off, 'portal_user');
1265+
const offGate = gateOf(
1266+
makeManager(off, { getTenancy: SINGLE_TENANCY, audience: open, emailAndPassword: { requireEmailVerification: false } }),
1267+
);
1268+
expect(await offGate({ email: 'joiner@anywhere.com', emailVerified: false }, social())).toBeUndefined();
1269+
});
1270+
});

0 commit comments

Comments
 (0)