Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

1.6 KB
Raw Blame
import { describe, expect, it, vi } from "vitest";
import { NextRequest } from "next/server";
import { createManagedAppCookie } from "../lib/managed-apps/session";
vi.hoisted(() => { process.env.NEXT_PUBLIC_MANAGED_APP_HOST_TEMPLATE = "{id}.mso.example.com"; });

const SECRET = "e".repeat(48);
const EPOCH = "epoch-0000000000000000";
vi.mock("@/lib/auth/device-store", () => ({
  currentSessionPolicy: async (scope: string) => ({ scope, epoch: EPOCH, changedAt: 1 }),
  getApprovedDevice: async () => ({ label: "owner", approvedAt: 1, role: "owner" }),
}));

async function loadProxy() {
  vi.resetModules();
  vi.stubEnv("OS_SESSION_SECRET", SECRET);
  vi.stubEnv("NEXT_PUBLIC_MANAGED_APP_HOST_TEMPLATE", "{id}.mso.example.com");
  vi.stubEnv("OPENCLAW_DASHBOARD_URL", "http://127.0.0.1:18789");
  return (await import("../lib/managed-apps/socket-policy")).socketPolicy;
}

function upgrade(cookieEpoch: string) {
  const now = Date.now();
  const token = createManagedAppCookie("openclaw", {
    issued_at: now, expires_at: now + 60_000, device_id: "dev-1",
    cookie_scope: "host", cookie_epoch: cookieEpoch,
  }, SECRET);
  return new NextRequest("https://openclaw.mso.example.com/chat", {
    headers: { host: "openclaw.mso.example.com", upgrade: "websocket", connection: "Upgrade", cookie: `__Host-mso-managed-app=${token}` },
  });
}

describe("proxy session policy epoch", () => {
  it("rejects a retained token from an older generation of the same scope", async () => {
    const proxy = await loadProxy();
    expect(await proxy(upgrade("epoch-9999999999999999"))).toBeNull();
    expect((await proxy(upgrade(EPOCH)))?.target).toBe("http://127.0.0.1:18789/chat");
  });
});