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.8 KB
Raw Blame
import { afterEach, describe, expect, it, vi } from "vitest";
vi.mock("server-only", () => ({}));
import { parseSystemctlServices, serviceControlAllowlist, validServiceUnit } from "./services";

afterEach(() => vi.unstubAllEnvs());

describe("systemd service inventory", () => {
  it("parses stable systemctl columns and marks only exact allowlist matches controllable", () => {
    const allow = new Set(["user:mso.service"]);
    const rows = parseSystemctlServices([
      "mso.service loaded active running Manef Shell OS",
      "[email protected] loaded failed failed Queue worker one",
      "not-a-unit.socket loaded active listening Socket",
    ].join("\n"), "user", allow);
    expect(rows).toEqual([
      {
        unit: "mso.service", scope: "user", load: "loaded", active: "active", sub: "running",
        description: "Manef Shell OS", controllable: true,
      },
      {
        unit: "[email protected]", scope: "user", load: "loaded", active: "failed", sub: "failed",
        description: "Queue worker one", controllable: false,
      },
    ]);
  });

  it("fails malformed allowlist entries closed instead of broadening control", () => {
    vi.stubEnv("OS_SERVICE_CONTROL_UNITS", "user:mso.service,system:nginx.service,*.service,user:../bad.service");
    const parsed = serviceControlAllowlist();
    expect([...parsed.units]).toEqual(["user:mso.service", "system:nginx.service"]);
    expect(parsed.diagnostics).toHaveLength(2);
  });

  it("accepts ordinary and template units but no spaces, slash, or flags", () => {
    expect(validServiceUnit("nginx.service")).toBe(true);
    expect(validServiceUnit("[email protected]")).toBe(true);
    for (const bad of ["../nginx.service", "nginx service", "nginx\\evil.service", "--help.service", "nginx.socket", ""]) {
      expect(validServiceUnit(bad)).toBe(false);
    }
  });
});