Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : ORIX App Universe8 * File : tests/hosts.test.ts9 * Module : tests10 * Repository : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website : https://www.orixlab.dev12 * Created : 2026-11-2113 * Last Modified : 2026-11-2114 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { beforeAll, describe, expect, it } from "vitest";44import { NextRequest } from "next/server";4546/** The site answers on two hosts; canonical addresses point at one, the administration lives on the other. */47describe("two public hosts", () => {48 let proxy: (typeof import("@/proxy"))["proxy"];49 beforeAll(async () => {50 Object.assign(process.env, { APP_URL: "https://admin.orix.test", PUBLIC_URL: "https://www.brand.test" });51 proxy = (await import("@/proxy")).proxy;52 });53 const req = (url: string, host: string) => new NextRequest(url, { headers: { host } });5455 it("sends /admin on the alias host to the administration origin, path and query kept", () => {56 const res = proxy(req("https://www.brand.test/admin/enroll?token=abc", "www.brand.test"));57 expect(res.status).toBe(307);58 expect(res.headers.get("location")).toBe("https://admin.orix.test/admin/enroll?token=abc");59 });60 it("leaves /admin alone on the administration host", () => {61 expect(proxy(req("https://admin.orix.test/admin", "admin.orix.test")).headers.get("location")).toBeNull();62 });63 it("serves public pages on either host without redirecting", () => {64 for (const host of ["www.brand.test", "admin.orix.test"]) expect(proxy(req(`https://${host}/apps`, host)).headers.get("location")).toBeNull();65 });66 it("uses the public address for canonical links and keeps same-origin checks on the administration origin", async () => {67 const { abs } = await import("@/lib/seo");68 const { assertSameOrigin } = await import("@/lib/security/http");69 expect(abs("/apps/scan")).toBe("https://www.brand.test/apps/scan");70 expect(() => assertSameOrigin(new Request("https://admin.orix.test/api/admin/x", { method: "POST", headers: { origin: "https://admin.orix.test" } }))).not.toThrow();71 expect(() => assertSameOrigin(new Request("https://admin.orix.test/api/admin/x", { method: "POST", headers: { origin: "https://www.brand.test" } }))).toThrow();72 });73});74