mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-13 14:37:26 +00:00
Handle malformed CommandBoard paths (#76)
This commit is contained in:
parent
ae371b91d0
commit
cb192906bd
3 changed files with 72 additions and 38 deletions
31
apps/commandboard-web/server.test.js
Normal file
31
apps/commandboard-web/server.test.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { createCommandBoardWebServer } from "./server.js";
|
||||
|
||||
let server;
|
||||
let baseUrl;
|
||||
|
||||
beforeAll(async () => {
|
||||
server = createCommandBoardWebServer();
|
||||
await new Promise((resolve) => server.listen(0, resolve));
|
||||
const address = server.address();
|
||||
if (!address || typeof address === "string") {
|
||||
throw new Error("Expected web server to bind to a local port");
|
||||
}
|
||||
baseUrl = `http://127.0.0.1:${address.port}`;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await new Promise((resolve, reject) => {
|
||||
server.close((error) => (error ? reject(error) : resolve()));
|
||||
});
|
||||
});
|
||||
|
||||
describe("CommandBoard web server", () => {
|
||||
it("rejects malformed path encoding as a client error", async () => {
|
||||
const response = await fetch(`${baseUrl}/%E0%A4%A`);
|
||||
const body = await response.text();
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
expect(body).toBe("Invalid path encoding");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue