|
1 | | -import { expect, test, type Page } from "@playwright/test" |
| 1 | +import { chromium, expect, test, type Page } from "@playwright/test" |
2 | 2 | import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises" |
3 | 3 | import { createServer, type ServerResponse } from "node:http" |
4 | 4 | import type { AddressInfo } from "node:net" |
@@ -453,3 +453,44 @@ test("the production build precaches every deployable file except on-demand Offi |
453 | 453 | await new Promise<void>((resolve, reject) => server.close((error) => (error ? reject(error) : resolve()))) |
454 | 454 | } |
455 | 455 | }) |
| 456 | + |
| 457 | +test("the production build installs as an app behind an authenticating proxy", async () => { |
| 458 | + const directory = new URL("../../dist/", import.meta.url) |
| 459 | + |
| 460 | + const server = createServer(async (request, response) => { |
| 461 | + // Model a reverse proxy that rejects every request without the signed-in user's cookie. |
| 462 | + if (!request.headers.cookie?.includes("session=signed-in")) return void response.writeHead(401).end() |
| 463 | + const path = new URL(request.url ?? "/", "http://localhost").pathname |
| 464 | + const file = extname(path) ? path : "/index.html" |
| 465 | + const bytes = await readFile(new URL(`.${file}`, directory)).catch(() => undefined) |
| 466 | + |
| 467 | + if (!bytes) return void response.writeHead(404).end("Not found") |
| 468 | + |
| 469 | + // Check the real HTML without starting the app or its service worker. |
| 470 | + if (file === "/index.html") |
| 471 | + response.writeHead(200, { "content-type": "text/html", "content-security-policy": "script-src 'none'" }) |
| 472 | + |
| 473 | + response.end(bytes) |
| 474 | + }) |
| 475 | + |
| 476 | + server.listen(0, "127.0.0.1") |
| 477 | + await once(server, "listening") |
| 478 | + // SAFETY: a server listening on a host and port reports an AddressInfo; only pipe servers report a string. |
| 479 | + const address = server.address() as AddressInfo |
| 480 | + const url = `http://127.0.0.1:${address.port}` |
| 481 | + // Chrome Headless Shell has no install checks and reports no errors for any page, and an incognito context always |
| 482 | + // reports one, so check in a persistent Chrome profile. |
| 483 | + const context = await chromium.launchPersistentContext("", { channel: "chromium" }) |
| 484 | + |
| 485 | + try { |
| 486 | + await context.addCookies([{ name: "session", value: "signed-in", url }]) |
| 487 | + const page = await context.newPage() |
| 488 | + await page.goto(url) |
| 489 | + const session = await context.newCDPSession(page) |
| 490 | + expect((await session.send("Page.getInstallabilityErrors")).installabilityErrors).toEqual([]) |
| 491 | + } finally { |
| 492 | + await context.close() |
| 493 | + server.closeAllConnections() |
| 494 | + await new Promise<void>((resolve, reject) => server.close((error) => (error ? reject(error) : resolve()))) |
| 495 | + } |
| 496 | +}) |
0 commit comments