mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
test: simplify network restrictions test
- Reduce to one allowed and one blocked domain - Remove slow google.com test - Fix TypeScript errors with AbortController - Match test formatting conventions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,47 +1,44 @@
|
|||||||
import { describe, it, expect } from "bun:test";
|
import { describe, test, expect } from "bun:test";
|
||||||
|
|
||||||
describe("Network Restrictions", () => {
|
describe("Network Restrictions", () => {
|
||||||
it("should block access to unauthorized domains", async () => {
|
test("should block access to unauthorized domains", async () => {
|
||||||
const unauthorizedUrls = [
|
const url = "https://example.com/api/data";
|
||||||
"https://example.com/api/data",
|
|
||||||
"https://jsonplaceholder.typicode.com/posts",
|
|
||||||
"https://httpbin.org/get",
|
|
||||||
"https://pastebin.com/raw/example123",
|
|
||||||
"https://google.com",
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const url of unauthorizedUrls) {
|
|
||||||
try {
|
try {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
timeout: 5000,
|
signal: controller.signal,
|
||||||
agent: undefined,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
clearTimeout(timeoutId);
|
||||||
expect(response.ok).toBe(false);
|
expect(response.ok).toBe(false);
|
||||||
throw new Error(`Unauthorized domain ${url} was not blocked by proxy`);
|
throw new Error(`Unauthorized domain ${url} was not blocked by proxy`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
expect(error).toBeDefined();
|
expect(error).toBeDefined();
|
||||||
console.log(`Successfully blocked: ${url}`);
|
console.log(`Successfully blocked: ${url}`);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow access to whitelisted domains", async () => {
|
test("should allow access to whitelisted domains", async () => {
|
||||||
const allowedUrls = [
|
const url = "https://api.github.com/zen";
|
||||||
"https://api.github.com/zen",
|
|
||||||
"https://registry.npmjs.org/-/ping",
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const url of allowedUrls) {
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, { timeout: 5000 });
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||||
|
|
||||||
|
const response = await fetch(url, {
|
||||||
|
signal: controller.signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
clearTimeout(timeoutId);
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
console.log(`Successfully allowed: ${url}`);
|
console.log(`Successfully allowed: ${url}`);
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Whitelisted domain ${url} was blocked: ${error.message}`,
|
`Whitelisted domain ${url} was blocked: ${error.message}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user