core: Downloads with user/pass use curl -u flag [GH-3183]

This commit is contained in:
Mitchell Hashimoto 2014-03-13 08:53:18 -07:00
parent 012c28606f
commit 513efa6739
3 changed files with 43 additions and 4 deletions

View File

@ -21,6 +21,7 @@ BUG FIXES:
- 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
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]
- hosts/linux: Unusual sed delimiter to avoid conflicts. [GH-3167]
- providers/virtualbox: Make more internal interactions with VBoxManage

View File

@ -1,3 +1,5 @@
require "uri"
require "log4r"
require "vagrant/util/busy"
@ -18,12 +20,28 @@ module Vagrant
attr_reader :destination
def initialize(source, destination, options=nil)
options ||= {}
@logger = Log4r::Logger.new("vagrant::util::downloader")
@source = source.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
options ||= {}
@auth = options[:auth]
@ca_cert = options[:ca_cert]
@continue = options[:continue]
@headers = options[:headers]
@ -180,6 +198,7 @@ module Vagrant
options += ["--continue-at", "-"] if @continue
options << "--insecure" if @insecure
options << "--cert" << @client_cert if @client_cert
options << "-u" << @auth if @auth
if @headers
Array(@headers).each do |header|

View File

@ -22,7 +22,9 @@ describe Vagrant::Util::Downloader do
describe "#download!" do
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
@ -50,8 +52,25 @@ describe Vagrant::Util::Downloader do
end
end
context "with a UI" do
pending "tests for a UI"
context "with a username and password" do
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