Files
computer-playbook/roles/web-app-moodle/files/playwright/test-baseline.js
kevinveenbirkenbachandClaude Opus 4.8 4c91df5de7 test(e2e): forbid raw page.goto, migrate all specs to Tor-resilient gotoOnion
New lint test_no_raw_goto.py forbids raw `page.goto(...)` in role playwright specs + persona flows (the gotoOnion wrapper in personas/utils is exempt) so navigation retries transient Tor-transport errors over onion. Migrates every raw call across ~75 roles (343 sites) to `gotoOnion(page, ...)` and teaches gotoOnion to detect relative onion URLs (`isOnionCanonical`). gotoOnion is a behaviour-identical drop-in on clearnet (single attempt, same return). Verified: no-raw-goto lint green, eslint 0 errors, make test green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 20:59:38 +02:00

27 lines
1.3 KiB
JavaScript

const { test, expect } = require("@playwright/test");
const { resolveTimeout } = require("./timeouts");
const { decodeDotenvQuotedValue, gotoOnion } = require("./personas");
const canonicalDomain = decodeDotenvQuotedValue(process.env.CANONICAL_DOMAIN);
exports.register = function (shared) {
test("moodle baseline: landing page reachable + canonical domain in URL", async ({ page }) => {
const response = await gotoOnion(page, `${shared.env.moodleBaseUrl}/`);
expect(response, "expected response").toBeTruthy();
expect(response.status(), "landing status < 400").toBeLessThan(400);
expect(
response.url().includes(canonicalDomain),
`expected canonical domain "${canonicalDomain}" in url`
).toBe(true);
});
test("moodle baseline: CSP header present, no violations on landing", async ({ page }) => {
const response = await gotoOnion(page, `${shared.env.moodleBaseUrl}/`);
const csp = response.headers()["content-security-policy"];
expect(csp, "Content-Security-Policy header expected").toBeTruthy();
await page.waitForTimeout(resolveTimeout(500));
const violations = await page.evaluate(() => window.__cspViolations || []);
expect(violations, `unexpected CSP violations: ${JSON.stringify(violations)}`).toEqual([]);
});
};