24 lines
1.5 KiB
TypeScript
24 lines
1.5 KiB
TypeScript
import type { Page } from '../../web/node_modules/@playwright/test/index.js';
|
|
import { expect } from '../../web/node_modules/@playwright/test/index.js';
|
|
import { readFileSync, statSync } from 'node:fs';
|
|
|
|
export function loginData(): { username: string; password: string } {
|
|
if (process.env.RMM_E2E_PROFILE !== 'dev/test') throw new Error('Explicit dev/test profile required');
|
|
const file = process.env.RMM_E2E_LOGIN_FILE;
|
|
if (!file) throw new Error('Protected login JSON file required');
|
|
const stat = statSync(file);
|
|
if (!stat.isFile() || (stat.mode & 0o777) !== 0o600 || stat.uid !== process.getuid?.()) throw new Error('Login file must be owned by current user, mode 0600');
|
|
const value: unknown = JSON.parse(readFileSync(file, 'utf8'));
|
|
if (!value || typeof value !== 'object' || !('username' in value) || !('password' in value) || typeof value.username !== 'string' || typeof value.password !== 'string') throw new Error('Invalid login file');
|
|
return { username: value.username, password: value.password };
|
|
}
|
|
export async function login(page: Page) {
|
|
const value = loginData();
|
|
await page.goto('/');
|
|
await page.getByLabel('Benutzername').fill(value.username);
|
|
await page.getByLabel('Passwort', { exact: true }).fill(value.password);
|
|
await page.getByRole('button', { name: 'Anmelden', exact: true }).click();
|
|
await expect(page.getByRole('status')).toContainText('SIMULIERT');
|
|
await expect(page.getByRole('status')).toContainText('kein menschlicher Produktions-Freigabenachweis');
|
|
}
|