From 22a5b652916adfd709c1dd1fc1773f96cd408f8f Mon Sep 17 00:00:00 2001 From: Pablo Zmdl Date: Thu, 25 Jun 2026 17:11:03 +0200 Subject: [PATCH] Refactor playwright login helper It now works for all test specs and does not require a password from the environment. Signed-off-by: Pablo Zmdl --- php/tests/tests/desec-existing-slug.spec.js | 2 +- php/tests/tests/desec-existing.spec.js | 2 +- php/tests/tests/desec-helpers.js | 22 ------------------- php/tests/tests/desec-register.spec.js | 2 +- php/tests/tests/helpers.js | 24 +++++++++++++++++++++ php/tests/tests/initial-setup.spec.js | 14 ++---------- php/tests/tests/restore-instance.spec.js | 14 ++---------- 7 files changed, 31 insertions(+), 49 deletions(-) delete mode 100644 php/tests/tests/desec-helpers.js create mode 100644 php/tests/tests/helpers.js diff --git a/php/tests/tests/desec-existing-slug.spec.js b/php/tests/tests/desec-existing-slug.spec.js index 01f1bfbe..179116cc 100644 --- a/php/tests/tests/desec-existing-slug.spec.js +++ b/php/tests/tests/desec-existing-slug.spec.js @@ -1,5 +1,5 @@ import { test, expect } from '@playwright/test'; -import { DESEC_MOCK_URL, logInToContainersPage } from './desec-helpers.js'; +import { DESEC_MOCK_URL, logInToContainersPage } from './helpers.js'; // Exercises reusing a slug the user already owns on an existing deSEC account. This is the // case that previously failed: deSEC answers POST /domains/ with 403 "Domain limit exceeded" diff --git a/php/tests/tests/desec-existing.spec.js b/php/tests/tests/desec-existing.spec.js index 7c5af394..0c8efacb 100644 --- a/php/tests/tests/desec-existing.spec.js +++ b/php/tests/tests/desec-existing.spec.js @@ -1,5 +1,5 @@ import { test, expect } from '@playwright/test'; -import { DESEC_MOCK_URL, logInToContainersPage } from './desec-helpers.js'; +import { DESEC_MOCK_URL, logInToContainersPage } from './helpers.js'; // Exercises the deSEC "I already have a verified account" login path: supplying a valid // password logs straight in and registers the domain in one step (no email-verification diff --git a/php/tests/tests/desec-helpers.js b/php/tests/tests/desec-helpers.js deleted file mode 100644 index 9332b308..00000000 --- a/php/tests/tests/desec-helpers.js +++ /dev/null @@ -1,22 +0,0 @@ -// Shared helpers for the deSEC Playwright scenarios. -// -// The deSEC mock is wired up by seeding configuration.json (see seed-desec-mock-config.php), -// which makes AIO consider itself already installed: /setup no longer renders the -// initial-password page. The seed step therefore writes a known master password (AIO_TEST_PASSWORD) -// that we log in with directly here instead of scraping it from /setup. - -export const DESEC_MOCK_URL = process.env.DESEC_MOCK_URL ?? 'http://localhost:8090'; - -const AIO_PASSWORD = process.env.AIO_TEST_PASSWORD; - -export async function logInToContainersPage(page) { - if (!AIO_PASSWORD) { - throw new Error('AIO_TEST_PASSWORD must be set to the master password seeded into configuration.json'); - } - await page.goto('./'); - await page.locator('#master-password').click(); - await page.locator('#master-password').fill(AIO_PASSWORD); - await page.getByRole('button', { name: 'Log in' }).click(); - await page.waitForURL('./containers'); - return page; -} diff --git a/php/tests/tests/desec-register.spec.js b/php/tests/tests/desec-register.spec.js index 7f2589ab..762012d2 100644 --- a/php/tests/tests/desec-register.spec.js +++ b/php/tests/tests/desec-register.spec.js @@ -1,5 +1,5 @@ import { test, expect } from '@playwright/test'; -import { DESEC_MOCK_URL, logInToContainersPage } from './desec-helpers.js'; +import { DESEC_MOCK_URL, logInToContainersPage } from './helpers.js'; // Drives the real AIO interface through the full deSEC "register a free domain" flow // against the local mock (php/tests/desec-mock.mjs). The mastercontainer's diff --git a/php/tests/tests/helpers.js b/php/tests/tests/helpers.js new file mode 100644 index 00000000..1246dad7 --- /dev/null +++ b/php/tests/tests/helpers.js @@ -0,0 +1,24 @@ +// Shared helpers for the deSEC Playwright scenarios. +// +// The deSEC mock is wired up by seeding configuration.json (see seed-desec-mock-config.php), +// which makes AIO consider itself already installed: /setup no longer renders the +// initial-password page. The seed step therefore writes a known master password (AIO_TEST_PASSWORD) +// that we log in with directly here instead of scraping it from /setup. + +export const DESEC_MOCK_URL = process.env.DESEC_MOCK_URL ?? 'http://localhost:8090'; + +export async function logInToContainersPage(setupPage) { + // Extract initial password + await setupPage.goto('./setup'); + const password = await setupPage.locator('#initial-password').innerText() + const containersPagePromise = setupPage.waitForEvent('popup'); + await setupPage.getByRole('link', { name: 'Open Nextcloud AIO login ↗' }).click(); + const containersPage = await containersPagePromise; + + // Log in and wait for redirect + await containersPage.locator('#master-password').click(); + await containersPage.locator('#master-password').fill(password); + await containersPage.getByRole('button', { name: 'Log in' }).click(); + await containersPage.waitForURL('./containers'); + return containersPage; +} diff --git a/php/tests/tests/initial-setup.spec.js b/php/tests/tests/initial-setup.spec.js index 0a133943..14636d8c 100755 --- a/php/tests/tests/initial-setup.spec.js +++ b/php/tests/tests/initial-setup.spec.js @@ -1,21 +1,11 @@ import { test, expect } from '@playwright/test'; import { writeFileSync } from 'node:fs' +import { logInToContainersPage } from './helpers.js'; test('Initial setup', async ({ page: setupPage }) => { test.setTimeout(10 * 60 * 1000) - // Extract initial password - await setupPage.goto('./setup'); - const password = await setupPage.locator('#initial-password').innerText() - const containersPagePromise = setupPage.waitForEvent('popup'); - await setupPage.getByRole('link', { name: 'Open Nextcloud AIO login ↗' }).click(); - const containersPage = await containersPagePromise; - - // Log in and wait for redirect - await containersPage.locator('#master-password').click(); - await containersPage.locator('#master-password').fill(password); - await containersPage.getByRole('button', { name: 'Log in' }).click(); - await containersPage.waitForURL('./containers'); + const containersPage = await logInToContainersPage(setupPage); // Reject IP addresses await containersPage.locator('#domain').click(); diff --git a/php/tests/tests/restore-instance.spec.js b/php/tests/tests/restore-instance.spec.js index 439c21b1..9f045a72 100755 --- a/php/tests/tests/restore-instance.spec.js +++ b/php/tests/tests/restore-instance.spec.js @@ -1,5 +1,6 @@ import { test, expect } from '@playwright/test'; import { readFileSync } from 'node:fs'; +import { logInToContainersPage } from './helpers.js'; test('Restore instance', async ({ page: setupPage }) => { test.setTimeout(10 * 60 * 1000) @@ -11,18 +12,7 @@ test('Restore instance', async ({ page: setupPage }) => { borgBackupPassword, } = JSON.parse(readFileSync('test_data.json')) - // Extract initial password - await setupPage.goto('./setup'); - const password = await setupPage.locator('#initial-password').innerText() - const containersPagePromise = setupPage.waitForEvent('popup'); - await setupPage.getByRole('link', { name: 'Open Nextcloud AIO login ↗' }).click(); - const containersPage = await containersPagePromise; - - // Log in and wait for redirect - await containersPage.locator('#master-password').click(); - await containersPage.locator('#master-password').fill(password); - await containersPage.getByRole('button', { name: 'Log in' }).click(); - await containersPage.waitForURL('./containers'); + const containersPage = await logInToContainersPage(setupPage); // Reject example.com (requires enabled domain validation) await containersPage.locator('#domain').click();