diff --git a/CHANGELOG.md b/CHANGELOG.md index ed10cf993..5bf914460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## 1.7.2 (unreleased) +BUG FIXES: + - core: private boxes still referencing vagrantcloud.com will have + their vagrant login access token properly appended. ## 1.7.1 (December 11, 2014) diff --git a/plugins/commands/login/middleware/add_authentication.rb b/plugins/commands/login/middleware/add_authentication.rb index bfb7dd46b..faaa3cfe7 100644 --- a/plugins/commands/login/middleware/add_authentication.rb +++ b/plugins/commands/login/middleware/add_authentication.rb @@ -18,7 +18,17 @@ module VagrantPlugins env[:box_urls].map! do |url| u = URI.parse(url) - if u.host == server_uri.host + replace = u.host == server_uri.host + if !replace + # We need this in here for the transition we made from + # Vagrant Cloud to Atlas. This preserves access tokens + # appending to both without leaking access tokens to + # unsavory URLs. + replace = u.host == "vagrantcloud.com" && + server_uri.host == "atlas.hashicorp.com" + end + + if replace u.query ||= "" u.query += "&" if u.query != "" u.query += "access_token=#{token}" diff --git a/test/unit/plugins/commands/login/middleware/add_authentication_test.rb b/test/unit/plugins/commands/login/middleware/add_authentication_test.rb index 826e5d46b..57bb66558 100644 --- a/test/unit/plugins/commands/login/middleware/add_authentication_test.rb +++ b/test/unit/plugins/commands/login/middleware/add_authentication_test.rb @@ -60,5 +60,28 @@ describe VagrantPlugins::LoginCommand::AddAuthentication do expect(env[:box_urls]).to eq(expected) end + + it "appends the access token to vagrantcloud.com URLs if Atlas" do + server_url = "https://atlas.hashicorp.com" + allow(Vagrant).to receive(:server_url).and_return(server_url) + + token = "foobarbaz" + VagrantPlugins::LoginCommand::Client.new(iso_env).store_token(token) + + original = [ + "http://google.com/box.box", + "http://vagrantcloud.com/foo.box", + "http://vagrantcloud.com/bar.box?arg=true", + ] + + expected = original.dup + expected[1] = "#{original[1]}?access_token=#{token}" + expected[2] = "#{original[2]}&access_token=#{token}" + + env[:box_urls] = original.dup + subject.call(env) + + expect(env[:box_urls]).to eq(expected) + end end end