feat(e2e): add support running behind proxy (#5348)
* docs: update maintaining * chore(e2e): add maxFailures to playwright * fix(ci): skip submodule in e2e job We don't need the submodules for the e2e job. This will speed up the checkout step. * feat(ci): add test-e2e-proxy job This adds a new job to CI to run our tests behind Caddy and simulate code-server running against a reverse-proxy. * refactor: make e2e work with reverse proxy This refactors the e2e test in a couple ways: - remove setting cookie in localStorage (instead we pass --auth none) - refactor address() method to account for reverse proxy logic * Update test/e2e/models/CodeServer.ts * Update test/playwright.config.ts * Update test/utils/constants.ts Co-authored-by: Asher <ash@coder.com> * Update test/utils/helpers.ts Co-authored-by: Asher <ash@coder.com> Co-authored-by: Asher <ash@coder.com>
This commit is contained in:
@ -1,2 +1,4 @@
|
||||
export const PASSWORD = "e45432jklfdsab"
|
||||
export const workspaceDir = "workspaces"
|
||||
export const REVERSE_PROXY_BASE_PATH = process.env.CS_TEST_REVERSE_PROXY_BASE_PATH || "ide"
|
||||
export const REVERSE_PROXY_PORT = process.env.CS_TEST_REVERSE_PROXY_PORT || "8000"
|
||||
|
@ -1,7 +1,4 @@
|
||||
import { Cookie } from "playwright"
|
||||
import { CookieKeys } from "../../src/common/http"
|
||||
import { hash } from "../../src/node/util"
|
||||
import { PASSWORD, workspaceDir } from "./constants"
|
||||
import { workspaceDir } from "./constants"
|
||||
import { clean } from "./helpers"
|
||||
import * as wtfnode from "./wtfnode"
|
||||
|
||||
@ -20,25 +17,5 @@ export default async function () {
|
||||
wtfnode.setup()
|
||||
}
|
||||
|
||||
// TODO: Replace this with a call to code-server to get the cookie. To avoid
|
||||
// too much overhead we can do an http POST request and avoid spawning a
|
||||
// browser for it.
|
||||
const cookies: Cookie[] = [
|
||||
{
|
||||
domain: "localhost",
|
||||
expires: -1,
|
||||
httpOnly: false,
|
||||
name: CookieKeys.Session,
|
||||
path: "/",
|
||||
sameSite: "Lax",
|
||||
secure: false,
|
||||
value: await hash(PASSWORD),
|
||||
},
|
||||
]
|
||||
|
||||
// Save storage state and store as an env variable
|
||||
// More info: https://playwright.dev/docs/auth/#reuse-authentication-state
|
||||
process.env.STORAGE = JSON.stringify({ cookies })
|
||||
|
||||
console.log("✅ Global Setup for Playwright End-to-End Tests is now complete.")
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ import { promises as fs } from "fs"
|
||||
import * as net from "net"
|
||||
import * as os from "os"
|
||||
import * as path from "path"
|
||||
import { CodeServer, CodeServerPage } from "../e2e/models/CodeServer"
|
||||
import { REVERSE_PROXY_PORT, REVERSE_PROXY_BASE_PATH } from "./constants"
|
||||
|
||||
/**
|
||||
* Spy on the logger and console and replace with mock implementations to
|
||||
@ -119,3 +121,18 @@ export function isAddressInfo(address: unknown): address is net.AddressInfo {
|
||||
(address as net.AddressInfo).address !== undefined
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* If using a proxy, return the address of the proxy.
|
||||
*
|
||||
* Otherwise, return the direct address of code-server.
|
||||
*/
|
||||
export async function getMaybeProxiedCodeServer(codeServer: CodeServerPage | CodeServer): Promise<string> {
|
||||
const address = await codeServer.address()
|
||||
if (process.env.USE_PROXY === "1") {
|
||||
const uri = new URL(address)
|
||||
return `http://${uri.hostname}:${REVERSE_PROXY_PORT}/${uri.port}/${REVERSE_PROXY_BASE_PATH}/`
|
||||
}
|
||||
|
||||
return address
|
||||
}
|
||||
|
Reference in New Issue
Block a user