| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { isSecureRelayUrl, normalizeSecureRelayUrl } from "./relayUrl.ts"; |
| 4 | |
| 5 | describe("normalizeSecureRelayUrl", () => { |
| 6 | it("normalizes secure relay origins", () => { |
| 7 | expect(normalizeSecureRelayUrl(" https://relay.example.test/// ")).toBe( |
| 8 | "https://relay.example.test", |
| 9 | ); |
| 10 | expect(normalizeSecureRelayUrl("https://relay.example.test:8443/")).toBe( |
| 11 | "https://relay.example.test:8443", |
| 12 | ); |
| 13 | }); |
| 14 | |
| 15 | it.each([ |
| 16 | "http://relay.example.test", |
| 17 | "https://user:password@relay.example.test", |
| 18 | "https://relay.example.test/path", |
| 19 | "https://relay.example.test?query=value", |
| 20 | "https://relay.example.test#fragment", |
| 21 | "not a url", |
| 22 | ])("rejects unsafe relay URL %s", (value) => { |
| 23 | expect(normalizeSecureRelayUrl(value)).toBeNull(); |
| 24 | expect(isSecureRelayUrl(value)).toBe(false); |
| 25 | }); |
| 26 | }); |