Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/security/boundaries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ describe("security boundaries", () => {
"Untrusted HTTPS origin: https://evil.example",
);
expect(() => policy.assertTrusted("not-an-origin")).toThrow();

// Test URL objects
expect(policy.isTrusted(new URL("https://example.substack.com/publish"))).toBe(true);
expect(policy.isTrusted(new URL("https://evil.example/publish"))).toBe(false);

// Test successful assertTrusted
const validUrl = policy.assertTrusted("https://example.substack.com");
expect(validUrl).toBeInstanceOf(URL);
expect(validUrl.origin).toBe("https://example.substack.com");

const validUrlObj = policy.assertTrusted(new URL("https://example.substack.com"));
expect(validUrlObj).toBeInstanceOf(URL);

// Test successful assertRedirect
const redirectUrl = policy.assertRedirect(
"https://example.substack.com",
"https://substack.com/api/v1/user",
);
expect(redirectUrl).toBeInstanceOf(URL);
expect(redirectUrl.origin).toBe("https://substack.com");

const redirectUrlObj = policy.assertRedirect(
new URL("https://example.substack.com"),
new URL("https://substack.com/api/v1/user"),
);
expect(redirectUrlObj).toBeInstanceOf(URL);
expect(redirectUrlObj.origin).toBe("https://substack.com");
});

it("rejects non-origin trusted policy configuration", () => {
Expand Down
Loading