mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Verify download links in a test
This commit is contained in:
parent
af4bbb10fc
commit
12caa6d1d4
2 changed files with 47 additions and 2 deletions
|
|
@ -5,7 +5,7 @@ import fetch from "make-fetch-happen";
|
||||||
|
|
||||||
const ULTIMATE_VERSION = "v0.2.2";
|
const ULTIMATE_VERSION = "v0.2.2";
|
||||||
|
|
||||||
const DOWNLOAD_URLS = {
|
export const DOWNLOAD_URLS = {
|
||||||
win32: {
|
win32: {
|
||||||
x64: {
|
x64: {
|
||||||
url: `https://github.com/AikidoSec/safechain-internals/releases/download/${ULTIMATE_VERSION}/SafeChainUltimate-windows-amd64.msi`,
|
url: `https://github.com/AikidoSec/safechain-internals/releases/download/${ULTIMATE_VERSION}/SafeChainUltimate-windows-amd64.msi`,
|
||||||
|
|
@ -87,7 +87,7 @@ export function getDownloadInfoForCurrentPlatform() {
|
||||||
* @param {string} expectedChecksum - Format: "algorithm:hash" (e.g., "sha256:abc123...")
|
* @param {string} expectedChecksum - Format: "algorithm:hash" (e.g., "sha256:abc123...")
|
||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
async function verifyChecksum(filePath, expectedChecksum) {
|
export async function verifyChecksum(filePath, expectedChecksum) {
|
||||||
const [algorithm, expected] = expectedChecksum.split(":");
|
const [algorithm, expected] = expectedChecksum.split(":");
|
||||||
|
|
||||||
const hash = createHash(algorithm);
|
const hash = createHash(algorithm);
|
||||||
|
|
|
||||||
45
packages/safe-chain/src/installation/downloadAgent.spec.js
Normal file
45
packages/safe-chain/src/installation/downloadAgent.spec.js
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
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 {
|
||||||
|
DOWNLOAD_URLS,
|
||||||
|
downloadFile,
|
||||||
|
verifyChecksum,
|
||||||
|
} from "./downloadAgent.js";
|
||||||
|
|
||||||
|
describe("downloadAgent checksums", { timeout: 120_000 }, () => {
|
||||||
|
const downloadedFiles = [];
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
for (const file of downloadedFiles) {
|
||||||
|
try {
|
||||||
|
unlinkSync(file);
|
||||||
|
} catch {
|
||||||
|
// ignore cleanup errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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()}`
|
||||||
|
);
|
||||||
|
downloadedFiles.push(destPath);
|
||||||
|
|
||||||
|
await downloadFile(url, destPath);
|
||||||
|
|
||||||
|
const isValid = await verifyChecksum(destPath, checksum);
|
||||||
|
assert.strictEqual(
|
||||||
|
isValid,
|
||||||
|
true,
|
||||||
|
`Checksum mismatch for ${platform}/${arch} (${url})`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue