feat: add magic-link admin login and speaker materials portal
This commit is contained in:
1 parent
3adc0fd58f
commit
8d8d3ae4b8
28 files changed
+1623
-232
No files matched your search
@@ -0,0 +1,223 @@
|
||||
import { test, expect, type Page } from '@playwright/test';
|
||||
|
||||
const adminUrl = process.env.CONVIVO_ADMIN_URL || 'http://localhost:3001';
|
||||
const confirmation = 'If this email belongs to an eligible account, a sign-in link has been sent.';
|
||||
const invalidLink = 'This sign-in link is invalid or expired. Please request a new link.';
|
||||
|
||||
function mockSession(email: string) {
|
||||
const user = {
|
||||
id: '11111111-1111-4111-8111-111111111111',
|
||||
aud: 'authenticated', role: 'authenticated', email,
|
||||
app_metadata: {}, user_metadata: {}, created_at: '2026-01-01T00:00:00Z',
|
||||
};
|
||||
const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url');
|
||||
return { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test-signature`, refresh_token: 'mock-refresh-token', token_type: 'bearer', expires_in: 3600 };
|
||||
}
|
||||
|
||||
async function mockApi(page: Page, email = '[email protected]', isAdmin = false, password = 'personal-password') {
|
||||
const session = mockSession(email);
|
||||
const calls = { users: 0, exchanges: 0, logouts: 0, passwords: 0 };
|
||||
await page.route('**/auth/v1/**', async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (url.pathname.endsWith('/user')) {
|
||||
calls.users++;
|
||||
await route.fulfill({ json: session.user });
|
||||
} else if (url.pathname.endsWith('/token')) {
|
||||
if (url.searchParams.get('grant_type') === 'pkce') calls.exchanges++;
|
||||
if (url.searchParams.get('grant_type') === 'password') calls.passwords++;
|
||||
await route.fulfill({ json: session });
|
||||
} else if (url.pathname.endsWith('/logout')) {
|
||||
calls.logouts++;
|
||||
await route.fulfill({ status: 204 });
|
||||
} else {
|
||||
await route.fulfill({ json: {} });
|
||||
}
|
||||
});
|
||||
await page.route('**/rest/v1/**', async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
await route.fulfill({ json: url.pathname.endsWith('/contacts')
|
||||
? { email, full_name: 'Test Admin', is_admin: isAdmin, password }
|
||||
: [] });
|
||||
});
|
||||
return { session, calls };
|
||||
}
|
||||
|
||||
test.describe('Admin magic links', () => {
|
||||
test('pending send locks the recipient and failed resend clears stale confirmation', async ({ page }) => {
|
||||
await mockApi(page);
|
||||
await page.clock.install();
|
||||
let requestCount = 0;
|
||||
let releaseSend!: () => void;
|
||||
const pendingSend = new Promise<void>((resolve) => { releaseSend = resolve; });
|
||||
await page.route('**/auth/v1/otp**', async (route) => {
|
||||
requestCount++;
|
||||
if (requestCount === 1) {
|
||||
await pendingSend;
|
||||
await route.fulfill({ json: {} });
|
||||
} else {
|
||||
await route.fulfill({ status: 500, json: { msg: 'SMTP unavailable' } });
|
||||
}
|
||||
});
|
||||
await page.goto(adminUrl);
|
||||
await page.getByLabel('Email', { exact: true }).fill('[email protected]');
|
||||
await page.getByRole('button', { name: 'Send magic link', exact: true }).click();
|
||||
await expect(page.getByLabel('Email', { exact: true })).toBeDisabled();
|
||||
await expect(page.getByRole('button', { name: 'Sending...', exact: true })).toBeDisabled();
|
||||
releaseSend();
|
||||
await expect(page.locator('.login-form [role="status"]')).toHaveText(confirmation);
|
||||
await expect(page.getByLabel('Email', { exact: true })).toBeEnabled();
|
||||
await page.clock.runFor(60_000);
|
||||
await page.getByRole('button', { name: 'Resend magic link', exact: true }).click();
|
||||
await expect(page.getByRole('alert')).toHaveText('Unable to send a sign-in link right now. Please try again later.');
|
||||
await expect(page.locator('.login-form [role="status"]')).toHaveCount(0);
|
||||
await expect(page.getByRole('button', { name: 'Send magic link', exact: true })).toBeEnabled();
|
||||
await expect(page.getByText('SMTP unavailable')).toHaveCount(0);
|
||||
expect(requestCount).toBe(2);
|
||||
});
|
||||
|
||||
test('email-only sending, private confirmation, cooldown and resend', async ({ page }) => {
|
||||
await mockApi(page);
|
||||
await page.clock.install();
|
||||
let requestCount = 0;
|
||||
await page.route('**/auth/v1/otp**', async (route) => {
|
||||
requestCount++;
|
||||
expect(route.request().postDataJSON()).toMatchObject({ email: '[email protected]', create_user: false });
|
||||
expect(new URL(route.request().url()).searchParams.get('redirect_to')).toBe(`${adminUrl}/auth/callback`);
|
||||
await route.fulfill({ json: {} });
|
||||
});
|
||||
await page.goto(adminUrl);
|
||||
await expect(page.getByLabel('Password', { exact: true })).toHaveCount(0);
|
||||
await page.getByLabel('Email', { exact: true }).fill('[email protected]');
|
||||
await page.getByRole('button', { name: 'Send magic link', exact: true }).click();
|
||||
await expect(page.locator('.login-form [role="status"]')).toHaveText(confirmation);
|
||||
await expect(page.getByRole('button', { name: 'Resend in 60s' })).toBeDisabled();
|
||||
await page.clock.runFor(60_000);
|
||||
await page.getByRole('button', { name: 'Resend magic link', exact: true }).click();
|
||||
await expect(page.getByRole('button', { name: 'Resend in 60s' })).toBeDisabled();
|
||||
expect(requestCount).toBe(2);
|
||||
});
|
||||
|
||||
for (const status of [400, 422, 429, 500]) {
|
||||
test(`OTP status ${status} does not reveal account existence`, async ({ page }) => {
|
||||
await mockApi(page);
|
||||
await page.route('**/auth/v1/otp**', (route) => route.fulfill({ status, json: { msg: 'User not found', code: 'test_error' } }));
|
||||
await page.goto(adminUrl);
|
||||
await page.getByLabel('Email', { exact: true }).fill('[email protected]');
|
||||
await page.getByRole('button', { name: 'Send magic link', exact: true }).click();
|
||||
if (status < 429) await expect(page.locator('.login-form [role="status"]')).toHaveText(confirmation);
|
||||
else await expect(page.getByRole('alert')).toHaveText('Unable to send a sign-in link right now. Please try again later.');
|
||||
await expect(page.getByText('User not found')).toHaveCount(0);
|
||||
});
|
||||
}
|
||||
|
||||
for (const account of [
|
||||
{ email: '[email protected]', isAdmin: false, admitted: true },
|
||||
{ email: '[email protected]', isAdmin: true, admitted: true },
|
||||
{ email: '[email protected]', isAdmin: false, admitted: false },
|
||||
]) {
|
||||
test(`implicit callback applies admin gate for ${account.email}`, async ({ page }) => {
|
||||
const { session, calls } = await mockApi(page, account.email, account.isAdmin);
|
||||
await page.goto(`${adminUrl}/auth/callback?next=https://example.org#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
|
||||
await expect(page).toHaveURL(`${adminUrl}/`);
|
||||
if (account.admitted) {
|
||||
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toBeVisible();
|
||||
await page.getByRole('button', { name: 'Sign out', exact: true }).click();
|
||||
await expect(page.getByRole('heading', { name: 'APPE Admin' })).toBeVisible();
|
||||
} else {
|
||||
await expect(page.getByRole('alert')).toHaveText('This account is not an admin.');
|
||||
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toHaveCount(0);
|
||||
expect(calls.logouts).toBe(1);
|
||||
expect(await page.evaluate(() => Object.keys(localStorage).filter((key) => key.endsWith('-auth-token')))).toEqual([]);
|
||||
}
|
||||
expect(calls.users).toBe(1);
|
||||
});
|
||||
}
|
||||
|
||||
test('code callback is exchanged once under StrictMode', async ({ page }) => {
|
||||
const { calls } = await mockApi(page);
|
||||
await page.goto(`${adminUrl}/auth/callback?code=mock-code&redirect_to=https://example.org`);
|
||||
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toBeVisible();
|
||||
await expect(page).toHaveURL(`${adminUrl}/`);
|
||||
expect(calls.exchanges).toBe(1);
|
||||
});
|
||||
|
||||
for (const suffix of [
|
||||
'#error=access_denied&error_code=otp_expired&error_description=Sensitive+server+detail',
|
||||
'?error=access_denied&error_code=otp_expired',
|
||||
'#access_token=incomplete',
|
||||
'',
|
||||
]) {
|
||||
test(`invalid callback is scrubbed and recoverable: ${suffix || 'empty'}`, async ({ page }) => {
|
||||
const { calls } = await mockApi(page);
|
||||
await page.goto(`${adminUrl}/auth/callback${suffix}`);
|
||||
await expect(page).toHaveURL(`${adminUrl}/`);
|
||||
await expect(page.getByRole('alert')).toHaveText(invalidLink);
|
||||
await expect(page.getByRole('button', { name: 'Send magic link', exact: true })).toBeVisible();
|
||||
expect(calls.users).toBe(0);
|
||||
expect(calls.exchanges).toBe(0);
|
||||
await expect(page.getByText('Sensitive server detail')).toHaveCount(0);
|
||||
});
|
||||
}
|
||||
|
||||
test('login has no password field or sign-in method selector', async ({ page }) => {
|
||||
const { calls } = await mockApi(page);
|
||||
await page.goto(adminUrl);
|
||||
await expect(page.getByLabel('Email', { exact: true })).toBeVisible();
|
||||
await expect(page.locator('input[type="password"]')).toHaveCount(0);
|
||||
await expect(page.getByRole('group', { name: 'Sign-in method' })).toHaveCount(0);
|
||||
await expect(page.getByRole('button', { name: 'Password', exact: true })).toHaveCount(0);
|
||||
await expect(page.getByRole('button', { name: 'Sign in', exact: true })).toHaveCount(0);
|
||||
await expect(page.getByRole('button', { name: 'Send magic link', exact: true })).toBeVisible();
|
||||
expect(calls.passwords).toBe(0);
|
||||
});
|
||||
|
||||
test('expired callback can recover by requesting a new magic link', async ({ page }) => {
|
||||
const { calls } = await mockApi(page);
|
||||
let requestCount = 0;
|
||||
await page.route('**/auth/v1/otp**', async (route) => {
|
||||
requestCount++;
|
||||
expect(route.request().postDataJSON()).toMatchObject({ email: '[email protected]', create_user: false });
|
||||
await route.fulfill({ json: {} });
|
||||
});
|
||||
await page.goto(`${adminUrl}/auth/callback#error=access_denied&error_code=otp_expired`);
|
||||
await expect(page.getByRole('alert')).toHaveText(invalidLink);
|
||||
await page.getByLabel('Email', { exact: true }).fill('[email protected]');
|
||||
await page.getByRole('button', { name: 'Send magic link', exact: true }).click();
|
||||
await expect(page.getByRole('alert')).toHaveCount(0);
|
||||
await expect(page.locator('.login-form [role="status"]')).toHaveText(confirmation);
|
||||
await expect(page.getByRole('button', { name: 'Resend in 60s' })).toBeDisabled();
|
||||
expect(requestCount).toBe(1);
|
||||
expect(calls.passwords).toBe(0);
|
||||
await expect(page).toHaveURL(`${adminUrl}/`);
|
||||
});
|
||||
|
||||
test('default-password contact has no change-password prompt on callback or session restore', async ({ page }) => {
|
||||
const { session, calls } = await mockApi(page, '[email protected]', false, 'appe-admin-2026');
|
||||
await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
|
||||
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toBeVisible();
|
||||
await expect(page.getByRole('dialog')).toHaveCount(0);
|
||||
await expect(page.getByText('Change your password', { exact: true })).toHaveCount(0);
|
||||
await expect(page.locator('input[type="password"]')).toHaveCount(0);
|
||||
await page.reload();
|
||||
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toBeVisible();
|
||||
await expect(page.getByRole('dialog')).toHaveCount(0);
|
||||
await expect(page.getByText('Change your password', { exact: true })).toHaveCount(0);
|
||||
await expect(page.locator('input[type="password"]')).toHaveCount(0);
|
||||
expect(calls.passwords).toBe(0);
|
||||
});
|
||||
|
||||
test('rejected code exchange clears a previously stored local session', async ({ page }) => {
|
||||
const { session } = await mockApi(page);
|
||||
await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
|
||||
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toBeVisible();
|
||||
await page.route('**/auth/v1/token**', (route) => route.fulfill({
|
||||
status: 400, json: { error: 'invalid_grant', error_description: 'Sensitive exchange detail' },
|
||||
}));
|
||||
await page.goto(`${adminUrl}/auth/callback?code=expired-code`);
|
||||
await expect(page.getByRole('alert')).toHaveText(invalidLink);
|
||||
await expect(page).toHaveURL(`${adminUrl}/`);
|
||||
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toHaveCount(0);
|
||||
expect(await page.evaluate(() => Object.keys(localStorage).filter((key) => key.endsWith('-auth-token')))).toEqual([]);
|
||||
await expect(page.getByText('Sensitive exchange detail')).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,235 @@
|
||||
import { test, expect, type Page } from '@playwright/test';
|
||||
|
||||
const appUrl = process.env.CONVIVO_BASE_URL || 'http://localhost:3000';
|
||||
const portalUrl = `${appUrl}/speaker/secret`;
|
||||
const invalidLink = 'This sign-in link has expired or is invalid. Request a new link.';
|
||||
|
||||
function mockSession(email = '[email protected]') {
|
||||
const user = {
|
||||
id: '11111111-1111-4111-8111-111111111111',
|
||||
aud: 'authenticated', role: 'authenticated', email,
|
||||
app_metadata: {}, user_metadata: {}, created_at: '2026-01-01T00:00:00Z',
|
||||
};
|
||||
const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url');
|
||||
return { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test-signature`, refresh_token: 'mock-refresh-token', token_type: 'bearer', expires_in: 3600 };
|
||||
}
|
||||
|
||||
async function mockApi(page: Page, talks: Record<string, unknown>[] = [], email = '[email protected]') {
|
||||
const session = mockSession(email);
|
||||
const calls = { users: 0, exchanges: 0, portal: 0, unexpected: [] as string[] };
|
||||
await page.route('**/auth/v1/**', async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (url.pathname.endsWith('/user')) {
|
||||
calls.users++;
|
||||
await route.fulfill({ json: session.user });
|
||||
} else if (url.pathname.endsWith('/token')) {
|
||||
calls.exchanges++;
|
||||
await route.fulfill({ json: session });
|
||||
} else if (url.pathname.endsWith('/logout')) {
|
||||
await route.fulfill({ status: 204 });
|
||||
} else await route.fulfill({ json: {} });
|
||||
});
|
||||
await page.route('**/rest/v1/**', async (route) => {
|
||||
if (new URL(route.request().url()).pathname.endsWith('/rpc/get_my_speaker_sessions')) calls.portal++;
|
||||
else calls.unexpected.push(route.request().url());
|
||||
await route.fulfill({ json: talks });
|
||||
});
|
||||
return { session, calls };
|
||||
}
|
||||
|
||||
test.describe('Speaker portal', () => {
|
||||
const talkId = '22222222-2222-4222-8222-222222222222';
|
||||
const talk = {
|
||||
session_id: talkId, title: 'Past talk', description: null, room: 'Room A', material_path: null as string | null,
|
||||
event_id: '33333333-3333-4333-8333-333333333333', event_name: 'Past conference',
|
||||
event_start_date: '2020-01-01', event_end_date: '2020-01-01', is_active: false,
|
||||
slot_date: '2020-01-01', start_time: '09:00:00', end_time: '10:00:00',
|
||||
};
|
||||
|
||||
for (const { width, title } of [
|
||||
{ width: 1280, title: 'Past talk' }, { width: 390, title: 'Past talk' },
|
||||
{ width: 1280, title: 'Future talk' }, { width: 390, title: 'Future talk' },
|
||||
]) {
|
||||
test(`inactive ${title} materials can upload, replace and delete at ${width}px`, async ({ page }) => {
|
||||
await page.setViewportSize({ width, height: 844 });
|
||||
const talks = [{ ...talk }, { ...talk, session_id: '44444444-4444-4444-8444-444444444444', title: 'Future talk', event_name: 'Future conference', slot_date: '2099-01-01' }];
|
||||
const materialTalk = talks.find((entry) => entry.title === title)!;
|
||||
const materialId = materialTalk.session_id;
|
||||
const { session, calls } = await mockApi(page, talks);
|
||||
let materialPath: string | null = null;
|
||||
const uploaded: string[] = [];
|
||||
const removed: string[] = [];
|
||||
await page.route('**/rest/v1/sessions?**', (route) => route.fulfill({ json: { material_path: materialPath } }));
|
||||
await page.route('**/rest/v1/rpc/set_session_material', async (route) => {
|
||||
const body = route.request().postDataJSON();
|
||||
expect(body.p_session_id).toBe(materialId);
|
||||
materialPath = body.p_material_path;
|
||||
materialTalk.material_path = materialPath;
|
||||
await route.fulfill({ json: { material_path: materialPath } });
|
||||
});
|
||||
await page.route('**/storage/v1/object/materials/**', async (route) => {
|
||||
const path = decodeURIComponent(new URL(route.request().url()).pathname.split('/object/materials/')[1]);
|
||||
expect(path).toMatch(new RegExp(`^sessions/${materialId}/[a-f0-9-]+-slides\\.txt$`));
|
||||
uploaded.push(path);
|
||||
await route.fulfill({ json: { Key: `materials/${path}` } });
|
||||
});
|
||||
await page.route('**/storage/v1/object/materials', async (route) => {
|
||||
removed.push(...route.request().postDataJSON().prefixes);
|
||||
await route.fulfill({ json: [] });
|
||||
});
|
||||
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);
|
||||
const article = page.getByTestId(`speaker-talk-${materialId}`);
|
||||
await expect(page.getByText('Future talk', { exact: true })).toBeVisible();
|
||||
await expect(page.getByTestId('checkin-required-gate')).toHaveCount(0);
|
||||
await article.getByLabel(`Upload material for ${title}`).setInputFiles({ name: 'slides.txt', mimeType: 'text/plain', buffer: Buffer.from('First slides') });
|
||||
await expect(article.getByRole('link', { name: 'Download material' })).toBeVisible();
|
||||
const firstPath = materialPath;
|
||||
await article.getByLabel(`Replace material for ${title}`).setInputFiles({ name: 'slides.txt', mimeType: 'text/plain', buffer: Buffer.from('Replacement slides') });
|
||||
await expect.poll(() => uploaded.length).toBe(2);
|
||||
await expect(article.getByRole('button', { name: 'Remove material' })).toBeEnabled();
|
||||
expect(materialPath).not.toBe(firstPath);
|
||||
expect(removed).toEqual([firstPath]);
|
||||
await expect(article.getByRole('link', { name: 'Download material' })).toHaveAttribute('href', new RegExp(`${materialPath}$`));
|
||||
await page.screenshot({ path: `/tmp/convivo-speaker-${width}-${title.split(' ')[0]}.png`, fullPage: true });
|
||||
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
|
||||
page.once('dialog', (dialog) => dialog.accept());
|
||||
await article.getByRole('button', { name: 'Remove material' }).click();
|
||||
await expect(article.getByText('No material uploaded')).toBeVisible();
|
||||
expect(materialPath).toBeNull();
|
||||
expect(removed).toEqual(uploaded);
|
||||
expect(calls.unexpected).toEqual([]);
|
||||
});
|
||||
}
|
||||
|
||||
for (const email of ['[email protected]', '[email protected]']) {
|
||||
test(`assigned staff identity ${email} can manage talk material without a registration role gate`, async ({ page }) => {
|
||||
const materialTalk = { ...talk };
|
||||
const { session, calls } = await mockApi(page, [materialTalk], email);
|
||||
let materialPath: string | null = null;
|
||||
await page.route('**/rest/v1/sessions?**', (route) => route.fulfill({ json: { material_path: materialPath } }));
|
||||
await page.route('**/storage/v1/object/materials/**', (route) => route.fulfill({ json: { Key: 'uploaded' } }));
|
||||
await page.route('**/rest/v1/rpc/set_session_material', async (route) => {
|
||||
expect(route.request().postDataJSON().p_session_id).toBe(talkId);
|
||||
materialPath = route.request().postDataJSON().p_material_path;
|
||||
materialTalk.material_path = materialPath;
|
||||
await route.fulfill({ json: { material_path: materialPath } });
|
||||
});
|
||||
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);
|
||||
await expect(page.getByText(email, { exact: true })).toBeVisible();
|
||||
await page.getByLabel('Upload material for Past talk').setInputFiles({
|
||||
name: 'slides.txt', mimeType: 'text/plain', buffer: Buffer.from('Staff talk slides'),
|
||||
});
|
||||
await expect(page.getByRole('link', { name: 'Download material' })).toBeVisible();
|
||||
await expect(page.getByTestId('checkin-required-gate')).toHaveCount(0);
|
||||
expect(calls.unexpected).toEqual([]);
|
||||
});
|
||||
}
|
||||
|
||||
test('failed material attachment cleans up upload and re-enables controls', async ({ page }) => {
|
||||
const { session } = await mockApi(page, [{ ...talk }]);
|
||||
const removed: string[] = [];
|
||||
await page.route('**/rest/v1/sessions?**', (route) => route.fulfill({ json: { material_path: null } }));
|
||||
await page.route('**/storage/v1/object/materials/**', (route) => route.fulfill({ json: { Key: 'uploaded' } }));
|
||||
await page.route('**/rest/v1/rpc/set_session_material', (route) => route.fulfill({ status: 403, json: { message: 'Assignment removed', code: '42501' } }));
|
||||
await page.route('**/storage/v1/object/materials', async (route) => {
|
||||
removed.push(...route.request().postDataJSON().prefixes);
|
||||
await route.fulfill({ json: [] });
|
||||
});
|
||||
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);
|
||||
const input = page.getByLabel('Upload material for Past talk');
|
||||
await input.setInputFiles({ name: 'slides.txt', mimeType: 'text/plain', buffer: Buffer.from('Slides') });
|
||||
await expect(page.getByRole('alert')).toHaveText('Assignment removed');
|
||||
await expect(input).toBeEnabled();
|
||||
expect(removed).toHaveLength(1);
|
||||
await expect(page.getByRole('link', { name: 'Download material' })).toHaveCount(0);
|
||||
await input.setInputFiles({ name: 'bad.exe', mimeType: 'application/octet-stream', buffer: Buffer.from('Invalid') });
|
||||
await expect(page.getByRole('alert')).toHaveText(/Choose a non-empty PDF/);
|
||||
expect(removed).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('portal authentication does not bypass the normal app check-in gate', async ({ page }) => {
|
||||
const { session } = await mockApi(page);
|
||||
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);
|
||||
await expect(page.getByRole('status')).toHaveText(/No assigned talks/);
|
||||
await page.route('**/rest/v1/contacts?**', (route) => route.fulfill({ json: { email: session.user.email, full_name: 'Speaker', is_admin: false } }));
|
||||
await page.route('**/rest/v1/registrations?**', (route) => route.fulfill({ json: { contact_email: session.user.email, type: 'speaker', checked_in: false, points: 37 } }));
|
||||
await page.goto(appUrl);
|
||||
await expect(page.getByTestId('checkin-required-gate')).toBeVisible();
|
||||
await expect(page.getByTestId('speaker-portal')).toHaveCount(0);
|
||||
});
|
||||
|
||||
for (const callback of ['implicit', 'pkce']) {
|
||||
test(`rejected ${callback} callback leaves no session and allows a new link`, async ({ page }) => {
|
||||
const { session } = await mockApi(page);
|
||||
const endpoint = callback === 'implicit' ? '**/auth/v1/user' : '**/auth/v1/token?**';
|
||||
await page.route(endpoint, (route) => route.fulfill({ status: 400, json: { msg: 'Sensitive server detail', code: 'test_error' } }));
|
||||
const suffix = callback === 'implicit'
|
||||
? `#access_token=${session.access_token}&refresh_token=${session.refresh_token}` : '?code=invalid-code';
|
||||
await page.goto(`${portalUrl}${suffix}`);
|
||||
await expect(page).toHaveURL(portalUrl);
|
||||
await expect(page.getByRole('alert')).toHaveText(callback === 'implicit' ? invalidLink
|
||||
: 'This sign-in link could not be opened on this device. Request a new link.');
|
||||
await expect(page.getByLabel('Email', { exact: true })).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toHaveCount(0);
|
||||
expect(await page.evaluate(() => Object.keys(localStorage).filter((key) => key.endsWith('-auth-token')))).toEqual([]);
|
||||
});
|
||||
}
|
||||
|
||||
for (const path of ['/speaker/secret', '/speaker']) {
|
||||
test(`requests links for existing users only at ${path}`, async ({ page }) => {
|
||||
await mockApi(page);
|
||||
let requests = 0;
|
||||
await page.route('**/auth/v1/otp**', async (route) => {
|
||||
requests++;
|
||||
expect(route.request().postDataJSON()).toMatchObject({ email: '[email protected]', create_user: false });
|
||||
expect(new URL(route.request().url()).searchParams.get('redirect_to')).toBe(portalUrl);
|
||||
await route.fulfill({ json: {} });
|
||||
});
|
||||
await page.goto(`${appUrl}${path}`);
|
||||
await page.getByLabel('Email', { exact: true }).fill('[email protected]');
|
||||
await page.getByRole('button', { name: 'Send sign-in link', exact: true }).click();
|
||||
await expect(page.getByRole('status')).toHaveText('Sign-in link requested. Check your email.');
|
||||
expect(requests).toBe(1);
|
||||
await expect(page.getByTestId('checkin-required-gate')).toHaveCount(0);
|
||||
});
|
||||
}
|
||||
|
||||
for (const suffix of [
|
||||
'#error=access_denied&error_description=Sensitive+server+detail',
|
||||
'?error=access_denied&error_code=otp_expired',
|
||||
'#access_token=incomplete',
|
||||
]) {
|
||||
test(`callback error is scrubbed and recoverable: ${suffix}`, async ({ page }) => {
|
||||
const { calls } = await mockApi(page);
|
||||
await page.goto(`${portalUrl}${suffix}`);
|
||||
await expect(page).toHaveURL(portalUrl);
|
||||
await expect(page.getByRole('alert')).toHaveText(suffix.includes('incomplete')
|
||||
? 'Incomplete sign-in link. Request a new link.' : invalidLink);
|
||||
await expect(page.getByRole('button', { name: 'Send sign-in link', exact: true })).toBeVisible();
|
||||
await expect(page.getByText('Sensitive server detail')).toHaveCount(0);
|
||||
expect(calls.users).toBe(0);
|
||||
expect(calls.exchanges).toBe(0);
|
||||
});
|
||||
}
|
||||
|
||||
for (const callback of ['implicit', 'pkce']) {
|
||||
test(`${callback} callback is consumed once under StrictMode and empty access stays isolated`, async ({ page }) => {
|
||||
const { session, calls } = await mockApi(page);
|
||||
const suffix = callback === 'implicit'
|
||||
? `#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`
|
||||
: '?code=mock-code&next=https://example.org';
|
||||
await page.goto(`${portalUrl}${suffix}`);
|
||||
await expect(page).toHaveURL(portalUrl);
|
||||
await expect(page.getByRole('status')).toHaveText(/No assigned talks/);
|
||||
expect(calls.users).toBe(callback === 'implicit' ? 1 : 0);
|
||||
expect(calls.exchanges).toBe(callback === 'pkce' ? 1 : 0);
|
||||
expect(calls.portal).toBeGreaterThan(0);
|
||||
expect(calls.unexpected).toEqual([]);
|
||||
await expect(page.locator('input[type="file"]')).toHaveCount(0);
|
||||
await expect(page.getByTestId('checkin-required-gate')).toHaveCount(0);
|
||||
await page.getByRole('button', { name: 'Sign out', exact: true }).click();
|
||||
await expect(page.getByLabel('Email', { exact: true })).toBeVisible();
|
||||
expect(await page.evaluate(() => Object.keys(localStorage).filter((key) => key.endsWith('-auth-token')))).toEqual([]);
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user