/
githubmirror
/
code-server
Обзор
Документация
Войти
/
githubmirror
/
code-server
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/unit/node/routes/health.test.ts
42 строки
1 KB
Asher
Add origin checks to web sockets (#6048)
03 мар 2023, 12:12
Не верифицирован
03 мар 2023, 12:12
d477972
Код
Авторство
О чём код?
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 }) }) })