-
Notifications
You must be signed in to change notification settings - Fork 0
test(admin): extend the accessibility scan to the main admin pages #1424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c02a0c2
test(admin): extend the accessibility scan to the main admin pages
solarssk 88a95bc
fix(admin): make the item "Not yet" label readable and the admin a11y…
solarssk e87cb63
test(admin): reset item state in the E2E seed so the a11y scan is rep…
solarssk cb77b72
test(admin): wait for spinners to clear instead of network idle in th…
solarssk 1fe0353
Merge branch 'main' into test/a11y-admin-surfaces
solarssk f58b417
test(admin): scan admin pages only once their data has loaded and ani…
solarssk 8b02ef3
Merge remote-tracking branch 'origin/main' into test/a11y-admin-surfaces
solarssk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { createHmac } from "node:crypto"; | ||
| import type { Page } from "@playwright/test"; | ||
|
|
||
| /** | ||
| * Signs the seeded superadmin in over the API on the page's own cookie jar, walking the forced | ||
| * TOTP enrollment (login -> totp/enroll -> totp/confirm -> backup-codes/complete). Admin roles | ||
| * must have MFA, and the enrollment secret only exists in the enroll response, so the code is | ||
| * computed here instead of driving the QR screen. Afterwards `page.goto("/admin/...")` is signed in. | ||
| */ | ||
|
|
||
| function base32Decode(input: string): Buffer { | ||
| const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | ||
| let bits = ""; | ||
| for (const ch of input.split("=")[0]!.toUpperCase()) { | ||
| const idx = alphabet.indexOf(ch); | ||
| if (idx < 0) throw new Error("invalid base32 secret"); | ||
| bits += idx.toString(2).padStart(5, "0"); | ||
| } | ||
| const bytes: number[] = []; | ||
| for (let i = 0; i + 8 <= bits.length; i += 8) | ||
| bytes.push(Number.parseInt(bits.slice(i, i + 8), 2)); | ||
| return Buffer.from(bytes); | ||
| } | ||
|
|
||
| function totp( | ||
| secret: string, | ||
| digits: number, | ||
| period: number, | ||
| algorithm: string, | ||
| ): string { | ||
| const counter = Math.floor(Date.now() / 1000 / period); | ||
| const buf = Buffer.alloc(8); | ||
| buf.writeBigUInt64BE(BigInt(counter)); | ||
| const hmac = createHmac(algorithm, base32Decode(secret)).update(buf).digest(); | ||
| const offset = hmac[hmac.length - 1]! & 0x0f; | ||
| const code = (hmac.readUInt32BE(offset) & 0x7fffffff) % 10 ** digits; | ||
| return String(code).padStart(digits, "0"); | ||
| } | ||
|
|
||
| export async function signInAsAdmin( | ||
| page: Page, | ||
| baseUrl: string, | ||
| email: string, | ||
| password: string, | ||
| ): Promise<void> { | ||
| const origin = new URL(baseUrl).origin; | ||
| const post = async (path: string, data?: Record<string, unknown>) => { | ||
| const res = await page.request.post(path, { | ||
| headers: { Origin: origin }, | ||
| data, | ||
| }); | ||
| if (!res.ok()) | ||
| throw new Error(`POST ${path} -> ${res.status()} ${await res.text()}`); | ||
| return (await res.json()) as Record<string, unknown>; | ||
| }; | ||
|
|
||
| let step = await post("/api/auth/login", { email, password }); | ||
| if (step["next"] === "enrollment_required") { | ||
| const enrolled = await post("/api/auth/mfa/totp/enroll"); | ||
| const uri = new URL(String(enrolled["otpauth_uri"])); | ||
| const secret = uri.searchParams.get("secret"); | ||
| if (!secret) throw new Error("enroll response had no TOTP secret"); | ||
| const code = totp( | ||
| secret, | ||
| Number(uri.searchParams.get("digits") ?? 6), | ||
| Number(uri.searchParams.get("period") ?? 30), | ||
| (uri.searchParams.get("algorithm") ?? "SHA1").toLowerCase(), | ||
| ); | ||
| step = await post("/api/auth/mfa/totp/confirm", { code }); | ||
| } | ||
| if (step["next"] === "backup_codes_required") { | ||
| step = await post("/api/auth/mfa/totp/backup-codes/complete"); | ||
| } | ||
| if (step["next"] !== "complete") { | ||
| throw new Error( | ||
| `admin login did not reach a full session (next=${String(step["next"])})`, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.