tool-cache downloadTool does not support relative redirects

Open Beginner friendly
#2,226 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
typescript
Domain
networking

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.

Description

bug

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:

  1. 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()
  1. Run the repository tests and view the TypeError: Invalid URL failure.

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.

Dominant language
TypeScript
Stars
5.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from actions/toolkit

All issues in actions/toolkit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.