Merge pull request #8636 from briancain/7118/master/handle-invalid-box-names

Handle box names that are URLs
This commit is contained in:
Brian Cain 2017-05-31 16:16:38 -07:00 committed by GitHub
commit d0f1f39fa6
3 changed files with 34 additions and 0 deletions

View File

@ -30,6 +30,12 @@ module Vagrant
def call(env)
@download_interrupted = false
unless env[:box_name].nil?
if URI.parse(env[:box_name]).kind_of?(URI::HTTP)
env[:ui].warn(I18n.t("vagrant.box_add_url_warn"))
end
end
url = Array(env[:box_url]).map do |u|
u = u.gsub("\\", "/")
if Util::Platform.windows? && u =~ /^[a-z]:/i

View File

@ -22,6 +22,9 @@ en:
Successfully added box '%{name}' (v%{version}) for '%{provider}'!
box_adding_direct: |-
Box file was not detected as metadata. Adding it directly...
box_add_url_warn: |-
It looks like you attempted to add a box with a URL for the name...
Instead, use box_url instead of box for box URLs.
box_downloading: |-
Downloading: %{url}
box_download_error: |-

View File

@ -280,6 +280,31 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
subject.call(env)
end
context "with a box name accidentally set as a URL" do
it "displays a warning to the user" do
box_path = iso_env.box2_file(:virtualbox)
with_web_server(box_path) do |port|
box_url_name = "http://127.0.0.1:#{port}/#{box_path.basename}"
env[:box_name] = box_url_name
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(name).to eq(box_url_name)
expect(version).to eq("0")
expect(opts[:metadata_url]).to be_nil
true
}.and_return(box)
expect(app).to receive(:call).with(env)
expect(env[:ui]).to receive(:warn)
.with(/It looks like you attempted to add a box with a URL for the name/)
subject.call(env)
end
end
end
context "with URL containing credentials" do
let(:username){ "box-username" }
let(:password){ "box-password" }