Ignore URLs which cannot be parsed in the authentication middleware

Fixes #9725
This commit is contained in:
Chris Roberts 2018-04-26 15:08:06 -07:00
parent a26d861ae6
commit 97f5822dee
2 changed files with 18 additions and 5 deletions

View File

@ -35,6 +35,7 @@ module VagrantPlugins
token = client.token
env[:box_urls].map! do |url|
begin
u = URI.parse(url)
if u.host != TARGET_HOST && REPLACEMENT_HOSTS.include?(u.host)
u.host = TARGET_HOST
@ -42,6 +43,9 @@ module VagrantPlugins
else
url
end
rescue URI::Error
url
end
end
server_uri = URI.parse(Vagrant.server_url.to_s)

View File

@ -125,6 +125,15 @@ describe VagrantPlugins::LoginCommand::AddAuthentication do
end
end
it "ignores urls that it cannot parse" do
bad_url = "this is not a valid url"
# Ensure the bad URL does cause an exception
expect{ URI.parse(bad_url) }.to raise_error URI::Error
env[:box_urls] = [bad_url]
subject.call(env)
expect(env[:box_urls].first).to eq(bad_url)
end
it "returns original urls when not modified" do
to_persist = "file:////path/to/box.box"
to_change = VagrantPlugins::LoginCommand::AddAuthentication::