| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { mcpRegistryAuth } from "../../src/http/mcp-registry-auth.js"; |
| 3 | |
| 4 | describe("mcp-registry-auth", () => { |
| 5 | const record = "v=MCPv1; k=ed25519; p=HbHhQYSP5tE1guSK2Df9MqxTJ8F+ojzjAesiFpgABTU="; |
| 6 | |
| 7 | it("serves the instance's own record, and nothing when it is missing or malformed", () => { |
| 8 | expect(mcpRegistryAuth({ PUBLIC_URL: "https://git.example.com", MCP_REGISTRY_AUTH: ` ${record} ` })).toBe(record); |
| 9 | expect(mcpRegistryAuth({ PUBLIC_URL: "https://git.example.com", MCP_REGISTRY_AUTH: "v=MCPv1; k=ecdsap384; p=AbC+/9==" })).toBe("v=MCPv1; k=ecdsap384; p=AbC+/9=="); |
| 10 | for (const MCP_REGISTRY_AUTH of [undefined, "", " ", "v=MCPv1; k=rsa; p=AAAA", "v=MCPv1; k=ed25519; p=", `${record}\nextra`, "<html>"]) { |
| 11 | expect(mcpRegistryAuth({ PUBLIC_URL: "https://git.example.com", MCP_REGISTRY_AUTH })).toBeNull(); |
| 12 | } |
| 13 | }); |
| 14 | |
| 15 | it("serves diffinery.com's built-in record only on diffinery.com", () => { |
| 16 | expect(mcpRegistryAuth({ PUBLIC_URL: "https://diffinery.com" })).toMatch(/^v=MCPv1; k=ed25519; p=[A-Za-z0-9+/]{43}=$/); |
| 17 | expect(mcpRegistryAuth({ PUBLIC_URL: "https://diffinery.com.evil.example" })).toBeNull(); |
| 18 | expect(mcpRegistryAuth({ PUBLIC_URL: "http://localhost:8787" })).toBeNull(); |
| 19 | }); |
| 20 | }); |