tool-cache downloadTool does not support relative redirects
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
If tc.downloadTool is used with a url that returns a relative redirect then the function fails with the error: TypeError: Invalid URL as it attempts to parse the relative url as an absolute url.
To Reproduce
Steps to reproduce the behavior:
- Apply this patch with a test to check the behaviour:
diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts
index 4712ab5f..c4329275 100644
--- a/packages/tool-cache/__tests__/tool-cache.test.ts
+++ b/packages/tool-cache/__tests__/tool-cache.test.ts
@@ -111,6 +111,22 @@ describe('@actions/tool-cache', function () {
expect(fs.statSync(downPath).size).toBe(35)
})
+ it('downloads a 35 byte file after a relative redirect', async () => {
+ nock('http://example.com')
+ .persist()
+ .get('/relative-redirect')
+ .reply(303, undefined, {
+ location: 'bytes/35'
+ })
+
+ const downPath: string = await tc.downloadTool(
+ 'http://example.com/relative-redirect'
+ )
+
+ expect(fs.existsSync(downPath)).toBeTruthy()
+ expect(fs.statSync(downPath).size).toBe(35)
+ })
+
it('handles error from response message stream', async () => {
nock('http://example.com')
.persist()
- Run the repository tests and view the
TypeError: Invalid URLfailure.
Expected behavior
The relative location should be resolved with the current url as the base instead of as an absolute url.
Additional context
The support for relative redirects is missing in the @actions/http-client package.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with packages/tool-cache/tests/tool-cache.test.ts and add or run the provided relative-redirect case to reproduce the failure. Then trace the redirect handling in the @actions/http-client package; done means the test downloads the 35-byte file successfully and the repository tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100