Skip to content

Commit

Permalink
Merge pull request #852 from LeeXGreen/netfetcher_http_authorization
Browse files Browse the repository at this point in the history
Support authenticated HTTP URLs (fixes #851)
  • Loading branch information
lamont-granquist authored Apr 16, 2019
2 parents 7b03186 + 6bf8a0f commit b9f8e54
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/omnibus/fetchers/net_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def download

# Set the cookie if one was given
options["Cookie"] = source[:cookie] if source[:cookie]
options["Authorization"] = source[:authorization] if source[:authorization]

download_file!(download_url, downloaded_file, options)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/omnibus/software.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def dependency(val)
#
# @option val [String] :cookie (nil)
# a cookie to set
# @option val [String] :authorization (nil)
# an authorization header to set
# @option val [String] :warning (nil)
# a warning message to print when downloading
# @option val [Symbol] :extract (nil)
Expand Down Expand Up @@ -294,7 +296,7 @@ def source(val = NULL)
extra_keys = val.keys - [
:git, :file, :path, :url, # fetcher types
:md5, :sha1, :sha256, :sha512, # hash type - common to all fetchers
:cookie, :warning, :unsafe, :extract, :cached_name, # used by net_fetcher
:cookie, :warning, :unsafe, :extract, :cached_name, :authorization, # used by net_fetcher
:options, # used by path_fetcher
:submodules # used by git_fetcher
]
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/fetchers/net_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,34 @@ module Omnibus

subject { described_class.new(manifest_entry, project_dir, build_dir) }

describe "authorization" do
context "when none passed" do
it "does not get passed" do
expect(subject).to receive(:download_file!) do |url_arg, path_arg, options_arg|
expect(options_arg).to_not have_key("Authorization")
end

subject.send(:download)
end
end

context "when passed" do
let(:auth_header) { "a fake auth header" }
let(:source) do
{ url: "https://get.example.com/file.tar.gz", md5: "abcd1234", authorization: auth_header }
end

it "does get passed" do
expect(subject).to receive(:download_file!) do |url_arg, path_arg, options_arg|
expect(options_arg).to have_key("Authorization")
expect(options_arg["Authorization"]).to eq(auth_header)
end

subject.send(:download)
end
end
end

describe "#fetch_required?" do
context "when file is not downloaded" do
before { allow(File).to receive(:exist?).and_return(false) }
Expand Down

0 comments on commit b9f8e54

Please sign in to comment.