diff --git a/plugins/commands/login/middleware/add_authentication.rb b/plugins/commands/login/middleware/add_authentication.rb index 6cd5bee07..060ecf544 100644 --- a/plugins/commands/login/middleware/add_authentication.rb +++ b/plugins/commands/login/middleware/add_authentication.rb @@ -13,6 +13,18 @@ module VagrantPlugins TARGET_HOST = "vagrantcloud.com".freeze CUSTOM_HOST_NOTIFY_WAIT = 5 + def self.custom_host_notified! + @_host_notify = true + end + + def self.custom_host_notified? + if defined?(@_host_notify) + @_host_notify + else + false + end + end + def initialize(app, env) @app = app LoginCommand::Plugin.init! @@ -33,16 +45,17 @@ module VagrantPlugins server_uri = URI.parse(Vagrant.server_url.to_s) if token && !server_uri.host.to_s.empty? - if server_uri.host != TARGET_HOST - env[:ui].warn(I18n.t("login_command.middleware.authentication.different_target", - custom_host: server_uri.host, known_host: TARGET_HOST) + "\n") - sleep CUSTOM_HOST_NOTIFY_WAIT - end - env[:box_urls].map! do |url| u = URI.parse(url) if u.host == server_uri.host + if server_uri.host != TARGET_HOST && !self.class.custom_host_notified? + env[:ui].warn(I18n.t("login_command.middleware.authentication.different_target", + custom_host: server_uri.host, known_host: TARGET_HOST) + "\n") + sleep CUSTOM_HOST_NOTIFY_WAIT + self.class.custom_host_notified! + end + q = CGI.parse(u.query || "") current = q["access_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 72a193b9d..07fc9fcfe 100644 --- a/test/unit/plugins/commands/login/middleware/add_authentication_test.rb +++ b/test/unit/plugins/commands/login/middleware/add_authentication_test.rb @@ -97,11 +97,13 @@ describe VagrantPlugins::LoginCommand::AddAuthentication do original = [ "http://google.com/box.box", "http://vagrantcloud.com/foo.box", - "http://example.com/bar.box" + "http://example.com/bar.box", + "http://example.com/foo.box" ] expected = original.dup - expected.last.replace(expected.last + "?access_token=#{token}") + expected[2] = expected[2] + "?access_token=#{token}" + expected[3] = expected[3] + "?access_token=#{token}" expect(subject).to receive(:sleep).once expect(ui).to receive(:warn).once