Merge pull request 'feat: Create temporary user helper function' (#5617) from gusted/forgejo-temp-user-e2e into forgejo
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / security-check (push) Blocked by required conditions
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (map[image:docker.io/bitnami/redis:7.2 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:docker.io/bitnami/valkey:7.2 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:ghcr.io/microsoft/garnet-alpine:1.0.14 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:registry.redict.io/redict:7.3.0-scratch port:6379]) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5617
Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
Otto 2024-10-19 22:05:31 +00:00
commit dfe9bdd15f
2 changed files with 25 additions and 8 deletions

View file

@ -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};
}

View file

@ -9,15 +9,11 @@
// @watch end
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) => {
await login_user(browser, workerInfo, 'user40');
});
test('WebAuthn register & login flow', async ({browser}, workerInfo) => {
test('WebAuthn register & login flow', async ({browser, request}, workerInfo) => {
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();
// Register a security key.
@ -51,7 +47,7 @@ test('WebAuthn register & login flow', async ({browser}, workerInfo) => {
response = await page.goto('/user/login');
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.getByRole('button', {name: 'Sign in'}).click();
await page.waitForURL(`${workerInfo.project.use.baseURL}/user/webauthn`);