mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-30 20:00:55 +08:00
Applies #660 (remove ?token= query extraction, switch web SSE to fetch+ Authorization Bearer, drop client-written auth cookie) cleanly on top of #633's same-origin CORS policy. Preserves #633's same-origin ACAO + Vary: Origin while allowing Authorization and Last-Event-ID on same-origin preflights, aligns openSSE 401 cookie clearing attributes, and updates the upload.test.mjs and traffic-stream.test.mjs harnesses for @/lib/sse (SSEStream stub + EventTarget, Event, MessageEvent, AbortController in VM context). Co-authored-by: Coff0xc <184964491+Coff0xc@users.noreply.github.com>
29 lines
1.0 KiB
JavaScript
29 lines
1.0 KiB
JavaScript
import ts from "typescript";
|
|
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { test } from "node:test";
|
|
import vm from "node:vm";
|
|
|
|
const output = ts.transpileModule(readFileSync(new URL("../src/lib/auth.ts", import.meta.url), "utf8"), {
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
|
|
}).outputText;
|
|
|
|
test("HTTPS marks the session cookie Secure while local HTTP remains usable", () => {
|
|
for (const protocol of ["https:", "http:"]) {
|
|
const storage = new Map();
|
|
const document = { cookie: "" };
|
|
const exports = {};
|
|
vm.runInNewContext(output, {
|
|
exports,
|
|
document,
|
|
window: { location: { protocol } },
|
|
localStorage: { setItem: (k, v) => storage.set(k, v) },
|
|
});
|
|
exports.auth.setToken("synthetic-session");
|
|
assert.equal(storage.get("artex_token"), "synthetic-session");
|
|
assert.equal(document.cookie.includes("; Secure"), protocol === "https:");
|
|
assert.ok(document.cookie.includes("SameSite=Lax"));
|
|
}
|
|
});
|