|
21 | 21 | * ADR-0143 D2.1's 2026-11-02 amendment) — Connect asks for the client |
22 | 22 | * id and secret before any window opens or anything is sent, and the |
23 | 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. |
| 24 | + * every opening and the secret never reaches the page's DOM; the form |
| 25 | + * shows the redirect URI the status read answered, with a copy button, |
| 26 | + * and says there is none when the read answers none (nothing guessed); |
| 27 | + * a reconnect shows the stored client and keeps it by default with a |
| 28 | + * begin that has no body, and replacing it sends the new client; a |
| 29 | + * disconnect re-reads the status, so the next Connect still shows the |
| 30 | + * URI; no other instance shows the form. |
28 | 31 | */ |
29 | 32 |
|
30 | 33 | import '@testing-library/jest-dom/vitest'; |
@@ -235,6 +238,8 @@ describe('disconnect', () => { |
235 | 238 | answer('DELETE', door('hubspot'), { status: 200, body: envelope(state('hubspot')) }); |
236 | 239 | renderPage(); |
237 | 240 | await screen.findByTestId('connection-row-hubspot'); |
| 241 | + // The status read after the disconnect answers what the server now holds. |
| 242 | + answer('GET', door('hubspot'), { status: 200, body: envelope(state('hubspot')) }); |
238 | 243 |
|
239 | 244 | fireEvent.click(within(row('hubspot')).getByRole('button', { name: 'Disconnect' })); |
240 | 245 | fireEvent.click(await screen.findByRole('button', { name: 'Cancel' })); |
@@ -263,10 +268,19 @@ describe('an installer-supplied OAuth client', () => { |
263 | 268 | const SECRET = 'dummy-installer-secret-NEVER-RENDERED'; |
264 | 269 | const installer = { name: 'docusign', label: 'DocuSign', provider: 'openapi', auth: { type: 'oauth2', grant: 'authorization_code', clientSource: 'installer' } }; |
265 | 270 | const begun = envelope({ connector: 'docusign', organizationId: 'org_1', authorizationUrl: AUTH_URL, expiresAt: new Date(Date.now() + 600_000).toISOString() }); |
| 271 | + /** The server's derivation, deliberately on another origin than the page: the form shows it as answered. */ |
| 272 | + const REDIRECT = 'https://public.acme.example/api/v1/automation/connectors/oauth/callback'; |
| 273 | + const stored = { |
| 274 | + status: 'reconnect_required' as const, |
| 275 | + statusReason: 'the refresh token was refused', |
| 276 | + connectedAt: '2026-10-30T08:00:00.000Z', |
| 277 | + client: { source: 'installer' as const, clientId: 'installer-client-1', hasSecret: true }, |
| 278 | + redirectUri: REDIRECT, |
| 279 | + }; |
266 | 280 |
|
267 | 281 | beforeEach(() => { |
268 | 282 | answer('GET', META, { status: 200, body: { type: 'connector', items: [...declared, installer] } }); |
269 | | - answer('GET', door('docusign'), { status: 200, body: envelope(state('docusign')) }); |
| 283 | + answer('GET', door('docusign'), { status: 200, body: envelope(state('docusign', { redirectUri: REDIRECT })) }); |
270 | 284 | }); |
271 | 285 |
|
272 | 286 | const form = () => screen.getByTestId('connector-client-form'); |
@@ -330,36 +344,91 @@ describe('an installer-supplied OAuth client', () => { |
330 | 344 | expect(document.body.innerHTML).not.toContain(SECRET); |
331 | 345 | }); |
332 | 346 |
|
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 | | - }); |
| 347 | + it('a reconnect keeps the stored client by default: no client fields, and the begin sends no body', async () => { |
| 348 | + answer('GET', door('docusign'), { status: 200, body: envelope(state('docusign', stored)) }); |
343 | 349 | answer('POST', door('docusign'), { status: 200, body: begun }); |
344 | 350 | renderPage(); |
345 | 351 | expect(await screen.findByTestId('connection-client-docusign')).toHaveTextContent('OAuth client installer-client-1, secret stored'); |
346 | 352 |
|
347 | 353 | 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.'); |
| 354 | + const kept = await screen.findByTestId('connector-client-stored'); |
| 355 | + expect(kept).toHaveTextContent('Stored client: installer-client-1'); |
| 356 | + expect(kept).toHaveTextContent('A client secret is stored with it.'); |
| 357 | + expect(within(form()).queryByLabelText('Client ID')).toBeNull(); |
| 358 | + expect(within(form()).queryByLabelText('Client secret')).toBeNull(); |
| 359 | + expect(screen.getByTestId('connector-client-redirect-uri')).toHaveTextContent(REDIRECT); |
| 360 | + |
| 361 | + fireEvent.click(within(form()).getByRole('button', { name: 'Continue to sign-in' })); |
| 362 | + await waitFor(() => expect(fakeWindow!.location.href).toBe(AUTH_URL)); |
| 363 | + const posts = sent('POST', door('docusign')); |
| 364 | + expect(posts).toHaveLength(1); |
| 365 | + expect(posts[0].body).toBeUndefined(); |
| 366 | + }); |
| 367 | + |
| 368 | + it('replacing the stored client shows the fields (id prefilled, secret empty) and sends the new client', async () => { |
| 369 | + answer('GET', door('docusign'), { status: 200, body: envelope(state('docusign', stored)) }); |
| 370 | + answer('POST', door('docusign'), { status: 200, body: begun }); |
| 371 | + renderPage(); |
| 372 | + await screen.findByTestId('connection-client-docusign'); |
| 373 | + fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Reconnect' })); |
| 374 | + fireEvent.click(await within(form()).findByRole('button', { name: 'Replace the stored client' })); |
| 375 | + |
351 | 376 | expect(idInput().value).toBe('installer-client-1'); |
352 | 377 | 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. |
| 378 | + fireEvent.change(idInput(), { target: { value: 'installer-client-2' } }); |
356 | 379 | fireEvent.change(secretInput(), { target: { value: SECRET } }); |
357 | 380 | fireEvent.click(within(form()).getByRole('button', { name: 'Continue to sign-in' })); |
358 | 381 | 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 }); |
| 382 | + expect(JSON.parse(sent('POST', door('docusign'))[0].body as string)).toEqual({ clientId: 'installer-client-2', clientSecret: SECRET }); |
360 | 383 | expect(document.body.innerHTML).not.toContain(SECRET); |
361 | 384 | }); |
362 | 385 |
|
| 386 | + it('shows the redirect URI exactly as the status read answered it, and Copy copies that value', async () => { |
| 387 | + const writeText = vi.fn(async () => {}); |
| 388 | + vi.stubGlobal('navigator', { ...navigator, clipboard: { writeText } }); |
| 389 | + renderPage(); |
| 390 | + await screen.findByTestId('connection-row-docusign'); |
| 391 | + fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Connect' })); |
| 392 | + expect(await screen.findByTestId('connector-client-redirect-uri')).toHaveTextContent(REDIRECT); |
| 393 | + expect(screen.queryByTestId('connector-client-redirect-missing')).toBeNull(); |
| 394 | + fireEvent.click(within(form()).getByRole('button', { name: 'Copy' })); |
| 395 | + await waitFor(() => expect(writeText).toHaveBeenCalledWith(REDIRECT)); |
| 396 | + expect(await within(form()).findByRole('button', { name: 'Copied' })).toBeInTheDocument(); |
| 397 | + }); |
| 398 | + |
| 399 | + it('a status read with no redirect URI says the deployment has none, and nothing is guessed', async () => { |
| 400 | + answer('GET', door('docusign'), { status: 200, body: envelope(state('docusign')) }); |
| 401 | + renderPage(); |
| 402 | + await screen.findByTestId('connection-row-docusign'); |
| 403 | + fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Connect' })); |
| 404 | + expect(await screen.findByTestId('connector-client-redirect-missing')).toHaveTextContent('has no redirect URI'); |
| 405 | + expect(screen.queryByTestId('connector-client-redirect-uri')).toBeNull(); |
| 406 | + expect(within(form()).queryByRole('button', { name: 'Copy' })).toBeNull(); |
| 407 | + expect(form().textContent).not.toContain('/oauth/callback'); |
| 408 | + expect(form().textContent).not.toContain(window.location.origin); |
| 409 | + }); |
| 410 | + |
| 411 | + it('a disconnect re-reads the status, so the next Connect still shows the redirect URI', async () => { |
| 412 | + answer('GET', door('docusign'), { status: 200, body: envelope(state('docusign', stored)) }); |
| 413 | + // The revoke answer carries the status alone, never the redirect URI. |
| 414 | + answer('DELETE', door('docusign'), { status: 200, body: envelope(state('docusign')) }); |
| 415 | + renderPage(); |
| 416 | + await screen.findByTestId('connection-client-docusign'); |
| 417 | + answer('GET', door('docusign'), { status: 200, body: envelope(state('docusign', { redirectUri: REDIRECT })) }); |
| 418 | + const readsBefore = sent('GET', door('docusign')).length; |
| 419 | + |
| 420 | + fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Disconnect' })); |
| 421 | + const dialog = await screen.findByRole('dialog'); |
| 422 | + fireEvent.click(within(dialog).getByRole('button', { name: 'Disconnect' })); |
| 423 | + await waitFor(() => expect(within(row('docusign')).getByText('Not connected')).toBeInTheDocument()); |
| 424 | + expect(sent('GET', door('docusign')).length).toBe(readsBefore + 1); |
| 425 | + |
| 426 | + fireEvent.click(within(row('docusign')).getByRole('button', { name: 'Connect' })); |
| 427 | + expect(await screen.findByTestId('connector-client-redirect-uri')).toHaveTextContent(REDIRECT); |
| 428 | + expect(screen.queryByTestId('connector-client-stored')).toBeNull(); |
| 429 | + expect(idInput().value).toBe(''); |
| 430 | + }); |
| 431 | + |
363 | 432 | it('Cancel sends nothing, and the next opening starts with an empty secret', async () => { |
364 | 433 | renderPage(); |
365 | 434 | await screen.findByTestId('connection-row-docusign'); |
|
0 commit comments