mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -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 () => {
|
||||
|
||||
@@ -170,7 +170,7 @@ describe("Error handling", () => {
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
},
|
||||
});
|
||||
expect(res.statusCode).toBe(422);
|
||||
expect([400, 422]).toContain(res.statusCode);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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 ─────────────────────
|
||||
|
||||
@@ -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 ──────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user