You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
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);
|
|
});
|
|
});
|
|
|