Skip to content

Commit 549138e

Browse files
committed
fix: randomize ips and CIDR blocks
1 parent bd0f84f commit 549138e

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

tests/integration/tools/atlas/accessLists.test.ts

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@ import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
22
import { Session } from "../../../../src/session.js";
33
import { describeAtlas, withProject } from "./atlasHelpers.js";
44

5+
function generateRandomIp() {
6+
const randomIp: number[] = [192];
7+
for (let i = 0; i < 3; i++) {
8+
randomIp.push(Math.floor(Math.random() * 256));
9+
}
10+
return randomIp.join(".");
11+
}
12+
513
describeAtlas("ip access lists", (integration) => {
614
withProject(integration, ({ getProjectId }) => {
7-
let ipInfo: {
8-
currentIpv4Address: string;
9-
};
15+
const ips = [generateRandomIp(), generateRandomIp()]
16+
const cidrBlocks = [generateRandomIp() + "/16", generateRandomIp() + "/24"];
17+
const values = [...ips, ...cidrBlocks];
1018

1119
beforeAll(async () => {
1220
const session: Session = integration.mcpServer().session;
1321
session.ensureAuthenticated();
14-
ipInfo = await session.apiClient.getIpInfo();
22+
const ipInfo = await session.apiClient.getIpInfo();
23+
values.push(ipInfo.currentIpv4Address);
1524
});
1625

1726
afterAll(async () => {
@@ -20,32 +29,16 @@ describeAtlas("ip access lists", (integration) => {
2029

2130
const projectId = getProjectId();
2231

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",
32+
for (const value of values) {
33+
await session.apiClient.deleteProjectIpAccessList({
34+
params: {
35+
path: {
36+
groupId: projectId,
37+
entryValue: value,
38+
},
3739
},
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-
});
40+
});
41+
}
4942
});
5043

5144
describe("atlas-create-access-list", () => {
@@ -69,8 +62,8 @@ describeAtlas("ip access lists", (integration) => {
6962
name: "atlas-create-access-list",
7063
arguments: {
7164
projectId,
72-
ipAddresses: ["8.8.8.8"],
73-
cidrBlocks: ["9.9.9.9/24"],
65+
ipAddresses: ips,
66+
cidrBlocks: cidrBlocks,
7467
currentIpAddress: true,
7568
},
7669
})) as CallToolResult;
@@ -98,9 +91,9 @@ describeAtlas("ip access lists", (integration) => {
9891
.callTool({ name: "atlas-inspect-access-list", arguments: { projectId } })) as CallToolResult;
9992
expect(response.content).toBeArray();
10093
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);
94+
for (const value of values) {
95+
expect(response.content[0].text).toContain(value);
96+
}
10497
});
10598
});
10699
});

0 commit comments

Comments
 (0)