Merge pull request #12419 from chrisroberts/fix-local-box-add

Fix local box add with relative path on Windows
This commit is contained in:
Chris Roberts 2021-06-22 15:45:49 -07:00 committed by GitHub
commit eae6c1d022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -88,7 +88,7 @@ module VagrantPlugins
begin
u = URI.parse(url)
q = CGI.parse(u.query || "")
if q["access_token"]
if !q["access_token"].empty?
@logger.warn("Removing access token from URL parameter.")
q.delete("access_token")
if q.empty?
@ -96,14 +96,15 @@ module VagrantPlugins
else
u.query = URI.encode_www_form(q)
end
u.to_s
else
@logger.warn("Authentication token not found as GET parameter.")
url
end
u.to_s
rescue URI::Error
url
end
end
@logger.warn("Authentication token not added as GET parameter.")
end
@app.call(env)
end.freeze

View File

@ -48,6 +48,25 @@ describe VagrantPlugins::CloudCommand::AddAuthentication do
expect(env[:box_urls]).to eq(original)
end
context "when urls are set" do
it "does not modify urls" do
original = ["https://example.com/boxes/test.box",
"file://C:/my/box/path/local.box"]
env[:box_urls] = original.dup
subject.call(env)
expect(env[:box_urls]).to eq(original)
end
it "should remove access_token parameters when found" do
env[:box_urls] = ["https://example.com/boxes/test.box?access_token=TEST",
"file://C:/my/box/path/local.box"]
subject.call(env)
expect(env[:box_urls]).to eq([
"https://example.com/boxes/test.box",
"file://C:/my/box/path/local.box"])
end
end
context "with VAGRANT_SERVER_ACCESS_TOKEN_BY_URL set" do
before { stub_env("VAGRANT_SERVER_ACCESS_TOKEN_BY_URL" => "1") }