mirror of
https://github.com/outline/outline.git
synced 2026-11-21 13:34:02 +03:00
* Initial plan * Add getExpectedOrigin helper to handle non-standard ports in passkeys Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Fix linting error in passkeys test Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Fix trailing whitespace in passkeys.ts Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Export getExpectedOrigin and test it directly Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
import type { APIContext } from "@server/types";
|
|
import { getExpectedOrigin } from "./passkeys";
|
|
|
|
describe("getExpectedOrigin", () => {
|
|
// Helper to mock APIContext for testing
|
|
const createMockContext = (options: {
|
|
protocol: string;
|
|
hostname: string;
|
|
host: string;
|
|
forwardedPort?: string;
|
|
}): APIContext => ({
|
|
protocol: options.protocol,
|
|
request: {
|
|
hostname: options.hostname,
|
|
host: options.host,
|
|
get: (header: string) => {
|
|
if (header === "X-Forwarded-Port" && options.forwardedPort) {
|
|
return options.forwardedPort;
|
|
}
|
|
return undefined;
|
|
},
|
|
} as unknown,
|
|
}) as unknown as APIContext;
|
|
|
|
it("should construct origin with non-standard HTTPS port from X-Forwarded-Port", () => {
|
|
const ctx = createMockContext({
|
|
protocol: "https",
|
|
hostname: "outline.example.com",
|
|
host: "outline.example.com", // Without port (from X-Forwarded-Host)
|
|
forwardedPort: "10081",
|
|
});
|
|
|
|
expect(getExpectedOrigin(ctx)).toBe("https://outline.example.com:10081");
|
|
});
|
|
|
|
it("should construct origin without port for standard HTTPS port (443)", () => {
|
|
const ctx = createMockContext({
|
|
protocol: "https",
|
|
hostname: "outline.example.com",
|
|
host: "outline.example.com",
|
|
forwardedPort: "443",
|
|
});
|
|
|
|
expect(getExpectedOrigin(ctx)).toBe("https://outline.example.com");
|
|
});
|
|
|
|
it("should construct origin without port for standard HTTP port (80)", () => {
|
|
const ctx = createMockContext({
|
|
protocol: "http",
|
|
hostname: "outline.example.com",
|
|
host: "outline.example.com",
|
|
forwardedPort: "80",
|
|
});
|
|
|
|
expect(getExpectedOrigin(ctx)).toBe("http://outline.example.com");
|
|
});
|
|
|
|
it("should use host with port when X-Forwarded-Port is not present", () => {
|
|
const ctx = createMockContext({
|
|
protocol: "https",
|
|
hostname: "outline.example.com",
|
|
host: "outline.example.com:8443",
|
|
});
|
|
|
|
expect(getExpectedOrigin(ctx)).toBe("https://outline.example.com:8443");
|
|
});
|
|
|
|
it("should construct origin without port when not in host and no X-Forwarded-Port", () => {
|
|
const ctx = createMockContext({
|
|
protocol: "https",
|
|
hostname: "outline.example.com",
|
|
host: "outline.example.com",
|
|
});
|
|
|
|
expect(getExpectedOrigin(ctx)).toBe("https://outline.example.com");
|
|
});
|
|
|
|
it("should handle HTTP with non-standard port", () => {
|
|
const ctx = createMockContext({
|
|
protocol: "http",
|
|
hostname: "outline.example.com",
|
|
host: "outline.example.com",
|
|
forwardedPort: "8080",
|
|
});
|
|
|
|
expect(getExpectedOrigin(ctx)).toBe("http://outline.example.com:8080");
|
|
});
|
|
});
|