mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
1f097b0fdd
* chore: resolve no-explicit-any lint warnings in plugins Replaces uses of `any` in the plugins directory with concrete types, `unknown`, or structured type assertions, addressing the remaining typescript-eslint(no-explicit-any) warnings flagged by oxlint. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * chore: address review feedback in GitLabIssueProvider Drop trailing semicolon from log string and add early return in `destroyNamespace` when neither `user_id` nor `full_path` is present to avoid an unnecessary full-scan transaction. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
90 lines
2.6 KiB
TypeScript
90 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");
|
|
});
|
|
});
|