Skip to content

Commit a0e2d77

Browse files
test(app-shell): pin Setup's SSO provider edit actions through the generic action form (#32370)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBXHkgowpKDfaVB6mkWcCXPt)_ Fixes #32185 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:只加测试。在共享的 action-runtime 测试夹具 `useConsoleActionRuntime.createUserRequiredField-28289.test.tsx` 里新增两个顶层 describe(8 个用例),钉住 Setup → SSO Providers 的「Edit SAML Settings」「Edit OIDC Settings」走通用参数表单时的行为;夹具的 `useObjectLabel` 替身补了 `actionResultDialog` 透传。没有改产品代码。 - 为什么改:#32185 第 1 项约定,若通用表单能正确渲染这些字段,本卡只做一次实测。真实 showcase 实测(截图见下表)显示通用表单全部达标:证书是多行 textarea、粘贴的 PEM 逐字节(含换行)提交;Client Secret 是空的 password 输入、留空不提交;providerId/issuer 取自行;两类拒绝与结果弹窗都能读懂。因此无需专用表单。 - 风险与回滚:仅测试文件,零运行时影响;回滚即 revert。 - 先看:测试文件末尾 `objectstack#32185 item 1` 两个 describe;下方「实测表」。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/hooks/__tests__/useConsoleActionRuntime.createUserRequiredField-28289.test.tsx`,预期 22 passed。 - 需要你做的:无,席位落地。本 PR 关闭 #32185(第 2 项已由 #32235 落地,第 1 项是最后一项)。 ## What changes Two new top-level `describe` blocks in the shared action-runtime harness (AGENTS.md: a new pin for a component with a shared harness file goes into that file, ruling record 6583487846). They drive the declared `edit_saml_provider` / `edit_oidc_provider` params (restated from `packages/platform-objects/src/identity/sys-sso-provider.object.ts`, help texts trimmed) through a real `ActionRunner`, the console runtime's api, param and result-dialog handlers and the real `ActionParamDialog`, with the door as the mocked authenticated fetch answering what `runUpdateSsoProviderFromForm` (`packages/plugins/plugin-auth/src/register-sso-provider.ts`) answers: - SAML: the certificate input is a `TEXTAREA`; a PEM with line breaks posts unchanged; `providerId` and `issuer` default from the row; a blank `entryPoint` posts nothing; `keepCurrentCert` is not sent as on when left alone; the result dialog shows the bridge's "updated: cert." line; the linked-user `409` stays in the dialog's refusal box. - OIDC: the client secret is an empty `type="password"` input; blank secret, client id and scopes post nothing; a typed secret posts once and never appears in the result dialog; the wrong-protocol `400` stays in the dialog's refusal box. The harness's `useObjectLabel` double gains `actionResultDialog: (_o, _a, spec) => spec` so the runtime's result-dialog handler can run; the existing cases do not call it. No renderer change: no gap was measured, so there is no red-on-main leg to show. ## Live check Showcase boot at `e883c71f` with `OS_SSO_ENABLED=true` (`objectstack dev --seed-admin`), console from `ui/apps/console` vite. Both providers were registered through Setup's own Register forms (SAML with an `openssl` self-signed cert; OIDC against a local discovery stub). Screenshots are in the project files under `ui-orders/32185-item1/`. | Check | Seen | Verdict | Shot | |:--|:--|:--|:--| | Certificate input is multi-line | `<textarea id="cert">`, empty on open | fine | `10-edit-saml-open.png` | | Pasted PEM posts byte-for-byte | action body `params.cert` equals the PEM file exactly, 19 line breaks both sides; stored `samlConfig.cert` equals it (bridge trims only the outer newline) | fine | `11-edit-saml-pem-pasted.png`, `12-edit-saml-result.png` | | Keep trusting current cert | checkbox posts `keepCurrentCert: true`; stored `cert` becomes a 2-item list | fine | `13-…`, `14-edit-saml-keep-current-result.png` | | Client secret | `<input type="password" autocomplete="new-password">`, empty on open and after a secret change; posted only when typed | fine | `20-edit-oidc-open.png`, `23-edit-oidc-reopen.png` | | Blank fields keep stored values | all-blank OIDC posts `{providerId}` only and gets the bridge's "Nothing to change" sentence in the dialog; after a secret-only and a scopes-only edit, stored `clientId` and SAML `entryPoint` are unchanged; a field typed then cleared posts `""`, which the bridge reads as keep | fine | `21-edit-oidc-all-blank.png`, `52-oidc-header-scopes-result.png` | | `providerId` / `issuer` default from row | both prefilled from the row on row and record-header launches | fine | `10-…`, `20-…` | | Identity change while users linked | `409` relayed: dialog stays open, box leads with "…Cannot change SSO provider identity fields while linked accounts exist." and keeps the bridge's hint behind **More**; the toast shows the whole sentence | fine | `40-saml-identity-refused-linked.png`, `41-…-more.png`, `51-oidc-header-clientid-refused-linked.png` | | Wrong protocol | `400` relayed: "…is an OIDC provider, so cert does not apply to it (that is "Edit SAML Settings")." with "Use "Edit OIDC Settings"." behind **More**, and in full in the toast | fine | `30-wrong-protocol.png` | | `resultDialog` shows what changed | "SAML settings saved / Changed: SSO provider "acme-saml" updated: cert."; OIDC likewise for `clientSecret`, `scopes` | fine | `12-…`, `22-edit-oidc-secret-result.png`, `52-…` | | Record header | both actions under the record sheet's **More actions** menu; same dialog | fine | `50-oidc-record.png`, `50b-oidc-record-menu.png` | | Hidden for a non-platform-admin | a member (`auditor.demo`) and an org admin both get "You don't have access to this app" on Setup, so no row or header is drawn; the action door answers both `403 PERMISSION_DENIED … requires capability [manage_platform_settings]` | fine (the `visible` term itself is not reachable without Setup access) | `60-nonadmin-list.png`, `60-orgadmin-list.png` | Notes, not gaps: - The refusal box shows the first sentence and keeps the rest one click behind **More** (objectui#13332's design); for the wrong-protocol refusal the hidden part is "Use "Edit OIDC Settings"." The toast raised beside it carries the whole sentence. - The card text lists an OIDC issuer among the editable fields. The server door deliberately does not offer it (bridge header: endpoints come from discovery at registration only); the bridge refuses a changed issuer with a sentence saying to register a new provider. That is #32268's ruling, not a console gap. ## Verification Tree: `objectstack-ai/objectstack` at `42300972` (base `e883c71f`). All under `scripts/pm/os-verify-lock.sh` (one held turn). - `pnpm --dir ui exec vitest run packages/app-shell/src/hooks/__tests__/useConsoleActionRuntime.createUserRequiredField-28289.test.tsx`: exit 0, 22 passed (14 existing + 8 new). - `pnpm --filter @object-ui/app-shell run type-check`: exit 0. - `npx eslint` on the test file from `ui/packages/app-shell`: 0 errors (47 `no-explicit-any` warnings, the file's existing style). - `node scripts/pm/dispatch-gates.mjs --commands` derived 26 commands; all 26 ran with exit 0, and `--ran` gives `26 derived famil(ies) accounted for — 26 run, 0 NOT-MEASURED`. - No changeset: only a test in the private `@object-ui/app-shell` changes (`skip-changeset`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzfXBsXXNG9DdUkrGnp Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3d744f1 commit a0e2d77

1 file changed

Lines changed: 221 additions & 0 deletions

File tree

‎ui/packages/app-shell/src/hooks/__tests__/useConsoleActionRuntime.createUserRequiredField-28289.test.tsx‎

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({
4848
actionDescription: (_o: any, _a: any, fallback: any) => fallback,
4949
actionSubmitText: (_o: any, _a: any, fallback: any) => fallback,
5050
actionCancelText: (_o: any, _a: any, fallback: any) => fallback,
51+
actionResultDialog: (_o: any, _a: any, spec: any) => spec,
5152
}),
5253
}));
5354
vi.mock('../useActionModal', () => ({
@@ -526,3 +527,223 @@ describe('objectstack#32297 — Register SSO Provider registers an Entra ID prov
526527
expect(params.mapEmail ?? '').toBe('');
527528
});
528529
});
530+
531+
/**
532+
* objectstack#32185 item 1 — Setup → SSO Providers → "Edit SAML Settings" and
533+
* "Edit OIDC Settings" draw through this same seam, the generic declared-action
534+
* form. The declared params are restated from `sys_sso_provider.edit_saml_provider`
535+
* / `edit_oidc_provider` (`@objectstack/platform-objects`, whose own pins hold
536+
* the declarations); help texts trimmed. The door is the mocked authenticated
537+
* fetch answering what plugin-auth's edit bridge answers
538+
* (`register-sso-provider.ts` `runUpdateSsoProviderFromForm`), so what is
539+
* pinned is the request the console sends and what it shows: the certificate
540+
* input is multi-line and a pasted PEM reaches the body byte-for-byte; the
541+
* client secret is a password input, never prefilled, and a blank one posts
542+
* nothing (the bridge reads blank as "keep"); `providerId` and `issuer` default
543+
* from the row; the result dialog names what changed.
544+
*/
545+
const UPDATE_PROVIDER = '/api/v1/auth/admin/sso/update-provider';
546+
const EDIT_SAML = {
547+
name: 'edit_saml_provider',
548+
label: 'Edit SAML Settings',
549+
type: 'api',
550+
method: 'POST',
551+
target: UPDATE_PROVIDER,
552+
refreshAfter: true,
553+
resultDialog: { title: 'SAML settings saved', acknowledge: 'Done', fields: [{ path: 'message', label: 'Changed', format: 'text' }] },
554+
};
555+
const EDIT_SAML_PARAMS = [
556+
{ name: 'providerId', field: 'provider_id', defaultFromRow: true, required: true },
557+
{ name: 'issuer', field: 'issuer', label: 'IdP Entity ID', defaultFromRow: true, required: false },
558+
{ name: 'entryPoint', label: 'IdP SSO URL', type: 'text', required: false },
559+
{ name: 'cert', label: 'New IdP Signing Certificate', type: 'textarea', required: false },
560+
{ name: 'keepCurrentCert', label: 'Keep trusting the current certificate', type: 'boolean', required: false },
561+
];
562+
const EDIT_OIDC = {
563+
name: 'edit_oidc_provider',
564+
label: 'Edit OIDC Settings',
565+
type: 'api',
566+
method: 'POST',
567+
target: UPDATE_PROVIDER,
568+
refreshAfter: true,
569+
resultDialog: { title: 'OIDC settings saved', acknowledge: 'Done', fields: [{ path: 'message', label: 'Changed', format: 'text' }] },
570+
};
571+
const EDIT_OIDC_PARAMS = [
572+
{ name: 'providerId', field: 'provider_id', defaultFromRow: true, required: true },
573+
{ name: 'clientId', label: 'Client ID', type: 'text', required: false },
574+
{ name: 'clientSecret', label: 'New Client Secret', type: 'password', required: false },
575+
{ name: 'scopes', label: 'Scopes', type: 'text', required: false, placeholder: 'openid email profile' },
576+
];
577+
/** The two row fields the params are backed by, as `sys_sso_provider` declares them. */
578+
const SSO_OBJECT = {
579+
name: 'sys_sso_provider',
580+
fields: {
581+
provider_id: { name: 'provider_id', type: 'text', label: 'Provider ID' },
582+
issuer: { name: 'issuer', type: 'text', label: 'Issuer' },
583+
},
584+
actions: [EDIT_SAML, EDIT_OIDC],
585+
};
586+
const SAML_ROW = { id: 'p1', provider_id: 'acme-saml', issuer: 'https://idp.acme.test/entity', domain: 'acme.test' };
587+
const OIDC_ROW = { id: 'p2', provider_id: 'acme-oidc', issuer: 'https://login.acme.test', domain: 'acme.test' };
588+
589+
/** A pasted PEM: armour, 64-column body lines, a trailing newline. */
590+
const PEM = [
591+
'-----BEGIN CERTIFICATE-----',
592+
'MIIBszCCAVmgAwIBAgIUQm9ndXNDZXJ0aWZpY2F0ZUZvclRlc3RzMAoGCCqGSM49',
593+
'BAMCMBkxFzAVBgNVBAMMDmlkcC5hY21lLnRlc3QwHhcNMjYxMTEwMDAwMDAwWhcN',
594+
'Mjcx',
595+
'-----END CERTIFICATE-----',
596+
'',
597+
].join('\n');
598+
599+
function SsoEditHarness({ onReady }: { onReady: (rt: ReturnType<typeof useConsoleActionRuntime>) => void }) {
600+
const runtime = useConsoleActionRuntime({
601+
dataSource: {},
602+
objects: [SSO_OBJECT] as any[],
603+
objectName: 'sys_sso_provider',
604+
});
605+
const ready = React.useRef(false);
606+
if (!ready.current) {
607+
ready.current = true;
608+
onReady(runtime);
609+
}
610+
return <>{runtime.dialogs}</>;
611+
}
612+
613+
/** Open `action` on `row` as a list-item click dispatches it: the declared params as `actionParams`, the row under `params._rowRecord`. */
614+
async function openEdit(action: typeof EDIT_SAML, params: unknown[], row: Record<string, unknown>) {
615+
let runtime!: ReturnType<typeof useConsoleActionRuntime>;
616+
render(
617+
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }}>
618+
<SsoEditHarness onReady={(rt) => { runtime = rt; }} />
619+
</I18nProvider>,
620+
);
621+
const runner = new ActionRunner({});
622+
runner.setParamCollectionHandler(runtime.paramCollectionHandler);
623+
runner.setToastHandler(vi.fn());
624+
runner.registerHandler('api', runtime.apiHandler);
625+
runner.setResultDialogHandler(runtime.resultDialogHandler);
626+
const settled: { result?: ActionResult } = {};
627+
await act(async () => {
628+
void runner.execute({ ...action, actionParams: params, params: { _rowRecord: row } } as any).then((r) => { settled.result = r; });
629+
});
630+
await screen.findByRole('dialog');
631+
return settled;
632+
}
633+
634+
function sentEditParams(actionName: string): Record<string, unknown> {
635+
const [url, init] = authFetchSpy.mock.calls[0] as [string, { body: string }];
636+
expect(String(url).endsWith(`/api/v1/actions/sys_sso_provider/${actionName}`)).toBe(true);
637+
return (JSON.parse(init.body) as { params: Record<string, unknown> }).params;
638+
}
639+
640+
function pressConfirm() {
641+
fireEvent.click(screen.getByRole('button', { name: /^(Confirm|Submit|OK)$/ }));
642+
}
643+
644+
describe('objectstack#32185 — Edit SAML Settings through the generic action form', () => {
645+
it('draws the certificate as a multi-line input and defaults providerId and issuer from the row', async () => {
646+
await openEdit(EDIT_SAML, EDIT_SAML_PARAMS, SAML_ROW);
647+
648+
const cert = await screen.findByLabelText(/^New IdP Signing Certificate/);
649+
expect(cert.tagName).toBe('TEXTAREA');
650+
expect(cert).toHaveValue('');
651+
expect(screen.getByLabelText(/^IdP Entity ID/)).toHaveValue(SAML_ROW.issuer);
652+
expect(screen.getByLabelText(/^IdP SSO URL/)).toHaveValue('');
653+
});
654+
655+
it('a pasted PEM posts byte-for-byte, line breaks included', async () => {
656+
answer(200, { success: true, data: { providerId: 'acme-saml', protocol: 'saml', updated: ['cert'], message: 'SSO provider "acme-saml" updated: cert.' } });
657+
await openEdit(EDIT_SAML, EDIT_SAML_PARAMS, SAML_ROW);
658+
659+
fireEvent.change(await screen.findByLabelText(/^New IdP Signing Certificate/), { target: { value: PEM } });
660+
pressConfirm();
661+
662+
await waitFor(() => expect(authFetchSpy).toHaveBeenCalledTimes(1));
663+
const params = sentEditParams('edit_saml_provider');
664+
expect(params.cert).toBe(PEM);
665+
expect(params.providerId).toBe('acme-saml');
666+
expect(params.issuer).toBe(SAML_ROW.issuer);
667+
expect(params.entryPoint ?? '').toBe('');
668+
expect(params.keepCurrentCert === true || params.keepCurrentCert === 'true').toBe(false);
669+
});
670+
671+
it('the result dialog names what changed', async () => {
672+
answer(200, { success: true, data: { providerId: 'acme-saml', protocol: 'saml', updated: ['cert'], message: 'SSO provider "acme-saml" updated: cert.' } });
673+
await openEdit(EDIT_SAML, EDIT_SAML_PARAMS, SAML_ROW);
674+
675+
fireEvent.change(await screen.findByLabelText(/^New IdP Signing Certificate/), { target: { value: PEM } });
676+
pressConfirm();
677+
678+
expect(await screen.findByText('SAML settings saved')).toBeInTheDocument();
679+
expect(screen.getByText('SSO provider "acme-saml" updated: cert.')).toBeInTheDocument();
680+
});
681+
682+
it('the identity-change refusal while users are linked keeps the dialog open with the bridge\'s sentence', async () => {
683+
const sentence = 'SSO provider "acme-saml" was not updated: Cannot change the issuer while users are linked. issuer identifies the IdP account each linked user signs in with, so it changes only while no user is linked to the provider.';
684+
answer(409, { success: false, error: { code: 'RESOURCE_CONFLICT', message: sentence, httpStatus: 409 } });
685+
const settled = await openEdit(EDIT_SAML, EDIT_SAML_PARAMS, SAML_ROW);
686+
687+
fireEvent.change(await screen.findByLabelText(/^IdP Entity ID/), { target: { value: 'https://idp.other.test/entity' } });
688+
pressConfirm();
689+
690+
const box = await screen.findByTestId('action-param-refusal');
691+
expect(box).toHaveTextContent('SSO provider "acme-saml" was not updated');
692+
expect(screen.getByRole('dialog')).toBeInTheDocument();
693+
expect(settled.result).toBeUndefined();
694+
});
695+
});
696+
697+
describe('objectstack#32185 — Edit OIDC Settings through the generic action form', () => {
698+
it('draws the client secret as an empty password input and defaults providerId from the row', async () => {
699+
await openEdit(EDIT_OIDC as any, EDIT_OIDC_PARAMS, OIDC_ROW);
700+
701+
const secret = await screen.findByLabelText(/^New Client Secret/);
702+
expect(secret).toHaveAttribute('type', 'password');
703+
expect(secret).toHaveValue('');
704+
expect(screen.getByLabelText(/^Client ID/)).toHaveValue('');
705+
expect(screen.getByLabelText(/^Scopes/)).toHaveValue('');
706+
});
707+
708+
it('a blank secret, client id and scopes post nothing for them', async () => {
709+
answer(200, { success: true, data: { providerId: 'acme-oidc', protocol: 'oidc', updated: ['clientId'], message: 'SSO provider "acme-oidc" updated: clientId.' } });
710+
await openEdit(EDIT_OIDC as any, EDIT_OIDC_PARAMS, OIDC_ROW);
711+
712+
fireEvent.change(await screen.findByLabelText(/^Client ID/), { target: { value: 'new-client' } });
713+
pressConfirm();
714+
715+
await waitFor(() => expect(authFetchSpy).toHaveBeenCalledTimes(1));
716+
const params = sentEditParams('edit_oidc_provider');
717+
expect(params.providerId).toBe('acme-oidc');
718+
expect(params.clientId).toBe('new-client');
719+
expect(params.clientSecret ?? '').toBe('');
720+
expect(params.scopes ?? '').toBe('');
721+
});
722+
723+
it('a typed secret posts once and is not shown again in the result dialog', async () => {
724+
answer(200, { success: true, data: { providerId: 'acme-oidc', protocol: 'oidc', updated: ['clientSecret'], message: 'SSO provider "acme-oidc" updated: clientSecret.' } });
725+
await openEdit(EDIT_OIDC as any, EDIT_OIDC_PARAMS, OIDC_ROW);
726+
727+
fireEvent.change(await screen.findByLabelText(/^New Client Secret/), { target: { value: 's3cret-value' } });
728+
pressConfirm();
729+
730+
await waitFor(() => expect(authFetchSpy).toHaveBeenCalledTimes(1));
731+
expect(sentEditParams('edit_oidc_provider').clientSecret).toBe('s3cret-value');
732+
expect(await screen.findByText('OIDC settings saved')).toBeInTheDocument();
733+
expect(screen.getByText('SSO provider "acme-oidc" updated: clientSecret.')).toBeInTheDocument();
734+
expect(document.body.textContent).not.toContain('s3cret-value');
735+
});
736+
737+
it('the wrong-protocol refusal reaches the admin with the bridge\'s sentence naming the right action', async () => {
738+
const sentence = 'SSO provider "acme-oidc" is an OIDC provider, so cert does not apply to it (that is "Edit SAML Settings"). Use "Edit OIDC Settings".';
739+
answer(400, { success: false, error: { code: 'INVALID_REQUEST', message: sentence, httpStatus: 400, field: 'cert' } });
740+
await openEdit(EDIT_SAML, EDIT_SAML_PARAMS, OIDC_ROW);
741+
742+
fireEvent.change(await screen.findByLabelText(/^New IdP Signing Certificate/), { target: { value: PEM } });
743+
pressConfirm();
744+
745+
const box = await screen.findByTestId('action-param-refusal');
746+
expect(box).toHaveTextContent('is an OIDC provider, so cert does not apply to it');
747+
expect(screen.getByRole('dialog')).toBeInTheDocument();
748+
});
749+
});

0 commit comments

Comments
 (0)