Merge pull request #6540 from mitchellh/b-non-http-head
core: don't do HEAD request for box on non-HTTP [GH-5477]
This commit is contained in:
commit
079ee6ea95
|
@ -491,6 +491,12 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# If this isn't HTTP, then don't do the HEAD request
|
||||
if !uri.scheme.downcase.start_with?("http")
|
||||
@logger.info("not checking metadata since box URI isn't HTTP")
|
||||
return false
|
||||
end
|
||||
|
||||
output = d.head
|
||||
match = output.scan(/^Content-Type: (.+?)$/i).last
|
||||
return false if !match
|
||||
|
|
|
@ -4,6 +4,8 @@ require "tempfile"
|
|||
require "tmpdir"
|
||||
require "webrick"
|
||||
|
||||
require "fake_ftp"
|
||||
|
||||
require File.expand_path("../../../../base", __FILE__)
|
||||
|
||||
require "vagrant/util/file_checksum"
|
||||
|
@ -34,6 +36,21 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
|||
FileChecksum.new(path, Digest::SHA1).checksum
|
||||
end
|
||||
|
||||
def with_ftp_server(path, **opts)
|
||||
path = Pathname.new(path)
|
||||
|
||||
tf = Tempfile.new("vagrant")
|
||||
tf.close
|
||||
|
||||
port = 21212
|
||||
server = FakeFtp::Server.new(port, port+1)
|
||||
server.add_file(path.basename, path.read)
|
||||
server.start
|
||||
yield port
|
||||
ensure
|
||||
server.stop rescue nil
|
||||
end
|
||||
|
||||
def with_web_server(path, **opts)
|
||||
tf = Tempfile.new("vagrant")
|
||||
tf.close
|
||||
|
@ -123,6 +140,26 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
|||
end
|
||||
end
|
||||
|
||||
it "adds from FTP URL" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
with_ftp_server(box_path) do |port|
|
||||
env[:box_name] = "foo"
|
||||
env[:box_url] = "ftp://127.0.0.1:#{port}/#{box_path.basename}"
|
||||
|
||||
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
|
||||
expect(checksum(path)).to eq(checksum(box_path))
|
||||
expect(name).to eq("foo")
|
||||
expect(version).to eq("0")
|
||||
expect(opts[:metadata_url]).to be_nil
|
||||
true
|
||||
}.and_return(box)
|
||||
|
||||
expect(app).to receive(:call).with(env)
|
||||
|
||||
subject.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises an error if no name is given" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
|
||||
|
|
Loading…
Reference in New Issue