|
| 1 | +import { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; |
| 2 | +import { Session } from "../../../../src/session.js"; |
| 3 | +import { describeAtlas, withProject } from "./atlasHelpers.js"; |
| 4 | + |
| 5 | +describeAtlas("ip access lists", (integration) => { |
| 6 | + withProject(integration, ({ getProjectId }) => { |
| 7 | + let ipInfo: { |
| 8 | + currentIpv4Address: string; |
| 9 | + }; |
| 10 | + |
| 11 | + beforeAll(async () => { |
| 12 | + const session: Session = integration.mcpServer().session; |
| 13 | + session.ensureAuthenticated(); |
| 14 | + ipInfo = await session.apiClient.getIpInfo(); |
| 15 | + }); |
| 16 | + |
| 17 | + afterAll(async () => { |
| 18 | + const session: Session = integration.mcpServer().session; |
| 19 | + session.ensureAuthenticated(); |
| 20 | + |
| 21 | + const projectId = getProjectId(); |
| 22 | + |
| 23 | + await session.apiClient.deleteProjectIpAccessList({ |
| 24 | + params: { |
| 25 | + path: { |
| 26 | + groupId: projectId, |
| 27 | + entryValue: ipInfo.currentIpv4Address, |
| 28 | + }, |
| 29 | + }, |
| 30 | + }); |
| 31 | + |
| 32 | + await session.apiClient.deleteProjectIpAccessList({ |
| 33 | + params: { |
| 34 | + path: { |
| 35 | + groupId: projectId, |
| 36 | + entryValue: "8.8.8.8", |
| 37 | + }, |
| 38 | + }, |
| 39 | + }); |
| 40 | + |
| 41 | + await session.apiClient.deleteProjectIpAccessList({ |
| 42 | + params: { |
| 43 | + path: { |
| 44 | + groupId: projectId, |
| 45 | + entryValue: "9.9.9.9/24", |
| 46 | + }, |
| 47 | + }, |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe("atlas-create-access-list", () => { |
| 52 | + it("should have correct metadata", async () => { |
| 53 | + const { tools } = await integration.mcpClient().listTools(); |
| 54 | + const createAccessList = tools.find((tool) => tool.name === "atlas-create-access-list")!; |
| 55 | + expect(createAccessList).toBeDefined(); |
| 56 | + expect(createAccessList.inputSchema.type).toBe("object"); |
| 57 | + expect(createAccessList.inputSchema.properties).toBeDefined(); |
| 58 | + expect(createAccessList.inputSchema.properties).toHaveProperty("projectId"); |
| 59 | + expect(createAccessList.inputSchema.properties).toHaveProperty("ipAddresses"); |
| 60 | + expect(createAccessList.inputSchema.properties).toHaveProperty("cidrBlocks"); |
| 61 | + expect(createAccessList.inputSchema.properties).toHaveProperty("currentIpAddress"); |
| 62 | + expect(createAccessList.inputSchema.properties).toHaveProperty("comment"); |
| 63 | + }); |
| 64 | + |
| 65 | + it("should create an access list", async () => { |
| 66 | + const projectId = getProjectId(); |
| 67 | + |
| 68 | + const response = (await integration.mcpClient().callTool({ |
| 69 | + name: "atlas-create-access-list", |
| 70 | + arguments: { |
| 71 | + projectId, |
| 72 | + ipAddresses: ["8.8.8.8"], |
| 73 | + cidrBlocks: ["9.9.9.9/24"], |
| 74 | + currentIpAddress: true, |
| 75 | + }, |
| 76 | + })) as CallToolResult; |
| 77 | + expect(response.content).toBeArray(); |
| 78 | + expect(response.content).toHaveLength(1); |
| 79 | + expect(response.content[0].text).toContain("IP/CIDR ranges added to access list"); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + describe("atlas-inspect-access-list", () => { |
| 84 | + it("should have correct metadata", async () => { |
| 85 | + const { tools } = await integration.mcpClient().listTools(); |
| 86 | + const inspectAccessList = tools.find((tool) => tool.name === "atlas-inspect-access-list")!; |
| 87 | + expect(inspectAccessList).toBeDefined(); |
| 88 | + expect(inspectAccessList.inputSchema.type).toBe("object"); |
| 89 | + expect(inspectAccessList.inputSchema.properties).toBeDefined(); |
| 90 | + expect(inspectAccessList.inputSchema.properties).toHaveProperty("projectId"); |
| 91 | + }); |
| 92 | + |
| 93 | + it("returns access list data", async () => { |
| 94 | + const projectId = getProjectId(); |
| 95 | + |
| 96 | + const response = (await integration |
| 97 | + .mcpClient() |
| 98 | + .callTool({ name: "atlas-inspect-access-list", arguments: { projectId } })) as CallToolResult; |
| 99 | + expect(response.content).toBeArray(); |
| 100 | + expect(response.content).toHaveLength(1); |
| 101 | + expect(response.content[0].text).toContain("8.8.8.8"); |
| 102 | + expect(response.content[0].text).toContain("9.9.9.9/24"); |
| 103 | + expect(response.content[0].text).toContain(ipInfo.currentIpv4Address); |
| 104 | + }); |
| 105 | + }); |
| 106 | + }); |
| 107 | +}); |
0 commit comments