Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion packages/api-server/test/rest-methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ skip("Get works on empty response", async t => {
t.is(response.statusCode, 204, "No content");
});

noGHTest("Get works when we have content", async t => {
test("Get works when we have content", async t => {
const { request, response } = mockRequestResponse("GET", "/api/get");

api.get("/api/get", RunnerMessageCode.MONITORING, comm);
Expand All @@ -73,6 +73,49 @@ noGHTest("Get works when we have content", async t => {
t.is(fullBody, "{\"healthy\":true}", "Data retrieved");
});

test("Get works with spaces and strange chars", async t => {
const endpoints = [
"/abc",
"/abc+",
"/abc ",
"/abc śź",
"/abc %0",
"/abc \0",
"/abc \t",
"/abc abc",
"/abc+abc",
"/abc%20abc",
"/abc\nabc",
"/abc'\"abc"
];

const monitorEndpoint = (name: string) => {
const out: { received: number, url?: string } = { received: 0 };

api.get(name, (message) => {
out.received++;
out.url = message.url;
return "OK";
});
return out;
};

const makeRequest = async (name: string) => {
const { request, response } = mockRequestResponse("GET", name);

server.request(request, response);

return [await response.fullBody, response.statusCode, name];
};

const srvSide = endpoints.map(monitorEndpoint);

const cliSide = await Promise.all(endpoints.map(makeRequest));

t.deepEqual(endpoints.map((name) => ["\"OK\"", 200, name]), cliSide);
t.deepEqual(endpoints.map((name) => ({ received: 1, url: name })), srvSide);
});

noGHTest("Op fails with bad and works with good content type", async t => {
let hadKilled = false;

Expand Down