|
| 1 | +import request from "supertest"; |
| 2 | +import { |
| 3 | + describeIf, |
| 4 | + idmux, |
| 5 | + Identity, |
| 6 | + TEST_API_URL, |
| 7 | + TEST_PRODUCTION, |
| 8 | +} from "../lib"; |
| 9 | +import { scrapeRaw } from "./lib"; |
| 10 | + |
| 11 | +// ========================================= |
| 12 | +// v0 + forced threat protection |
| 13 | +// |
| 14 | +// The deprecated v0 endpoints never resolve a threat protection policy, so |
| 15 | +// teams whose flag is "forced" must be rejected on the content-fetching v0 |
| 16 | +// endpoints (scrape, crawl, search) with 403. The rejection happens right |
| 17 | +// after auth — before any credit check or scraping — so no provider or |
| 18 | +// scrape target is needed. crawl-status/crawl-cancel intentionally stay |
| 19 | +// open so existing jobs can drain. |
| 20 | +// ========================================= |
| 21 | + |
| 22 | +async function crawlRaw(body: unknown, identity: Identity) { |
| 23 | + return await request(TEST_API_URL) |
| 24 | + .post("/v0/crawl") |
| 25 | + .set("Authorization", `Bearer ${identity.apiKey}`) |
| 26 | + .set("Content-Type", "application/json") |
| 27 | + .send(body as object); |
| 28 | +} |
| 29 | + |
| 30 | +async function searchRaw(body: unknown, identity: Identity) { |
| 31 | + return await request(TEST_API_URL) |
| 32 | + .post("/v0/search") |
| 33 | + .set("Authorization", `Bearer ${identity.apiKey}`) |
| 34 | + .set("Content-Type", "application/json") |
| 35 | + .send(body as object); |
| 36 | +} |
| 37 | + |
| 38 | +// Requires idmux-provisioned team flags, which only exist in the production |
| 39 | +// test configuration. |
| 40 | +describeIf(TEST_PRODUCTION)("V0 threat protection (forced flag)", () => { |
| 41 | + let identity: Identity; |
| 42 | + |
| 43 | + beforeAll(async () => { |
| 44 | + identity = await idmux({ |
| 45 | + name: "v0-threat-protection/forced", |
| 46 | + flags: { |
| 47 | + threatProtection: "forced", |
| 48 | + }, |
| 49 | + }); |
| 50 | + }, 10000); |
| 51 | + |
| 52 | + it.concurrent("rejects v0 scrape with 403", async () => { |
| 53 | + const res = await scrapeRaw({ url: "https://firecrawl.dev" }, identity); |
| 54 | + expect(res.statusCode).toBe(403); |
| 55 | + expect(res.body.error).toContain("Threat protection"); |
| 56 | + expect(res.body.error).toContain("v0"); |
| 57 | + }); |
| 58 | + |
| 59 | + it.concurrent("rejects v0 crawl with 403", async () => { |
| 60 | + const res = await crawlRaw({ url: "https://firecrawl.dev" }, identity); |
| 61 | + expect(res.statusCode).toBe(403); |
| 62 | + expect(res.body.error).toContain("Threat protection"); |
| 63 | + expect(res.body.error).toContain("v0"); |
| 64 | + }); |
| 65 | + |
| 66 | + it.concurrent("rejects v0 search with 403", async () => { |
| 67 | + const res = await searchRaw({ query: "firecrawl" }, identity); |
| 68 | + expect(res.statusCode).toBe(403); |
| 69 | + expect(res.body.error).toContain("Threat protection"); |
| 70 | + expect(res.body.error).toContain("v0"); |
| 71 | + }); |
| 72 | +}); |
0 commit comments