From 78e8e1786907cdc146f38a112738b7dddaa1a5ca Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 6 Mar 2017 09:14:04 -0800 Subject: [PATCH] Cast host value to string prior to empty? check. Force string type prior to empty? check to prevent errors if host ip value is nil. Add coverage for proper handling of nil value. --- plugins/communicators/winrm/helper.rb | 2 +- test/unit/plugins/communicators/winrm/helper_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/communicators/winrm/helper.rb b/plugins/communicators/winrm/helper.rb index 928c29979..b435a960c 100644 --- a/plugins/communicators/winrm/helper.rb +++ b/plugins/communicators/winrm/helper.rb @@ -33,7 +33,7 @@ module VagrantPlugins return addr if addr ssh_info = machine.ssh_info - raise Errors::WinRMNotReady if !ssh_info || ssh_info[:host].empty? + raise Errors::WinRMNotReady if !ssh_info || ssh_info[:host].to_s.empty? return ssh_info[:host] end diff --git a/test/unit/plugins/communicators/winrm/helper_test.rb b/test/unit/plugins/communicators/winrm/helper_test.rb index 818a4c75e..5768c720e 100644 --- a/test/unit/plugins/communicators/winrm/helper_test.rb +++ b/test/unit/plugins/communicators/winrm/helper_test.rb @@ -42,6 +42,12 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do expect { subject.winrm_address(machine) }. to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady) end + + it "raise a WinRMNotReady exception if it detects an unset host ip" do + machine.stub(ssh_info: { host: nil }) + expect { subject.winrm_address(machine) }. + to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady) + end end describe ".winrm_info" do