A desktop coding agent with free access to frontier models.
TypeScript
import { describe, expect, test } from "bun:test";
import { normalizeOrganizationServerInput } from "../src/app/lib/organization-server-input";
describe("normalizeOrganizationServerInput", () => {
test("normalizes full URLs and bare hostnames to their origin", () => {
expect(normalizeOrganizationServerInput("https://omnirush.acme.com/werpiweur")).toBe(
"https://omnirush.acme.com",
);
expect(normalizeOrganizationServerInput(" omnirush.acme.com ")).toBe(
"https://omnirush.acme.com",
);
expect(normalizeOrganizationServerInput("http://localhost:3005/dashboard?x=1#y")).toBe(
"http://localhost:3005",
);
expect(normalizeOrganizationServerInput("https://omnirush.acme.com:8443/path")).toBe(
"https://omnirush.acme.com:8443",
);
});
test("allows http only for loopback hosts", () => {
expect(normalizeOrganizationServerInput("http://localhost:3005")).toBe(
"http://localhost:3005",
);
expect(normalizeOrganizationServerInput("http://127.0.0.1")).toBe(
"http://127.0.0.1",
);
expect(normalizeOrganizationServerInput("http://127.42.7.9:8080")).toBe(
"http://127.42.7.9:8080",
);
expect(normalizeOrganizationServerInput("http://[::1]:3005")).toBe(
"http://[::1]:3005",
);
expect(normalizeOrganizationServerInput("http://omnirush.acme.com")).toBeNull();
expect(normalizeOrganizationServerInput("http://den.internal:8080")).toBeNull();
});
test("keeps https available for non-loopback hosts", () => {
expect(normalizeOrganizationServerInput("https://omnirush.acme.com")).toBe(
"https://omnirush.acme.com",
);
expect(normalizeOrganizationServerInput("https://den.internal:8080/path")).toBe(
"https://den.internal:8080",
);
});
test("rejects unsupported schemes, empty values, and malformed input", () => {
expect(normalizeOrganizationServerInput("ftp://omnirush.acme.com")).toBeNull();
expect(normalizeOrganizationServerInput("")).toBeNull();
expect(normalizeOrganizationServerInput("not a url at all")).toBeNull();
expect(normalizeOrganizationServerInput("https://")).toBeNull();
});
test("rejects URL-parser userinfo and backslash oddities", () => {
expect(normalizeOrganizationServerInput("https://[email protected]")).toBeNull();
expect(normalizeOrganizationServerInput("https://admin:[email protected]/path")).toBeNull();
expect(normalizeOrganizationServerInput("https:\\omnirush.acme.com\\dashboard")).toBeNull();
expect(normalizeOrganizationServerInput("omnirush.acme.com\\@attacker.example")).toBeNull();
});
});