Lines 15-55javascript
16 fs.rmSync(tmpRoot, { recursive: true, force: true });
18 it("walks a dir, scans manifests, and gates on critical", async () => {
19 fs.writeFileSync(path.join(tmpRoot, "Dockerfile"), "FROM vllm/vllm-openai\nENV OPENAI_API_KEY=sk-abcdEFGH1234567890ijklMNOP\nEXPOSE 8000\n");
20 fs.mkdirSync(path.join(tmpRoot, "k8s"));
21 fs.writeFileSync(path.join(tmpRoot, "k8s", "mlflow.yaml"), "kind: Deployment\nspec:\n containers:\n - name: mlflow\n ports:\n - containerPort: 5000\n");
22 // A non-IaC file that must be ignored by the walk.
23 fs.writeFileSync(path.join(tmpRoot, "README.md"), "0.0.0.0 mlflow vllm 8888");
24 const result = await executeIacScan({ targetAbs: tmpRoot, failOn: "critical", maxBytes: 1_000_000 });
25 expect(result.scannedFiles).toBe(2); // README.md skipped
26 const ruleIds = result.findings.map((f) => f.ruleId);
27 expect(ruleIds).toContain("iac-hardcoded-secret-openai");
28 expect(ruleIds).toContain("iac-exposed-ai-service-port");
29 expect(result.bySeverity.critical).toBeGreaterThanOrEqual(1);
30 expect(result.flagged).toBeGreaterThanOrEqual(1);
31 expect(result.exitCode).toBe(1);
33 it("excludes node_modules / .git from the walk", async () => {
34 fs.mkdirSync(path.join(tmpRoot, "node_modules", "pkg"), { recursive: true });
35 fs.writeFileSync(path.join(tmpRoot, "node_modules", "pkg", "Dockerfile"), "FROM x\nENV AWS_SECRET_ACCESS_KEY=AKIAABCDEFGHIJKLMNOP\n");
CriticalCritical Secret
Package contains a critical-looking secret pattern.
dist/commands/__tests__/iac-scan.test.jsView on unpkg · L35 CriticalSecret Pattern
AWS access key ID in dist/commands/__tests__/iac-scan.test.js
dist/commands/__tests__/iac-scan.test.jsView on unpkg · L35 36 const result = await executeIacScan({ targetAbs: tmpRoot, failOn: "high", maxBytes: 1_000_000 });
37 expect(result.scannedFiles).toBe(0);
38 expect(result.findings).toEqual([]);
39 expect(result.exitCode).toBe(0);
41 it("scans a single file passed directly (any extension)", async () => {
42 const p = path.join(tmpRoot, "my-deploy");
43 fs.writeFileSync(p, 'apiVersion: apps/v1\nkind: Deployment\nspec:\n ports:\n - containerPort: 8888\n');
44 const result = await executeIacScan({ targetAbs: p, failOn: "high", maxBytes: 1_000_000 });
45 expect(result.scannedFiles).toBe(1);
46 expect(result.findings.some((f) => f.ruleId === "iac-exposed-ai-service-port")).toBe(true);
48 it("clean repo gates pass (exit 0)", async () => {
49 fs.writeFileSync(path.join(tmpRoot, "Dockerfile"), 'FROM python:3.12-slim\nCMD ["uvicorn","app","--host","127.0.0.1"]\n');
50 const result = await executeIacScan({ targetAbs: tmpRoot, failOn: "low", maxBytes: 1_000_000 });
51 expect(result.findings).toEqual([]);
52 expect(result.exitCode).toBe(0);
55//# sourceMappingURL=iac-scan.test.js.map