|
| 1 | +import { test, expect } from '../base' |
| 2 | +import { gotoHydrated } from '../helpers' |
| 3 | + |
| 4 | +// udata lands the agent back on /verify after the ProConnect round-trip: the destination |
| 5 | +// was remembered when the page was first opened, before leaving for ProConnect. |
| 6 | +test('a successful ProConnect reauthentication goes on to the remembered destination', async ({ page }) => { |
| 7 | + await gotoHydrated(page, '/verify?next=/admin/me/profile') |
| 8 | + |
| 9 | + await page.goto('/verify?flash=proconnect_reauth_success') |
| 10 | + |
| 11 | + await expect(page).toHaveURL(/\/admin\/me\/profile/) |
| 12 | + await expect(page.getByText('Compte confirmé.')).toBeVisible() |
| 13 | +}) |
| 14 | + |
| 15 | +test('going back after a successful ProConnect reauthentication does not bounce forward', async ({ page }) => { |
| 16 | + await gotoHydrated(page, '/verify?next=/admin/me/profile') |
| 17 | + await page.goto('/verify?flash=proconnect_reauth_success') |
| 18 | + await expect(page).toHaveURL(/\/admin\/me\/profile/) |
| 19 | + |
| 20 | + await page.goBack() |
| 21 | + |
| 22 | + await expect(page).toHaveURL(/\/verify\?next=/) |
| 23 | +}) |
| 24 | + |
| 25 | +test.describe('when the two-factor setup requires a fresh session', () => { |
| 26 | + // The 401 below is the point of the test: the browser logs it. |
| 27 | + test.use({ allowedConsoleMessages: ['the server responded with a status of 401'] }) |
| 28 | + |
| 29 | + test('the reauthentication goes back to the setup', async ({ page }) => { |
| 30 | + // udata asks for a fresh session until the identity is confirmed. |
| 31 | + await page.route('**/tf-setup?*', route => route.fulfill({ status: 401, json: { response: { reauth_required: true } } })) |
| 32 | + await gotoHydrated(page, '/admin/me/profile') |
| 33 | + await page.getByRole('button', { name: 'Configurer l\'authentification deux facteurs' }).click() |
| 34 | + await expect(page.getByRole('heading', { level: 1, name: 'Confirmer votre identité' })).toBeVisible() |
| 35 | + |
| 36 | + await page.unroute('**/tf-setup?*') |
| 37 | + await page.goto('/verify?flash=proconnect_reauth_success') |
| 38 | + |
| 39 | + await expect(page.getByRole('dialog', { name: 'Authentification deux facteurs' })).toBeVisible() |
| 40 | + await expect(page.getByTestId('totp-key')).not.toBeEmpty() |
| 41 | + }) |
| 42 | +}) |
| 43 | + |
| 44 | +test('the ProConnect button asks udata for a reauthentication, not a login', async ({ page }) => { |
| 45 | + let requested: URL | undefined |
| 46 | + // Stop at udata: the round-trip itself goes through ProConnect. |
| 47 | + await page.route('**/api/1/proconnect/**', (route) => { |
| 48 | + requested = new URL(route.request().url()) |
| 49 | + return route.abort() |
| 50 | + }) |
| 51 | + await page.goto('/verify') |
| 52 | + |
| 53 | + await page.getByRole('button', { name: 'S’identifier avec ProConnect' }).click() |
| 54 | + |
| 55 | + await expect.poll(() => requested?.pathname).toBe('/api/1/proconnect/reauth/') |
| 56 | +}) |
| 57 | + |
| 58 | +test('a failed ProConnect reauthentication stays on the page and says so', async ({ page }) => { |
| 59 | + await page.goto('/verify?next=/admin/me/profile') |
| 60 | + await expect(page.getByRole('heading', { level: 1, name: 'Confirmer votre identité' })).toBeVisible() |
| 61 | + |
| 62 | + await page.goto('/verify?flash=proconnect_reauth_failed') |
| 63 | + |
| 64 | + await expect(page.getByText('La confirmation de votre identité avec ProConnect a échoué. Veuillez réessayer.')).toBeVisible() |
| 65 | + await expect(page).toHaveURL(/\/verify/) |
| 66 | +}) |
0 commit comments