Skip to content

Commit 3560179

Browse files
committed
feat(console): ask for the installer's OAuth client on Connect
An oauth2 connector instance declaring clientSource: 'installer' now opens a client form on Connect / Reconnect: client id and a masked, write-only client secret. The begin POST carries { clientId, clientSecret }; a reconnect shows the stored client id and whether a secret is kept, prefills the id and sends the client again. Every other instance connects with no form, as before. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jQhfprmgNtfhzNURJ6
1 parent aca58cd commit 3560179

13 files changed

Lines changed: 490 additions & 16 deletions

File tree

‎ui/packages/app-shell/src/views/setup/ConnectorConnectionsPage.test.tsx‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
* the window and shows the server's words; a URL that is not http(s) is
1818
* never navigated to.
1919
* 4. **disconnect** — only behind a confirmation; Cancel sends nothing.
20+
* 5. **an installer-supplied OAuth client** (`clientSource: 'installer'`,
21+
* ADR-0143 D2.1's 2026-11-02 amendment) — Connect asks for the client
22+
* id and secret before any window opens or anything is sent, and the
23+
* begin carries `{ clientId, clientSecret }`; the secret input is empty on
24+
* every opening and the secret never reaches the page's DOM; a reconnect
25+
* shows the stored client id and whether a secret is kept, prefills the
26+
* id, and still sends the client (today's server refuses a client-less
27+
* begin of such an instance); no other instance shows the form.
2028
*/
2129

2230
import '@testing-library/jest-dom/vitest';
@@ -250,3 +258,135 @@ describe('disconnect', () => {
250258
expect(await within(dialog).findByRole('alert')).toHaveTextContent('nothing to revoke');
251259
});
252260
});
261+
262+
describe('an installer-supplied OAuth client', () => {
263+
const SECRET = 'dummy-installer-secret-NEVER-RENDERED';
264+
const installer = { name: 'docusign', label: 'DocuSign', provider: 'openapi', auth: { type: 'oauth2', grant: 'authorization_code', clientSource: 'installer' } };
265+
const begun = envelope({ connector: 'docusign', organizationId: 'org_1', authorizationUrl: AUTH_URL, expiresAt: new Date(Date.now() + 600_000).toISOString() });
266+
267+
beforeEach(() => {
268+
answer('GET', META, { status: 200, body: { type: 'connector', items: [...declared, installer] } });
269+
answer('GET', door('docusign'), { status: 200, body: envelope(state('docusign')) });
270+
});
271+
272+
const form = () => screen.getByTestId('connector-client-form');
273+
const secretInput = () => within(form()).getByLabelText('Client secret') as HTMLInputElement;
274+
const idInput = () => within(form()).getByLabelText('Client ID') as HTMLInputElement;
275+
276+
it('Connect asks for the client before any window opens or anything is sent, and the begin carries it', async () => {
277+
renderPage();
278+
await screen.findByTestId('connection-row-docusign');
279+
fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Connect' }));
280+
281+
expect(await screen.findByTestId('connector-client-form')).toBeInTheDocument();
282+
expect(openSpy).not.toHaveBeenCalled();
283+
expect(sent('POST', door('docusign'))).toHaveLength(0);
284+
expect(idInput().value).toBe('');
285+
expect(secretInput().value).toBe('');
286+
expect(secretInput()).toHaveAttribute('type', 'password');
287+
expect(secretInput()).toHaveAttribute('autocomplete', 'new-password');
288+
expect(within(form()).getByRole('button', { name: 'Continue to sign-in' })).toBeDisabled();
289+
290+
answer('POST', door('docusign'), { status: 200, body: begun });
291+
fireEvent.change(idInput(), { target: { value: ' installer-client-1 ' } });
292+
fireEvent.change(secretInput(), { target: { value: SECRET } });
293+
fireEvent.click(within(form()).getByRole('button', { name: 'Continue to sign-in' }));
294+
295+
await waitFor(() => expect(fakeWindow!.location.href).toBe(AUTH_URL));
296+
expect(openSpy).toHaveBeenCalledTimes(1);
297+
expect(fakeWindow!.opener).toBeNull();
298+
const posts = sent('POST', door('docusign'));
299+
expect(posts).toHaveLength(1);
300+
expect(JSON.parse(posts[0].body as string)).toEqual({ clientId: 'installer-client-1', clientSecret: SECRET });
301+
await waitFor(() => expect(screen.queryByTestId('connector-client-form')).toBeNull());
302+
expect(document.body.innerHTML).not.toContain(SECRET);
303+
});
304+
305+
it('a public client (no secret) sends only its id', async () => {
306+
answer('POST', door('docusign'), { status: 200, body: begun });
307+
renderPage();
308+
await screen.findByTestId('connection-row-docusign');
309+
fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Connect' }));
310+
fireEvent.change(idInput(), { target: { value: 'public-client' } });
311+
fireEvent.click(within(form()).getByRole('button', { name: 'Continue to sign-in' }));
312+
await waitFor(() => expect(sent('POST', door('docusign'))).toHaveLength(1));
313+
expect(JSON.parse(sent('POST', door('docusign'))[0].body as string)).toEqual({ clientId: 'public-client' });
314+
});
315+
316+
it('a refused begin keeps the form open with the server\'s words, and the secret is gone from it', async () => {
317+
const refusal = "Connector instance 'docusign': `clientId` must be the client id the vendor issued, a non-empty text of at most 512 characters. Nothing was connected.";
318+
answer('POST', door('docusign'), { status: 400, body: errorEnvelope('VALIDATION_ERROR', refusal) });
319+
renderPage();
320+
await screen.findByTestId('connection-row-docusign');
321+
fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Connect' }));
322+
fireEvent.change(idInput(), { target: { value: 'installer-client-1' } });
323+
fireEvent.change(secretInput(), { target: { value: SECRET } });
324+
fireEvent.click(within(form()).getByRole('button', { name: 'Continue to sign-in' }));
325+
326+
expect(await within(form()).findByRole('alert')).toHaveTextContent('Nothing was connected.');
327+
expect(fakeWindow!.close).toHaveBeenCalled();
328+
expect(idInput().value).toBe('installer-client-1');
329+
expect(secretInput().value).toBe('');
330+
expect(document.body.innerHTML).not.toContain(SECRET);
331+
});
332+
333+
it('a reconnect shows the stored client, prefills its id, leaves the secret empty, and sends the client again', async () => {
334+
answer('GET', door('docusign'), {
335+
status: 200,
336+
body: envelope(state('docusign', {
337+
status: 'reconnect_required',
338+
statusReason: 'the refresh token was refused',
339+
connectedAt: '2026-10-30T08:00:00.000Z',
340+
client: { source: 'installer', clientId: 'installer-client-1', hasSecret: true },
341+
})),
342+
});
343+
answer('POST', door('docusign'), { status: 200, body: begun });
344+
renderPage();
345+
expect(await screen.findByTestId('connection-client-docusign')).toHaveTextContent('OAuth client installer-client-1, secret stored');
346+
347+
fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Reconnect' }));
348+
const stored = await screen.findByTestId('connector-client-stored');
349+
expect(stored).toHaveTextContent('Stored client: installer-client-1');
350+
expect(stored).toHaveTextContent('A client secret is stored with it.');
351+
expect(idInput().value).toBe('installer-client-1');
352+
expect(secretInput().value).toBe('');
353+
354+
// Today's server takes a client on every begin of such an instance:
355+
// keeping the id and re-entering the secret sends both, never a client-less begin.
356+
fireEvent.change(secretInput(), { target: { value: SECRET } });
357+
fireEvent.click(within(form()).getByRole('button', { name: 'Continue to sign-in' }));
358+
await waitFor(() => expect(sent('POST', door('docusign'))).toHaveLength(1));
359+
expect(JSON.parse(sent('POST', door('docusign'))[0].body as string)).toEqual({ clientId: 'installer-client-1', clientSecret: SECRET });
360+
expect(document.body.innerHTML).not.toContain(SECRET);
361+
});
362+
363+
it('Cancel sends nothing, and the next opening starts with an empty secret', async () => {
364+
renderPage();
365+
await screen.findByTestId('connection-row-docusign');
366+
fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Connect' }));
367+
fireEvent.change(secretInput(), { target: { value: SECRET } });
368+
fireEvent.click(within(form()).getByRole('button', { name: 'Cancel' }));
369+
await waitFor(() => expect(screen.queryByTestId('connector-client-form')).toBeNull());
370+
fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Connect' }));
371+
expect(secretInput().value).toBe('');
372+
expect(sent('POST', door('docusign'))).toHaveLength(0);
373+
expect(openSpy).not.toHaveBeenCalled();
374+
});
375+
376+
it('no other instance shows the form: a declared or dynamically registered client connects at once, with no body', async () => {
377+
answer('POST', door('notion'), { status: 200, body: envelope({ connector: 'notion', organizationId: 'org_1', authorizationUrl: AUTH_URL, expiresAt: new Date(Date.now() + 600_000).toISOString() }) });
378+
renderPage();
379+
await screen.findByTestId('connection-row-notion');
380+
fireEvent.click(within(row('notion')).getByRole('button', { name: 'Connect' }));
381+
expect(openSpy).toHaveBeenCalledTimes(1);
382+
expect(screen.queryByTestId('connector-client-form')).toBeNull();
383+
await waitFor(() => expect(sent('POST', door('notion'))).toHaveLength(1));
384+
expect(sent('POST', door('notion'))[0].body).toBeUndefined();
385+
386+
fakeWindow!.closed = true;
387+
await waitFor(() => expect(within(row('hubspot')).getByRole('button', { name: 'Reconnect' })).toBeEnabled());
388+
fireEvent.click(within(row('hubspot')).getByRole('button', { name: 'Reconnect' }));
389+
expect(screen.queryByTestId('connector-client-form')).toBeNull();
390+
expect(screen.queryByTestId('connection-client-hubspot')).toBeNull();
391+
});
392+
});

0 commit comments

Comments
 (0)