Merge pull request #349 from AikidoSec/bug/ci-build-pre-release

Stop downloadAgent test from depending on live artifacts
This commit is contained in:
Reinier Criel 2026-03-25 14:06:56 -07:00 committed by GitHub
commit cc0f08dc03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,18 +2,18 @@ import { describe, it, after } from "node:test";
import assert from "node:assert";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { unlinkSync } from "node:fs";
import { unlinkSync, writeFileSync } from "node:fs";
import { createHash } from "node:crypto";
import {
DOWNLOAD_URLS,
downloadFile,
verifyChecksum,
} from "./downloadAgent.js";
describe("downloadAgent checksums", { timeout: 120_000 }, () => {
const downloadedFiles = [];
describe("downloadAgent", () => {
const tempFiles = [];
after(() => {
for (const file of downloadedFiles) {
for (const file of tempFiles) {
try {
unlinkSync(file);
} catch {
@ -24,22 +24,33 @@ describe("downloadAgent checksums", { timeout: 120_000 }, () => {
for (const [platform, architectures] of Object.entries(DOWNLOAD_URLS)) {
for (const [arch, { url, checksum }] of Object.entries(architectures)) {
it(`${platform}/${arch} checksum matches`, async () => {
const destPath = join(
tmpdir(),
`safe-chain-test-${platform}-${arch}-${Date.now()}`
it(`${platform}/${arch} has a valid download definition`, () => {
assert.match(
url,
/^https:\/\/github\.com\/AikidoSec\/safechain-internals\/releases\/download\/v\d+\.\d+\.\d+\/.+/,
);
downloadedFiles.push(destPath);
assert.match(checksum, /^sha256:[a-f0-9]{64}$/);
});
}
}
await downloadFile(url, destPath);
it("verifies checksum for a local file", async () => {
const destPath = join(tmpdir(), `safe-chain-test-${Date.now()}`);
tempFiles.push(destPath);
const isValid = await verifyChecksum(destPath, checksum);
assert.strictEqual(
isValid,
writeFileSync(destPath, "safe-chain-test");
const expectedHash = createHash("sha256")
.update("safe-chain-test")
.digest("hex");
assert.equal(
await verifyChecksum(destPath, `sha256:${expectedHash}`),
true,
`Checksum mismatch for ${platform}/${arch} (${url})`
);
assert.equal(
await verifyChecksum(destPath, `sha256:${"0".repeat(64)}`),
false,
);
});
}
}
});