feat: verify download against published SHA256SUMS by default (#121)

Signed-off-by: somaz <genius5711@gmail.com>
This commit is contained in:
somaz authored and GitHub committed 2026-06-26 12:42:14 -03:00
1 parent 56007213a1
commit d3dc77de53
7 files changed
+354 -13

No files matched your search

+38 -3
View File
@@ -39,6 +39,7 @@ jest.unstable_mockModule('@actions/tool-cache', () => ({
jest.unstable_mockModule('../releases.js', () => ({
getRelease: jest.fn(),
getDownloadChecksum: jest.fn(),
Release: jest.fn()
}));
@@ -50,7 +51,7 @@ jest.unstable_mockModule('../util.js', () => ({
const { getInput, warning, exportVariable, getMultilineInput } = await import('@actions/core');
const tc = await import('@actions/tool-cache');
const io = await import('@actions/io');
const { getRelease } = await import('../releases.js');
const { getRelease, getDownloadChecksum } = await import('../releases.js');
const { default: setup } = await import('../setup-tofu.js');
const { fileSHA256 } = await import('../util.js');
@@ -76,10 +77,17 @@ describe('setup-tofu', () => {
const mockRelease = {
version: '1.10.5',
getBuild: jest.fn().mockReturnValue({ url: 'mock-url' })
getBuild: jest.fn().mockReturnValue({
url: 'mock-url',
name: 'tofu_1.10.5_linux_amd64.zip'
})
};
getRelease.mockResolvedValue(mockRelease);
// Default to "no published checksum retrievable" so tests that don't
// exercise checksum behaviour keep skipping verification, as before.
getDownloadChecksum.mockResolvedValue(null);
// Write version file to temporary directory
tempDirPath = join(tmpdir(), 'setup-tofu-');
tempDir = await fs.mkdtemp(tempDirPath);
@@ -392,9 +400,13 @@ describe('setup-tofu', () => {
await setup();
expect(fileSHA256).toHaveBeenCalled();
// An explicit checksums input wins; the published SHA256SUMS is not fetched.
expect(getDownloadChecksum).not.toHaveBeenCalled();
});
it('should not validate checksum when no checksums are provided', async () => {
it('should validate against the published SHA256SUMS when no checksums input is provided', async () => {
fileSHA256.mockResolvedValue(mockChecksum);
getDownloadChecksum.mockResolvedValue(mockChecksum);
getMultilineInput.mockImplementation((name) => {
const defaults = {
checksums: []
@@ -405,7 +417,30 @@ describe('setup-tofu', () => {
await setup();
expect(getDownloadChecksum).toHaveBeenCalledWith(
'1.10.5',
'tofu_1.10.5_linux_amd64.zip'
);
expect(fileSHA256).toHaveBeenCalled();
});
it('should skip verification when no published checksum can be retrieved', async () => {
getDownloadChecksum.mockResolvedValue(null);
getMultilineInput.mockImplementation((name) => {
const defaults = {
checksums: []
};
return defaults[name] ?? [];
});
await setup();
expect(getDownloadChecksum).toHaveBeenCalled();
expect(fileSHA256).not.toHaveBeenCalled();
expect(warning).toHaveBeenCalledWith(
expect.stringContaining('Proceeding without checksum verification')
);
});
it('should throw error when checksum validation fails', async () => {