Spaces:
Running

File size: 2,719 Bytes
6207c91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c15d63
 
88ffd69
4e35045
 
 
 
6207c91
4e35045
9c15d63
d9d7a37
 
6207c91
23a1787
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/** FINAL E2E — fresh logged-in user sees the real new-episode notification. */
const BASE = "https://ahmdelbaz28-ahmdrtap.hf.space";
const H: Record<string, string> = {
  "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);