diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts index fbc4ed12f9..290700b9bb 100644 --- a/packages/tool-cache/__tests__/tool-cache.test.ts +++ b/packages/tool-cache/__tests__/tool-cache.test.ts @@ -347,6 +347,22 @@ describe('@actions/tool-cache', function() { await io.rmRF(tempDir) } }) + it.each(['pwsh', 'powershell'])( + 'unzip properly fails with bad path (%s)', + async powershellTool => { + const originalPath = process.env['PATH'] + try { + if (powershellTool === 'powershell' && IS_WINDOWS) { + //remove pwsh from PATH temporarily to test fallback case + process.env['PATH'] = removePWSHFromPath(process.env['PATH']) + } + + await expect(tc.extractZip('badPath')).rejects.toThrow() + } finally { + process.env['PATH'] = originalPath + } + } + ) } else if (IS_MAC) { it('extract .xar', async () => { const tempDir = path.join(tempPath, 'test-install.xar') @@ -579,13 +595,7 @@ describe('@actions/tool-cache', function() { if (powershellTool === 'powershell' && IS_WINDOWS) { //remove pwsh from PATH temporarily to test fallback case - const newPath = originalPath - ?.split(';') - .filter(segment => { - return !segment.startsWith(`C:\\Program Files\\PowerShell`) - }) - .join(';') - process.env['PATH'] = newPath + process.env['PATH'] = removePWSHFromPath(process.env['PATH']) } const extPath: string = await tc.extractZip(zipFile) @@ -865,3 +875,12 @@ function setGlobal(key: string, value: T | undefined): void { g[key] = value } } + +function removePWSHFromPath(path: string | undefined): string { + return (path || '') + .split(';') + .filter(segment => { + return !segment.startsWith(`C:\\Program Files\\PowerShell`) + }) + .join(';') +} diff --git a/source.zip b/source.zip new file mode 100644 index 0000000000..5e4697c64a Binary files /dev/null and b/source.zip differ