mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 22:43:32 +00:00
feat: Create temporary user helper function
- Add a helper function that creates and log into a temporary user. So it doesn't affect other users and tests and the test can more easily be retried with a 'fresh' state instead of a broken state. - Adjust the Webauthn test to make use of this. - Relevant: #5291, #5394
This commit is contained in:
parent
b76d7a2b2d
commit
0b92d6e0ba
|
@ -80,3 +80,24 @@ export async function save_visual(page) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a temporary user and login to that user and store session info.
|
||||||
|
// This should ideally run on a per test basis.
|
||||||
|
export async function create_temp_user(browser, workerInfo, request) {
|
||||||
|
const username = globalThis.crypto.randomUUID();
|
||||||
|
const newUser = await request.post(`/api/v1/admin/users`, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Basic ${btoa(`user1:${LOGIN_PASSWORD}`)}`,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
username,
|
||||||
|
email: `${username}@host.invalid`,
|
||||||
|
password: LOGIN_PASSWORD,
|
||||||
|
must_change_password: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(newUser.ok()).toBeTruthy();
|
||||||
|
|
||||||
|
return {context: await login_user(browser, workerInfo, username), username};
|
||||||
|
}
|
||||||
|
|
|
@ -9,15 +9,11 @@
|
||||||
// @watch end
|
// @watch end
|
||||||
|
|
||||||
import {expect} from '@playwright/test';
|
import {expect} from '@playwright/test';
|
||||||
import {test, login_user, load_logged_in_context} from './utils_e2e.js';
|
import {test, create_temp_user} from './utils_e2e.js';
|
||||||
|
|
||||||
test.beforeAll(async ({browser}, workerInfo) => {
|
test('WebAuthn register & login flow', async ({browser, request}, workerInfo) => {
|
||||||
await login_user(browser, workerInfo, 'user40');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('WebAuthn register & login flow', async ({browser}, workerInfo) => {
|
|
||||||
test.skip(workerInfo.project.name !== 'chromium', 'Uses Chrome protocol');
|
test.skip(workerInfo.project.name !== 'chromium', 'Uses Chrome protocol');
|
||||||
const context = await load_logged_in_context(browser, workerInfo, 'user40');
|
const {context, username} = await create_temp_user(browser, workerInfo, request);
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
||||||
// Register a security key.
|
// Register a security key.
|
||||||
|
@ -51,7 +47,7 @@ test('WebAuthn register & login flow', async ({browser}, workerInfo) => {
|
||||||
response = await page.goto('/user/login');
|
response = await page.goto('/user/login');
|
||||||
await expect(response?.status()).toBe(200);
|
await expect(response?.status()).toBe(200);
|
||||||
|
|
||||||
await page.getByLabel('Username or email address').fill('user40');
|
await page.getByLabel('Username or email address').fill(username);
|
||||||
await page.getByLabel('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByRole('button', {name: 'Sign in'}).click();
|
await page.getByRole('button', {name: 'Sign in'}).click();
|
||||||
await page.waitForURL(`${workerInfo.project.use.baseURL}/user/webauthn`);
|
await page.waitForURL(`${workerInfo.project.use.baseURL}/user/webauthn`);
|
||||||
|
|
Loading…
Reference in a new issue