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.

2.9 KB
Raw Blame
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { promises as fs } from "node:fs";
import os from "node:os";
import path from "node:path";
const PAT="pat_synthetic_12345678901234567890",KEY="prod:happy-otter-123|synthetic_deploy_key_1234567890";
let root:string;
beforeEach(async()=>{root=await fs.mkdtemp(path.join(os.tmpdir(),"mso-convex-env-"));process.env.OS_INFRA_STORE=path.join(root,"infra.json");vi.resetModules();});
afterEach(async()=>{delete process.env.OS_INFRA_STORE;await fs.rm(root,{recursive:true,force:true});vi.resetModules();});
async function seeded(){const {integrationManage}=await import("./connection-manage");await integrationManage({action:"user.create",user:"alice",confirm:true});await integrationManage({action:"connection.create",user:"alice",provider:"convex-cloud",connection:"admin",authMethod:"personal",source:"direct",confirm:true});const {withIntegrationSelection}=await import("./connection-service"),{setInfraProvider}=await import("./store");await withIntegrationSelection({user:"alice",connection:"admin"},()=>setInfraProvider("convex-cloud",{personalToken:PAT}));return withIntegrationSelection;}
const json=(body:unknown,status=200)=>new Response(JSON.stringify(body),{status,headers:{"content-type":"application/json"}});
it("returns only requested presence booleans and always deletes the view-only key",async()=>{const withSelection=await seeded();let deleted=false;const fetchImpl=vi.fn(async(input:RequestInfo|URL,init?:RequestInit)=>{const url=String(input);if(url.endsWith("/create_deploy_key")){expect(JSON.parse(String(init?.body))).toMatchObject({allowedActions:["deployment:env:view"]});return json({deployKey:KEY});}if(url.endsWith("/list_environment_variables")){expect(new Headers(init?.headers).get("authorization")).toBe(`Convex ${KEY}`);return json({environmentVariables:{AUTH_GOOGLE_ID:"client-id-secret-value",OTHER_SECRET:"top-secret"}});}if(url.endsWith("/delete_deploy_key")){deleted=true;return json({});}return json({error:"unexpected"},500);});const {getConvexEnvPresence}=await import("./convex-env-presence");const result=await withSelection({user:"alice",connection:"admin"},()=>getConvexEnvPresence({deploymentName:"happy-otter-123",names:["AUTH_GOOGLE_ID","AUTH_GOOGLE_SECRET"]},fetchImpl));expect(result).toEqual({deploymentName:"happy-otter-123",presence:{AUTH_GOOGLE_ID:true,AUTH_GOOGLE_SECRET:false}});expect(JSON.stringify(result)).not.toContain("client-id-secret-value");expect(JSON.stringify(result)).not.toContain("OTHER_SECRET");expect(deleted).toBe(true);});
it("refuses broad or malformed name requests",async()=>{const {getConvexEnvPresence}=await import("./convex-env-presence");await expect(getConvexEnvPresence({deploymentName:"happy-otter-123",names:[]})).rejects.toMatchObject({code:"invalid_convex_env_names"});await expect(getConvexEnvPresence({deploymentName:"happy-otter-123",names:["BAD-NAME"]})).rejects.toMatchObject({code:"invalid_convex_env_names"});});