Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,12 +1,26 @@
import { describe, it, expect } from "vitest";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { afterEach, describe, it, expect } from "vitest";
import {
collectFiles,
formatFinding,
isKnownLocalCredential,
scanText,
isAllowlistedPath,
lineHasPlaceholder,
PATTERNS,
} from "./verify-secrets.mjs";
const temporaryDirectories = [];
afterEach(() => {
for (const directory of temporaryDirectories.splice(0)) {
fs.rmSync(directory, { recursive: true, force: true });
}
});
describe("verify-secrets pattern detection", () => {
it("detects a GitHub PAT in plain text", () => {
const sample = `const token = "ghp_AbCdEfGhIjKlMnOpQrStUv0123456789";`;
@@ -29,6 +43,39 @@ describe("verify-secrets pattern detection", () => {
expect(findings.some((f) => f.patternId === "gitlab-pat")).toBe(true);
});
it("detects common package, model-hosting, Google, and age credentials", () => {
const samples = [
["npm-access-token", "npm_abcdefghijklmnopqrstuvwxyz0123456789"],
["pypi-access-token", "pypi-abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGH"],
["huggingface-token", "hf_abcdefghijklmnopqrstuvwxyz0123456789"],
["google-api-key", "AIzaabcdefghijklmnopqrstuvwxyz123456789"],
["age-secret-key", "AGE-SECRET-KEY-1ABCDEFGHIJKLMNOPQRSTUVWXYZ"],
];
for (const [patternId, sample] of samples) {
expect(scanText(String(sample), { filename: "src/config.ts" }).some((finding) => finding.patternId === patternId)).toBe(true);
}
});
it("detects unquoted secret assignments and credentials embedded in URLs", () => {
const sample = [
"CLIENT_SECRET=abcdef0123456789abcdef0123456789",
"DATABASE_URL=postgresql://service:super-secret-password@db.internal/app",
].join("\n");
const findings = scanText(sample, { filename: "infra/app.env" });
expect(findings.some((finding) => finding.patternId === "generic-high-entropy-assignment")).toBe(true);
expect(findings.some((finding) => finding.patternId === "embedded-url-credentials")).toBe(true);
});
it("does not classify long source identifiers as unquoted secret values", () => {
const samples = [
"const token = existingPortalDomainVerificationTokenHash;",
"token: E2E_CUSTOMER_01_SECRET_IDENTIFIER,",
];
for (const sample of samples) {
expect(scanText(sample, { filename: "src/domain.ts" })).toHaveLength(0);
}
});
it("detects an AWS Access Key ID", () => {
const sample = `AKIAIOSFODNN7EXAMPLE2`;
const findings = scanText(sample, { filename: "apps/web/aws.ts" });
@@ -150,6 +197,12 @@ describe("verify-secrets allowlist semantics", () => {
expect(isAllowlistedPath("/repo/apps/web/stubs/foo.ts")).toBe(true);
});
it("does not allowlist incidental substrings that merely contain test words", () => {
expect(isAllowlistedPath("/repo/apps/web/attestation/source.ts")).toBe(false);
expect(isAllowlistedPath("/repo/apps/web/contest/source.ts")).toBe(false);
expect(isAllowlistedPath("/repo/apps/web/test/source.ts")).toBe(true);
});
it("does not allowlist arbitrary source files", () => {
expect(isAllowlistedPath("/repo/apps/web/routes/login.tsx")).toBe(false);
expect(isAllowlistedPath("/repo/packages/db/src/client.ts")).toBe(false);
@@ -164,14 +217,75 @@ describe("verify-secrets registry shape", () => {
"github-pat",
"github-fine-grained-pat",
"gitlab-pat",
"npm-access-token",
"pypi-access-token",
"huggingface-token",
"google-api-key",
"aws-access-key-id",
"payment-secret-live",
"payment-webhook-live",
"slack-bot-token",
"private-key-header",
"age-secret-key",
"jwt-like",
"generic-high-entropy-assignment",
"embedded-url-credentials",
]),
);
});
});
describe("verify-secrets tracked-file coverage", () => {
it("scans tracked hidden and infrastructure paths but not untracked files", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "hivegrid-secrets-"));
temporaryDirectories.push(root);
spawnSync("git", ["init", "-q"], { cwd: root });
for (const relativePath of [".gitea/workflows/ci.yml", "infra/app.env", "runtime/api/index.js"]) {
const absolutePath = path.join(root, relativePath);
fs.mkdirSync(path.dirname(absolutePath), { recursive: true });
fs.writeFileSync(absolutePath, "tracked");
}
fs.writeFileSync(path.join(root, "untracked.txt"), "not scanned");
spawnSync("git", ["add", ".gitea/workflows/ci.yml", "infra/app.env", "runtime/api/index.js"], { cwd: root });
const relativeFiles = collectFiles(root).map((file) => path.relative(root, file)).sort();
expect(relativeFiles).toEqual([".gitea/workflows/ci.yml", "infra/app.env", "runtime/api/index.js"]);
});
it("redacts matched values from scanner output", () => {
const secret = "ghp_AbCdEfGhIjKlMnOpQrStUv0123456789";
const output = formatFinding(
{ file: "/repo/app.ts", line: 1, patternId: "github-pat", match: secret },
"/repo",
);
expect(output).not.toContain(secret);
expect(output).toContain("redacted length=");
});
it("recognizes only the canonical loopback Postgres test credential", () => {
const finding = {
patternId: "embedded-url-credentials",
match: "postgresql://postgres:postgres@localhost:5432/hivegrid",
};
expect(isKnownLocalCredential(finding)).toBe(true);
expect(
isKnownLocalCredential({
...finding,
match: "postgresql://hivegrid:hivegrid@127.0.0.1:5432/hivegrid",
}),
).toBe(true);
expect(
isKnownLocalCredential({
...finding,
match: "postgresql://postgres:not-the-test-value@localhost:5432/hivegrid",
}),
).toBe(false);
expect(
isKnownLocalCredential({
...finding,
match: "postgresql://postgres:postgres@db.internal:5432/hivegrid",
}),
).toBe(false);
});
});