MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / verifyAdminInBrowser

Function verifyAdminInBrowser

e2e/cloud/support/admin-mfa.ts:98–126  ·  view source on GitHub ↗
(page: Page, secret?: string)

Source from the content-addressed store, hash-verified

96
97/** Complete the visible MFA prompt using enrollment or this test identity's authenticator. */
98export const verifyAdminInBrowser = async (page: Page, secret?: string): Promise<void> => {
99 await page.getByRole("heading", { name: "Unlock organization settings" }).waitFor();
100 const [started] = await Promise.all([
101 page.waitForResponse((response) => response.url().endsWith("/api/auth/admin-mfa/start")),
102 page.getByRole("button", { name: "Continue", exact: true }).click(),
103 ]);
104 const raw: unknown = await started.json();
105 const setup = Option.getOrNull(decodeSetup(raw));
106 const key = setup?.secret ?? (Option.isSome(decodeChallenge(raw)) ? secret : undefined);
107 if (!started.ok() || !key) throw new Error("Could not open the test authenticator");
108 await page.getByLabel("Six-digit code").fill(new TOTP({ secret: key }).generate());
109 const [verified] = await Promise.all([
110 page.waitForResponse((response) => response.url().endsWith("/api/auth/admin-mfa/verify")),
111 page.getByRole("button", { name: "Verify", exact: true }).click(),
112 ]);
113 if (!verified.ok()) throw new Error("Browser admin verification failed");
114 await page
115 .getByRole("heading", { name: "Unlock organization settings" })
116 .waitFor({ state: "detached" });
117 // Successful verification reloads the document, so Chromium can discard that
118 // response body. Check the persisted session through the product instead.
119 const selector = new URL(page.url()).pathname.split("/")[1];
120 if (!selector) throw new Error("Admin verification has no organization scope");
121 const status = await page.request.get("/api/auth/admin-mfa", {
122 headers: { "x-executor-organization": selector },
123 });
124 if (!status.ok() || Option.isNone(decodeVerifiedState(await status.json())))
125 throw new Error("The browser session is not verified");
126};

Calls 3

jsonMethod · 0.65
generateMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected