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

Support authenticated HTTP URLs (fixes #851) #852

Merged
merged 2 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance to update this documentation with the example? I'd have to scrape the barrel of my web header knowledge to remember how to set this. Maybe something like this?

Suggested change
# an authorization header to set
# an authorization header to set, e.g. "Basic " + Base64.encode64("#{username}:#{password}")

# @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