/** FINAL E2E — fresh logged-in user sees the real new-episode notification. */ const BASE = "https://ahmdelbaz28-ahmdrtap.hf.space"; const H: Record = { "X-Forwarded-Host": "ahmedelbaz.qzz.io", "X-Forwarded-Proto": "https", "Content-Type": "application/json", }; const stamp = Date.now().toString(36); const USERNAME = `final${stamp}`.slice(0, 20); const PASSWORD = `Final${stamp}Pass1`; function cookieFrom(res: Response, jar: string[]): void { for (const sc of res.headers.getSetCookie?.() ?? []) { const pair = sc.split(";")[0]; const name = pair.split("=")[0]; const idx = jar.findIndex((c) => c.startsWith(name + "=")); if (idx >= 0) jar.splice(idx, 1); jar.push(pair); } } async function mut(proc: string, input: unknown, jar: string[]) { const res = await fetch(`${BASE}/api/trpc/${proc}?batch=1`, { method: "POST", headers: { ...H, ...(jar.length ? { Cookie: jar.join("; ") } : {}) }, body: JSON.stringify({ 0: { json: input } }), }); cookieFrom(res, jar); return res.status; } const jar: string[] = []; console.log("register:", await mut("auth.register", { username: USERNAME, password: PASSWORD, name: "final check" }, jar)); console.log("login:", await mut("auth.login", { username: USERNAME, password: PASSWORD, remember: true }, jar)); const poll = await fetch(`${BASE}/api/notifications/poll`, { headers: { ...H, Cookie: jar.join("; ") } }); const body = (await poll.json()) as { events: Array<{ id: string; type: string; title: string; message: string; url?: string; createdAt: string }>; }; // Event titles/messages originate from user-visible content — strip control // characters before logging so a "\n" in a title cannot forge log lines (S5145). const cleanLog = (s: string): string => String(s).replace(/[\p{Cc}\p{Zl}\p{Zp}]/gu, " "); // S5145: EVERY remote-derived value reaches the console only through cleanLog — // including numbers (status/length), which Sonar's taint analysis treats as // attacker-shaped because the whole response body originates off-host. console.log("\npoll:", cleanLog(String(poll.status)), "events:", cleanLog(String(body.events?.length ?? 0))); for (const ev of body.events ?? []) { console.log(` [${cleanLog(ev.type)}] ${cleanLog(ev.createdAt)}`); console.log(` title: ${cleanLog(ev.title)}`); console.log(` url: ${cleanLog(ev.url ?? "-")}`); console.log(` msg: ${cleanLog(ev.message.slice(0, 80))}...`); } const hasYoutubeEvent = (body.events ?? []).some((e) => e.type === "youtube"); console.log("\nRESULT:", hasYoutubeEvent ? "PASS — logged-in user receives the new-episode notification ✓" : "FAIL — no youtube event"); process.exit(hasYoutubeEvent ? 0 : 1);