mirror of
https://github.com/coder/code-server.git
synced 2024-12-04 15:00:38 +08:00
d477972c68
* Move splitOnFirstEquals to util I will be making use of this to parse the forwarded header. * Type splitOnFirstEquals with two items Also add some test cases. * Check origin header on web sockets * Update changelog with origin check * Fix web sockets not closing with error code
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import * as httpserver from "../../../utils/httpserver"
|
|
import * as integration from "../../../utils/integration"
|
|
|
|
describe("health", () => {
|
|
let codeServer: httpserver.HttpServer | undefined
|
|
|
|
afterEach(async () => {
|
|
if (codeServer) {
|
|
await codeServer.dispose()
|
|
codeServer = undefined
|
|
}
|
|
})
|
|
|
|
it("/healthz", async () => {
|
|
codeServer = await integration.setup(["--auth=none"], "")
|
|
const resp = await codeServer.fetch("/healthz")
|
|
expect(resp.status).toBe(200)
|
|
const json = await resp.json()
|
|
expect(json).toStrictEqual({ lastHeartbeat: 0, status: "expired" })
|
|
})
|
|
|
|
it("/healthz (websocket)", async () => {
|
|
codeServer = await integration.setup(["--auth=none"], "")
|
|
const ws = codeServer.ws("/healthz")
|
|
const message = await new Promise((resolve, reject) => {
|
|
ws.on("error", (err) => {
|
|
console.error("[healthz]", err)
|
|
})
|
|
ws.on("message", (message) => {
|
|
try {
|
|
const j = JSON.parse(message.toString())
|
|
resolve(j)
|
|
} catch (error) {
|
|
reject(error)
|
|
}
|
|
})
|
|
ws.on("open", () => ws.send(JSON.stringify({ event: "health" })))
|
|
})
|
|
ws.terminate()
|
|
expect(message).toStrictEqual({ event: "health", status: "expired", lastHeartbeat: 0 })
|
|
})
|
|
})
|