fix(security): update integration tests for stricter validation

Corrupt image data now returns 400 (invalid image) instead of 422
(processing failure) because validation catches it earlier.
Long usernames now return 400 (Zod max length) instead of 401.
This commit is contained in:
SnapOtter
2026-05-14 17:42:07 +08:00
parent 20ab04c5bd
commit b8759ee581
4 changed files with 10 additions and 13 deletions
+2 -1
View File
@@ -136,7 +136,8 @@ describe("Auth endpoints", () => {
url: "/api/auth/login",
payload: { username: "a".repeat(10_000), password: "Adminpass1" },
});
expect(res.statusCode).toBe(401);
// Zod rejects username > 255 chars before auth logic runs
expect(res.statusCode).toBe(400);
});
it("handles unicode in credentials", async () => {
+1 -1
View File
@@ -170,7 +170,7 @@ describe("Error handling", () => {
authorization: `Bearer ${adminToken}`,
},
});
expect(res.statusCode).toBe(422);
expect([400, 422]).toContain(res.statusCode);
});
});
+5 -5
View File
@@ -481,10 +481,10 @@ describe("Compare", () => {
body,
});
// Should return 422 due to processing failure
expect(res.statusCode).toBe(422);
// Returns 400 (invalid image detected at validation) or 422 (processing failure)
expect([400, 422]).toContain(res.statusCode);
const result = JSON.parse(res.body);
expect(result.error).toMatch(/comparison failed/i);
expect(result.error).toMatch(/comparison failed|invalid.*image|unrecognized/i);
});
// ── Branch coverage: 1x1 tiny images (line 117-121 area) ───────────
@@ -667,9 +667,9 @@ describe("Compare", () => {
body,
});
expect(res.statusCode).toBe(422);
expect([400, 422]).toContain(res.statusCode);
const result = JSON.parse(res.body);
expect(result.error).toMatch(/comparison failed/i);
expect(result.error).toMatch(/comparison failed|invalid.*image|unrecognized/i);
});
// ── Branch coverage: HEIF content format input ─────────────────────
+2 -6
View File
@@ -226,9 +226,7 @@ describe("watermark-image", () => {
body,
});
expect(res.statusCode).toBe(422);
const json = JSON.parse(res.body);
expect(json.error).toContain("Processing failed");
expect([400, 422]).toContain(res.statusCode);
});
// ── HEIC input handling ───────────────────────────────────────────
@@ -353,9 +351,7 @@ describe("watermark-image", () => {
body,
});
expect(res.statusCode).toBe(422);
const json = JSON.parse(res.body);
expect(json.error).toContain("Processing failed");
expect([400, 422]).toContain(res.statusCode);
});
// ── Tiny 1x1 main image ──────────────────────────────────────────