core: Downloads with user/pass use curl -u flag [GH-3183]
This commit is contained in:
parent
012c28606f
commit
513efa6739
|
@ -21,6 +21,7 @@ BUG FIXES:
|
||||||
- core: If you add a box path that doesn't exist, error earlier. [GH-3091]
|
- core: If you add a box path that doesn't exist, error earlier. [GH-3091]
|
||||||
- core: Validation on forwarded ports to make sure they're between
|
- core: Validation on forwarded ports to make sure they're between
|
||||||
0 and 65535. [GH-3187]
|
0 and 65535. [GH-3187]
|
||||||
|
- core: Downloads with user/password use the curl `-u` flag. [GH-3183]
|
||||||
- guests/darwin: Fix an exception when configuring networks. [GH-3143]
|
- guests/darwin: Fix an exception when configuring networks. [GH-3143]
|
||||||
- hosts/linux: Unusual sed delimiter to avoid conflicts. [GH-3167]
|
- hosts/linux: Unusual sed delimiter to avoid conflicts. [GH-3167]
|
||||||
- providers/virtualbox: Make more internal interactions with VBoxManage
|
- providers/virtualbox: Make more internal interactions with VBoxManage
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require "uri"
|
||||||
|
|
||||||
require "log4r"
|
require "log4r"
|
||||||
|
|
||||||
require "vagrant/util/busy"
|
require "vagrant/util/busy"
|
||||||
|
@ -18,12 +20,28 @@ module Vagrant
|
||||||
attr_reader :destination
|
attr_reader :destination
|
||||||
|
|
||||||
def initialize(source, destination, options=nil)
|
def initialize(source, destination, options=nil)
|
||||||
|
options ||= {}
|
||||||
|
|
||||||
@logger = Log4r::Logger.new("vagrant::util::downloader")
|
@logger = Log4r::Logger.new("vagrant::util::downloader")
|
||||||
@source = source.to_s
|
@source = source.to_s
|
||||||
@destination = destination.to_s
|
@destination = destination.to_s
|
||||||
|
|
||||||
|
begin
|
||||||
|
url = URI.parse(@source)
|
||||||
|
if url.scheme && url.scheme.start_with?("http") && url.user
|
||||||
|
auth = "#{url.user}"
|
||||||
|
auth += ":#{url.password}" if url.password
|
||||||
|
url.user = nil
|
||||||
|
url.password = nil
|
||||||
|
options[:auth] ||= auth
|
||||||
|
@source = url.to_s
|
||||||
|
end
|
||||||
|
rescue URI::InvalidURIError
|
||||||
|
# Ignore, since its clearly not HTTP
|
||||||
|
end
|
||||||
|
|
||||||
# Get the various optional values
|
# Get the various optional values
|
||||||
options ||= {}
|
@auth = options[:auth]
|
||||||
@ca_cert = options[:ca_cert]
|
@ca_cert = options[:ca_cert]
|
||||||
@continue = options[:continue]
|
@continue = options[:continue]
|
||||||
@headers = options[:headers]
|
@headers = options[:headers]
|
||||||
|
@ -180,6 +198,7 @@ module Vagrant
|
||||||
options += ["--continue-at", "-"] if @continue
|
options += ["--continue-at", "-"] if @continue
|
||||||
options << "--insecure" if @insecure
|
options << "--insecure" if @insecure
|
||||||
options << "--cert" << @client_cert if @client_cert
|
options << "--cert" << @client_cert if @client_cert
|
||||||
|
options << "-u" << @auth if @auth
|
||||||
|
|
||||||
if @headers
|
if @headers
|
||||||
Array(@headers).each do |header|
|
Array(@headers).each do |header|
|
||||||
|
|
|
@ -22,7 +22,9 @@ describe Vagrant::Util::Downloader do
|
||||||
|
|
||||||
describe "#download!" do
|
describe "#download!" do
|
||||||
let(:curl_options) {
|
let(:curl_options) {
|
||||||
["--fail", "--location", "--max-redirs", "10", "--user-agent", described_class::USER_AGENT, "--output", destination, source, {}]
|
["--fail", "--location", "--max-redirs", "10",
|
||||||
|
"--user-agent", described_class::USER_AGENT,
|
||||||
|
"--output", destination, source, {}]
|
||||||
}
|
}
|
||||||
|
|
||||||
context "with a good exit status" do
|
context "with a good exit status" do
|
||||||
|
@ -50,8 +52,25 @@ describe Vagrant::Util::Downloader do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with a UI" do
|
context "with a username and password" do
|
||||||
pending "tests for a UI"
|
it "downloads the file with the proper flags" do
|
||||||
|
original_source = source
|
||||||
|
source = "http://foo:bar@baz.com/box.box"
|
||||||
|
subject = described_class.new(source, destination)
|
||||||
|
|
||||||
|
i = curl_options.index(original_source)
|
||||||
|
curl_options[i] = "http://baz.com/box.box"
|
||||||
|
|
||||||
|
i = curl_options.index("--output")
|
||||||
|
curl_options.insert(i, "foo:bar")
|
||||||
|
curl_options.insert(i, "-u")
|
||||||
|
|
||||||
|
Vagrant::Util::Subprocess.should_receive(:execute).
|
||||||
|
with("curl", *curl_options).
|
||||||
|
and_return(subprocess_result)
|
||||||
|
|
||||||
|
expect(subject.download!).to be_true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue