Files
setup-uv/__tests__/download/checksum/checksum.test.ts
T
William Woodruff de938e707d Add the require-checksums input (#1139)
Adds `require-checksums`, which enforces the "intrinsic or explicitly
provided checksum" idea. See #1032.

<details>
<summary>Automated notes</summary>

Add the opt-in input `require-checksums`. When enabled, setup-uv
verifies the archive against the workflow's `checksum` input or the
digest bundled for the resolved uv version, architecture, and platform.
If neither is available, setup fails before downloading the archive. By
default, setup-uv continues to accept manifest checksums as it does
today.

The setting also applies to custom manifests, which can still supply
download URLs. On persistent runners, strict mode keys tool-cache
entries by the expected archive digest so a previous manifest-verified
installation cannot bypass the check.

Closes #1032. Builds on #1033.

## Validation

- `npm ci --ignore-scripts` and `npm run all` passed under Node 24 (182
tests).
- The packaged-action regression test installs a custom build into a
temporary runner tool cache. It checks that strict mode rejects a
manifest-only version even with a warm cache, reuses a verified
installation for the same digest, and rejects a changed digest or a
custom build that conflicts with the bundled digest.

</details>

---------

Signed-off-by: William Woodruff <william@yossarian.net>
2026-11-16 22:24:53 +01:00

89 lines
1.9 KiB
TypeScript

import { expect, it, test } from "@jest/globals";
import {
isknownVersion,
validateChecksum,
} from "../../../src/download/checksum/checksum";
const validChecksum =
"f3da96ec7e995debee7f5d52ecd034dfb7074309a1da42f76429ecb814d813a3";
const filePath = "__tests__/fixtures/checksumfile";
test("checksum should match", async () => {
// string params don't matter only test the checksum mechanism, not known checksums
await validateChecksum(
validChecksum,
filePath,
"aarch64",
"pc-windows-msvc",
"1.2.3",
);
});
test("provided checksum beats known checksums", async () => {
await validateChecksum(
validChecksum,
filePath,
"x86_64",
"unknown-linux-gnu",
"0.3.0",
"incorrect-manifest-checksum",
);
});
test("known checksums beat manifest checksums", async () => {
await expect(
validateChecksum(
undefined,
filePath,
"x86_64",
"unknown-linux-gnu",
"0.3.0",
validChecksum,
),
).rejects.toThrow("did not match");
});
test("manifest checksums are used when no known checksum exists", async () => {
await expect(
validateChecksum(
undefined,
filePath,
"aarch64",
"pc-windows-msvc",
"1.2.3",
"incorrect-manifest-checksum",
),
).rejects.toThrow("did not match");
});
test.each(["", undefined])("rejects missing checksums (%s)", async (hash) => {
await expect(
validateChecksum(
undefined,
filePath,
"aarch64",
"pc-windows-msvc",
"1.2.3",
hash,
),
).rejects.toThrow("No checksum found");
});
type KnownVersionFixture = { version: string; known: boolean };
it.each<KnownVersionFixture>([
{
known: true,
version: "0.3.0",
},
{
known: false,
version: "0.0.15",
},
])(
"isknownVersion should return $known for version $version",
({ version, known }) => {
expect(isknownVersion(version)).toBe(known);
},
);