server/tests/api.test.ts

56 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

import { afterAll, describe, expect, test } from "bun:test";
import { fakeRequest, getTestUsers } from "./utils.ts";
2023-09-22 00:42:59 +02:00
2024-04-14 02:46:33 +02:00
const { tokens, deleteUsers } = await getTestUsers(1);
2023-09-22 00:42:59 +02:00
2023-10-18 02:57:47 +02:00
describe("API Tests", () => {
2024-04-07 07:30:49 +02:00
afterAll(async () => {
2024-04-14 02:46:33 +02:00
await deleteUsers();
2024-04-07 07:30:49 +02:00
});
test("Try sending FormData without a boundary", async () => {
const formData = new FormData();
formData.append("test", "test");
const response = await fakeRequest("/api/v1/statuses", {
method: "POST",
headers: {
Authorization: `Bearer ${tokens[0].data.accessToken}`,
"Content-Type": "multipart/form-data",
},
body: formData,
});
expect(response.status).toBe(400);
const data = await response.json();
expect(data.error).toBeString();
expect(data.error).toContain("https://stackoverflow.com");
});
// Now automatically mitigated by the server
/* test("try sending a request with a different origin", async () => {
if (new URL(config.http.base_url).protocol === "http:") {
return;
}
const response = await fakeRequest(
"/api/v1/instance",
base_url.replace("https://", "http://"),
),
{
method: "GET",
headers: {
Authorization: `Bearer ${tokens[0].data.accessToken}`,
},
},
),
);
expect(response.status).toBe(400);
const data = await response.json();
expect(data.error).toContain("does not match base URL");
}); */
2023-09-22 00:42:59 +02:00
});