From 495c529f84515cd04a844496542564b9ca9785f7 Mon Sep 17 00:00:00 2001 From: Luke Tomlinson Date: Thu, 13 May 2021 17:45:45 -0400 Subject: [PATCH] Add Test for failing case for both pwsh and powershell --- .../tool-cache/__tests__/tool-cache.test.ts | 33 ++++++++++++++---- source.zip | Bin 0 -> 164 bytes 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 source.zip 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 0000000000000000000000000000000000000000..5e4697c64a88a8708afc02807acfe68c704d6e71 GIT binary patch literal 164 zcmWIWW@h1H0D)WGYlFZHD8bGk!%&=GT9lls9~#2Rz}z!yZUP9GR&X;gvV3J^U|vWRhdXWrPIOFad_Qjvyx7Kvsx>7>2R3fs`=tO%@PA?i+ literal 0 HcmV?d00001