Skip to content

tool-cache downloadTool does not support relative redirects #2226

@tobil4sk

Description

@tobil4sk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions