mirror of
https://github.com/actions/setup-java.git
synced 2026-08-01 16:22:58 +00:00
Verify JDK downloads with vendor checksums (#1167)
* Verify JDK downloads with vendor checksums Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a800a031-600e-4d28-b23e-be309555d38d * Handle missing vendor checksum values Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a800a031-600e-4d28-b23e-be309555d38d * Preserve checksum error during cleanup failure Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a800a031-600e-4d28-b23e-be309555d38d * Validate checksum metadata value types Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a800a031-600e-4d28-b23e-be309555d38d * Clarify checksum documentation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a800a031-600e-4d28-b23e-be309555d38d * Expand vendor checksum verification Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a800a031-600e-4d28-b23e-be309555d38d * Accept SHA-256 or SHA-512 for JetBrains checksum sibling JetBrains publishes a single, generically-named ".checksum" sibling whose digest algorithm isn't disclosed by the filename. Older JBR 11 builds (e.g. jbrsdk_nomod-11_0_16-*-b2043.64.tar.gz) publish a SHA-256 digest there, while newer builds publish SHA-512. The JetBrains installer previously assumed SHA-512 unconditionally, so verification failed with "Malformed sha512 checksum metadata ... expected a 128-character hexadecimal digest" for those older builds, breaking the jetbrains 11 e2e job on macOS and Windows. fetchChecksum now accepts a list of candidate algorithms and infers the actual algorithm from the returned digest's length, preferring the strongest match. The JetBrains installer passes ['sha512', 'sha256']; all other callers are unaffected since they already pass a single, vendor-disclosed algorithm. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a800a031-600e-4d28-b23e-be309555d38d * Use SapMachine archive checksum files Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a800a031-600e-4d28-b23e-be309555d38d --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a800a031-600e-4d28-b23e-be309555d38d
This commit is contained in:
@@ -148,6 +148,27 @@ describe('getAvailableVersions', () => {
|
||||
});
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
let spyHttpClientGet: any;
|
||||
|
||||
const JETBRAINS_CHECKSUM = 'c'.repeat(128);
|
||||
|
||||
beforeEach(() => {
|
||||
// Every resolved release fetches `${url}.checksum` (sha512, GNU
|
||||
// `<hex> <filename>` format); stub it so tests never reach the real
|
||||
// network, except the dedicated 'version %s can be downloaded' test
|
||||
// below which intentionally exercises real HTTPS HEAD requests.
|
||||
spyHttpClientGet = jest
|
||||
.spyOn(HttpClient.prototype, 'get')
|
||||
.mockResolvedValue({
|
||||
message: {statusCode: 200},
|
||||
readBody: async () => `${JETBRAINS_CHECKSUM} jbrsdk.tar.gz\n`
|
||||
} as any);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it.each([
|
||||
['17', '17.0.11+1207.24'],
|
||||
['11.0', '11.0.16+2043.64'],
|
||||
@@ -231,4 +252,72 @@ describe('findPackageForDownload', () => {
|
||||
/No matching version found for SemVer */
|
||||
);
|
||||
});
|
||||
|
||||
it('fetches the authoritative sha512 checksum only for the resolved version', async () => {
|
||||
const distribution = new JetBrainsDistribution({
|
||||
version: '21',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
|
||||
const result = await distribution['findPackageForDownload']('21');
|
||||
|
||||
expect(result.checksum).toEqual({
|
||||
algorithm: 'sha512',
|
||||
value: JETBRAINS_CHECKSUM,
|
||||
source: `${result.url}.checksum`
|
||||
});
|
||||
// Only the single resolved/winning version's checksum is requested,
|
||||
// not one per candidate considered during version resolution.
|
||||
expect(spyHttpClientGet).toHaveBeenCalledWith(`${result.url}.checksum`);
|
||||
expect(spyHttpClientGet).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('parses only the first whitespace-delimited token from the GNU checksum payload', async () => {
|
||||
spyHttpClientGet.mockResolvedValue({
|
||||
message: {statusCode: 200},
|
||||
readBody: async () => `${JETBRAINS_CHECKSUM} jbrsdk-21.tar.gz\n`
|
||||
} as any);
|
||||
|
||||
const distribution = new JetBrainsDistribution({
|
||||
version: '21',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
|
||||
const result = await distribution['findPackageForDownload']('21');
|
||||
|
||||
expect(result.checksum?.value).toBe(JETBRAINS_CHECKSUM);
|
||||
});
|
||||
|
||||
it('falls back to a sha256 checksum for older JBR builds that only publish one', async () => {
|
||||
// Older JBR 11 builds (e.g. jbrsdk_nomod-11_0_16-*-b2043.64.tar.gz) publish
|
||||
// a SHA-256 digest at the generic `.checksum` sibling instead of SHA-512.
|
||||
const sha256Checksum = 'a'.repeat(64);
|
||||
spyHttpClientGet.mockResolvedValue({
|
||||
message: {statusCode: 200},
|
||||
readBody: async () =>
|
||||
`${sha256Checksum} jbrsdk_nomod-11_0_16-osx-x64-b2043.64.tar.gz\n`
|
||||
} as any);
|
||||
|
||||
const distribution = new JetBrainsDistribution({
|
||||
version: '21',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
|
||||
const result = await distribution['findPackageForDownload']('21');
|
||||
|
||||
expect(result.checksum).toEqual({
|
||||
algorithm: 'sha256',
|
||||
value: sha256Checksum,
|
||||
source: `${result.url}.checksum`
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user