|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | + |
| 3 | +import { assertFrameSession, frameAllowPolicy, normalizeFramePath } from "./index.js"; |
| 4 | + |
| 5 | +describe("normalizeFramePath", () => { |
| 6 | + test("canonicalizes page paths", () => { |
| 7 | + expect(normalizeFramePath("/guides/./start/index.html")).toBe("/guides/start"); |
| 8 | + expect(normalizeFramePath("/guides/next/../start")).toBe("/guides/start"); |
| 9 | + expect(normalizeFramePath("/")).toBe("/"); |
| 10 | + }); |
| 11 | + |
| 12 | + test("rejects URL-shaped and root-escaping input", () => { |
| 13 | + for (const path of [ |
| 14 | + "https://example.com/page", |
| 15 | + "//example.com", |
| 16 | + "/../../secret", |
| 17 | + "/a%2Fb", |
| 18 | + "/a?b=1", |
| 19 | + ]) { |
| 20 | + expect(() => normalizeFramePath(path)).toThrow(); |
| 21 | + } |
| 22 | + }); |
| 23 | +}); |
| 24 | + |
| 25 | +test("frameAllowPolicy emits only supported, unique permissions", () => { |
| 26 | + expect(frameAllowPolicy(["fullscreen", "camera", "fullscreen"])).toBe("camera; fullscreen"); |
| 27 | +}); |
| 28 | + |
| 29 | +test("assertFrameSession requires a live HTTPS session", () => { |
| 30 | + const expiresAt = new Date(Date.now() + 60_000).toISOString(); |
| 31 | + expect(assertFrameSession({ url: "https://demo.view.fast/?__=sfv_token", expiresAt })).toEqual({ |
| 32 | + url: "https://demo.view.fast/?__=sfv_token", |
| 33 | + expiresAt, |
| 34 | + }); |
| 35 | + expect(() => assertFrameSession({ url: "http://demo.example/page", expiresAt })).toThrow( |
| 36 | + "must use HTTPS", |
| 37 | + ); |
| 38 | + expect(() => |
| 39 | + assertFrameSession({ |
| 40 | + url: "https://demo.view.fast/", |
| 41 | + expiresAt: new Date(Date.now() - 1_000).toISOString(), |
| 42 | + }), |
| 43 | + ).toThrow("already expired"); |
| 44 | +}); |
0 commit comments