import { describe, expect, test } from "bun:test"; import { assertSafeRssUrl, assertSafeRssUrlForFetch, RssUrlUnsafeError } from "./rss-url"; describe("assertSafeRssUrl", () => { test("allows https example", () => { expect(() => assertSafeRssUrl("https://example.com/feed.xml")).not.toThrow(); }); test("rejects file protocol", () => { expect(() => assertSafeRssUrl("file:///etc/passwd")).toThrow(RssUrlUnsafeError); }); test("rejects localhost", () => { expect(() => assertSafeRssUrl("http://localhost/feed")).toThrow(RssUrlUnsafeError); }); test("rejects private ipv4 literal", () => { expect(() => assertSafeRssUrl("http://192.168.1.1/feed")).toThrow(RssUrlUnsafeError); }); }); describe("assertSafeRssUrlForFetch", () => { test("allows public ipv4 literal without dns", async () => { const u = await assertSafeRssUrlForFetch("https://1.1.1.1/feed.xml"); expect(u).toContain("1.1.1.1"); }); test("rejects private ipv4 literal", async () => { await expect(assertSafeRssUrlForFetch("https://10.0.0.1/feed")).rejects.toThrow(RssUrlUnsafeError); }); test("rejects unresolvable host", async () => { await expect( assertSafeRssUrlForFetch("http://this-name-should-not-exist-xyz-12345.invalid/feed"), ).rejects.toThrow(RssUrlUnsafeError); }); });