import { isSameDomain, applyCustomDappUrl, isUrlAllowedByManifestDomains, } from "./manifestDomainUtils"; describe("manifestDomainUtils", () => { describe("isSameDomain", () => { it("should return true for same domains and protocols", () => { expect(isSameDomain("https://example.com/path1", "https://example.com/path2")).toBe(true); }); it("should return false for same domains with different protocols", () => { expect(isSameDomain("http://example.com/path1", "https://example.com/path2")).toBe(false); }); it("should return true for same domains and protocols with different ports", () => { expect(isSameDomain("https://example.com:3000/path1", "https://example.com:8080/path2")).toBe( true, ); }); it("should return true for same domains and protocols with different query params", () => { expect(isSameDomain("https://example.com/path?a=1", "https://example.com/path?b=2")).toBe( true, ); }); it("should return true for same domains and protocols with different paths", () => { expect(isSameDomain("https://example.com/path1", "https://example.com/path2")).toBe(true); }); it("should return true for same domains and protocols with different hashes", () => { expect( isSameDomain("https://example.com/path#section1", "https://example.com/path#section2"), ).toBe(true); }); it("should return false for different domains", () => { expect(isSameDomain("https://example.com/path", "https://other.com/path")).toBe(false); }); it("should return true for different subdomains (same base domain)", () => { expect(isSameDomain("https://app.example.com/path", "https://api.example.com/path")).toBe( true, ); }); it("should return true for subdomain and base domain", () => { expect(isSameDomain("https://example.com/path", "https://app.example.com/path")).toBe(true); }); it("should return true for www subdomain and base domain", () => { expect(isSameDomain("https://www.example.com/path", "https://example.com/path")).toBe(true); }); it("should return true for multiple levels of subdomains", () => { expect( isSameDomain( "https://api.staging.example.com/path", "https://app.production.example.com/path", ), ).toBe(true); }); it("should return true for .co.uk domains with different subdomains", () => { expect(isSameDomain("https://app.example.co.uk/path", "https://api.example.co.uk/path")).toBe( true, ); }); it("should return true for .co.uk subdomain and base domain", () => { expect(isSameDomain("https://example.co.uk/path", "https://www.example.co.uk/path")).toBe( true, ); }); it("should return false for different .co.uk base domains", () => { expect(isSameDomain("https://example.co.uk/path", "https://other.co.uk/path")).toBe(false); }); it("should return false for http vs https", () => { expect(isSameDomain("http://example.com/path", "https://example.com/path")).toBe(false); }); it("should return false for https vs http", () => { expect(isSameDomain("https://example.com/path", "http://example.com/path")).toBe(false); }); it("should return false when first URL is undefined", () => { expect(isSameDomain(undefined, "https://example.com/path")).toBe(false); }); it("should return false when second URL is undefined", () => { expect(isSameDomain("https://example.com/path", undefined)).toBe(false); }); it("should return false when both URLs are undefined", () => { expect(isSameDomain(undefined, undefined)).toBe(false); }); it("should return false when first URL is invalid", () => { expect(isSameDomain("not-a-url", "https://example.com/path")).toBe(false); }); it("should return false when second URL is invalid", () => { expect(isSameDomain("https://example.com/path", "not-a-url")).toBe(false); }); it("should return false when both URLs are invalid", () => { expect(isSameDomain("not-a-url", "not-a-url")).toBe(false); }); it("should return false for localhost URLs", () => { expect(isSameDomain("http://localhost:3000", "http://localhost:8080")).toBe(false); }); it("should return false for IP address URLs", () => { expect(isSameDomain("http://192.168.1.1", "http://192.168.1.2")).toBe(false); }); }); describe("isUrlAllowedByManifestDomains", () => { it("should allow https URL when domains include https://*", () => { expect(isUrlAllowedByManifestDomains("https://example.com/path", ["https://*"])).toBe(true); expect(isUrlAllowedByManifestDomains("https://any.domain.com/foo", ["https://*"])).toBe(true); }); it("should allow exact origin match", () => { expect( isUrlAllowedByManifestDomains("https://example.com/page", ["https://example.com"]), ).toBe(true); }); it("should reject URL when origin does not match any pattern", () => { expect(isUrlAllowedByManifestDomains("https://other.com/path", ["https://example.com"])).toBe( false, ); }); it("should reject non-https and non-http schemes", () => { expect(isUrlAllowedByManifestDomains("javascript:alert(1)", ["https://*"])).toBe(false); expect(isUrlAllowedByManifestDomains("data:text/html,