Merge pull request #8636 from briancain/7118/master/handle-invalid-box-names
Handle box names that are URLs
This commit is contained in:
commit
d0f1f39fa6
|
@ -30,6 +30,12 @@ module Vagrant
|
||||||
def call(env)
|
def call(env)
|
||||||
@download_interrupted = false
|
@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|
|
url = Array(env[:box_url]).map do |u|
|
||||||
u = u.gsub("\\", "/")
|
u = u.gsub("\\", "/")
|
||||||
if Util::Platform.windows? && u =~ /^[a-z]:/i
|
if Util::Platform.windows? && u =~ /^[a-z]:/i
|
||||||
|
|
|
@ -22,6 +22,9 @@ en:
|
||||||
Successfully added box '%{name}' (v%{version}) for '%{provider}'!
|
Successfully added box '%{name}' (v%{version}) for '%{provider}'!
|
||||||
box_adding_direct: |-
|
box_adding_direct: |-
|
||||||
Box file was not detected as metadata. Adding it directly...
|
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: |-
|
box_downloading: |-
|
||||||
Downloading: %{url}
|
Downloading: %{url}
|
||||||
box_download_error: |-
|
box_download_error: |-
|
||||||
|
|
|
@ -280,6 +280,31 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
end
|
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
|
context "with URL containing credentials" do
|
||||||
let(:username){ "box-username" }
|
let(:username){ "box-username" }
|
||||||
let(:password){ "box-password" }
|
let(:password){ "box-password" }
|
||||||
|
|
Loading…
Reference in New Issue