test(e2e): address self-review follow-ups (dedup, XSS render guard, SSE hardening)
Follow-ups from the code review of the test-quality batches: - Consolidate duplicated helpers into e2e/helpers/: seed.ts (seedUpload, seedComment, listComments, findFeedRow) and sse.ts (mintSseTicket, openStream, trackStreamOpens). Refactor authorization-deep, xss-injection, like-comment, sse-ticket-abuse, ddos, sse-realtime, multi-tab, and SseListener to use them — the upload/comment/ticket-flow contracts now live in one place each instead of being re-inlined across 3–7 specs. - xss-injection display-name loop: it navigated to /feed (which renders uploader names, not the viewer's) so "nothing fired" passed vacuously — the payload was never rendered. Now navigate to /account (the actual sink) and add a render guard asserting the payload reached the DOM as escaped text before checking __xssFired. - sse-realtime reconnect: snapshot the stream-open count AFTER backgrounding, so the "new connection" assertion is attributable to the foreground event and can't be satisfied by a spurious native/error reconnect before the toggle. - recover-page: correct the comment (auto-submit is the onPinInput handler, not an $effect). 44 affected specs verified green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -5,37 +5,10 @@
|
||||
* with cross-user and banned-user scenarios that span multiple resources.
|
||||
*/
|
||||
import { test, expect } from '../../fixtures/test';
|
||||
import { uploadRaw, JPEG_MAGIC } from '../../helpers/upload-client';
|
||||
import { seedUpload, seedComment, listComments, findFeedRow } from '../../helpers/seed';
|
||||
|
||||
const BASE = process.env.E2E_FRONTEND_URL ?? 'http://localhost:3101';
|
||||
|
||||
/** Seed a real upload owned by `jwt` and return its id. */
|
||||
async function seedUpload(jwt: string, caption?: string): Promise<string> {
|
||||
const body = new Uint8Array(1024);
|
||||
body.set(JPEG_MAGIC, 0);
|
||||
const res = await uploadRaw(jwt, body, { filename: 'a.jpg', contentType: 'image/jpeg', caption });
|
||||
if (res.status !== 201) throw new Error(`seed upload failed: ${res.status} ${await res.text()}`);
|
||||
return (await res.json()).id;
|
||||
}
|
||||
|
||||
/** Seed a real comment on `uploadId` authored by `jwt`; return its id. */
|
||||
async function seedComment(jwt: string, uploadId: string, body = 'mine'): Promise<string> {
|
||||
const res = await fetch(`${BASE}/api/v1/upload/${uploadId}/comments`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${jwt}`, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ body }),
|
||||
});
|
||||
if (res.status !== 201) throw new Error(`seed comment failed: ${res.status} ${await res.text()}`);
|
||||
return (await res.json()).id;
|
||||
}
|
||||
|
||||
async function listComments(jwt: string, uploadId: string): Promise<any[]> {
|
||||
const res = await fetch(`${BASE}/api/v1/upload/${uploadId}/comments`, {
|
||||
headers: { Authorization: `Bearer ${jwt}` },
|
||||
});
|
||||
return res.json();
|
||||
}
|
||||
|
||||
test.describe('Adversarial — deep authorization', () => {
|
||||
// IDOR: user B must not be able to delete user A's REAL comment. This exercises the
|
||||
// ownership guard (`comment.user_id != auth.user_id` → 403) — the previous version fired
|
||||
@@ -87,13 +60,12 @@ test.describe('Adversarial — deep authorization', () => {
|
||||
});
|
||||
|
||||
// IDOR: user B must not be able to edit (re-caption / re-tag) user A's upload.
|
||||
test('user B cannot edit user A\'s upload caption (403, caption unchanged)', async ({ guest, db }) => {
|
||||
test('user B cannot edit user A\'s upload caption (403, caption unchanged)', async ({ guest }) => {
|
||||
const a = await guest('UploadOwnerA2');
|
||||
const b = await guest('AttackerB3');
|
||||
|
||||
const uploadId = await seedUpload(a.jwt, 'original caption');
|
||||
// Make it visible in the feed so we can read the caption back.
|
||||
await db.setUploadCompressionStatus(uploadId, 'done');
|
||||
// seedUpload marks compression done, so the upload is feed-visible for the read-back.
|
||||
const uploadId = await seedUpload(a.jwt, { caption: 'original caption' });
|
||||
|
||||
const res = await fetch(`${BASE}/api/v1/upload/${uploadId}`, {
|
||||
method: 'PATCH',
|
||||
@@ -104,9 +76,7 @@ test.describe('Adversarial — deep authorization', () => {
|
||||
|
||||
// No state change: the caption A set is intact.
|
||||
const feedRes = await fetch(`${BASE}/api/v1/feed`, { headers: { Authorization: `Bearer ${a.jwt}` } });
|
||||
const feed: any = await feedRes.json();
|
||||
const list: any[] = feed.uploads ?? feed.items ?? feed;
|
||||
const row = list.find((u: any) => u.id === uploadId);
|
||||
const row = findFeedRow(await feedRes.json(), uploadId);
|
||||
expect(row?.caption).toBe('original caption');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user