Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

artifact.download does not follow 302 redirects #131

Open
jgitlin-p21 opened this issue May 29, 2020 · 2 comments
Open

artifact.download does not follow 302 redirects #131

jgitlin-p21 opened this issue May 29, 2020 · 2 comments
Labels
Status: Untriaged An issue that has yet to be triaged.

Comments

@jgitlin-p21
Copy link
Contributor

Version:

3.0.12

Environment:

Artifactory Cloud Pro X hosted by JFrog
ruby 2.7.0p0 under Linux

Scenario:

Using artifactory client gem to download artifacts from a JFrog Artifactory server. Some artifacts download_uri property points to a URI for which the Artifactory server responds with a 302 redirect. This means the response body is empty, and the download method produces a zero-byte file

Steps to Reproduce:

artifacts = artifactory_client.artifact_usage_search(some_search_criteria)
artifacts.each { |artifact| artifact.download "/tmp" }

Issue seen when using pry:

[8] pry(#<Artifactory::Cleaner::Controller>)> r = artifact.client.get(artifact.download_uri) { |chunk| puts "Got #{chunk.length} bytes of data" }
=> #<Net::HTTPFound 302 Found readbody=true>
[9] pry(#<Artifactory::Cleaner::Controller>)> r.inspect
=> "#<Net::HTTPFound 302 Found readbody=true>"
...
[18] pry(#<Net::HTTPFound>):1> @header
=> {"date"=>["Fri, 29 May 2020 17:36:24 GMT"],
 "transfer-encoding"=>["chunked"],
 "connection"=>["keep-alive"],
 "x-artifactory-id"=>["d9d08d7d33e1d33ef1c12c437ef8007d16529d49"],
 "x-artifactory-node-id"=>["pinnacle21-artifactory-primary-0"],
 "location"=>
  ["https://jfrog-prod-use1-shared-virginia-main.s3.amazonaws.com/aol-pinnacle21/filestore/66/66e5adda6c86317bbd3fa9ebdd2bb1397ff29013?response-content-disposition=attachment%3Bfilename%3D%22cinc-15.11.3-1.el8.x86_64.rpm%22&response-content-type=application%2Fx-rpm&OTHER_PARAMS_MASKED_FOR_SECURITY"],
 "strict-transport-security"=>["max-age=15724800; includeSubDomains"],
 "x-request-id"=>["..."]}

Expected Result:

/tmp has many RPM and other artifact files with the same content they had on the Artifactory server

Actual Result:

/tmp has many zero-byte files with the same filenames as the artifacts to be downloaded, but no data

@jgitlin-p21 jgitlin-p21 added the Status: Untriaged An issue that has yet to be triaged. label May 29, 2020
@jgitlin-p21
Copy link
Contributor Author

Checking the source, we should be following redirects...

          case response
          when Net::HTTPRedirection
            redirect = response["location"]
            request(verb, redirect, data, headers)

So this may be as simple as adding Net::HTTPFound to that case statement...

@jgitlin-p21
Copy link
Contributor Author

jgitlin-p21 commented May 29, 2020

I see the issue. That redirect handling code is only executed if a block is not given, so it either needs to handle cases where a block is give or artifact.download needs similar logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Untriaged An issue that has yet to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant