|
1 | 1 | import { RateLimiter } from "../../../src/node/routes/login"
|
| 2 | +import * as httpserver from "../../utils/httpserver" |
| 3 | +import * as integration from "../../utils/integration" |
2 | 4 |
|
3 | 5 | describe("login", () => {
|
4 | 6 | describe("RateLimiter", () => {
|
@@ -34,4 +36,41 @@ describe("login", () => {
|
34 | 36 | expect(limiter.removeToken()).toBe(false)
|
35 | 37 | })
|
36 | 38 | })
|
| 39 | + describe("/login", () => { |
| 40 | + let _codeServer: httpserver.HttpServer | undefined |
| 41 | + function codeServer(): httpserver.HttpServer { |
| 42 | + if (!_codeServer) { |
| 43 | + throw new Error("tried to use code-server before setting it up") |
| 44 | + } |
| 45 | + return _codeServer |
| 46 | + } |
| 47 | + |
| 48 | + // Store whatever might be in here so we can restore it afterward. |
| 49 | + // TODO: We should probably pass this as an argument somehow instead of |
| 50 | + // manipulating the environment. |
| 51 | + const previousEnvPassword = process.env.PASSWORD |
| 52 | + |
| 53 | + beforeEach(async () => { |
| 54 | + process.env.PASSWORD = "test" |
| 55 | + _codeServer = await integration.setup(["--auth=password"], "") |
| 56 | + }) |
| 57 | + |
| 58 | + afterEach(async () => { |
| 59 | + process.env.PASSWORD = previousEnvPassword |
| 60 | + if (_codeServer) { |
| 61 | + await _codeServer.close() |
| 62 | + _codeServer = undefined |
| 63 | + } |
| 64 | + }) |
| 65 | + |
| 66 | + it("should return HTML with 'Missing password' message", async () => { |
| 67 | + const resp = await codeServer().fetch("/login", { method: "POST" }) |
| 68 | + |
| 69 | + expect(resp.status).toBe(200) |
| 70 | + |
| 71 | + const htmlContent = await resp.text() |
| 72 | + |
| 73 | + expect(htmlContent).toContain("Missing password") |
| 74 | + }) |
| 75 | + }) |
37 | 76 | })
|
0 commit comments