diff --git a/plugins/communicators/winrm/config.rb b/plugins/communicators/winrm/config.rb index 09ec5fb62..37259e3b3 100644 --- a/plugins/communicators/winrm/config.rb +++ b/plugins/communicators/winrm/config.rb @@ -11,14 +11,15 @@ module VagrantPlugins attr_accessor :ssl def initialize - @username = UNSET_VALUE - @password = UNSET_VALUE - @host = UNSET_VALUE - @port = UNSET_VALUE - @guest_port = UNSET_VALUE - @max_tries = UNSET_VALUE - @timeout = UNSET_VALUE - @ssl = UNSET_VALUE + @username = UNSET_VALUE + @password = UNSET_VALUE + @host = UNSET_VALUE + @port = UNSET_VALUE + @guest_port = UNSET_VALUE + @max_tries = UNSET_VALUE + @timeout = UNSET_VALUE + @ssl = UNSET_VALUE + @ssl_peer_verification = UNSET_VALUE end def finalize! @@ -30,6 +31,7 @@ module VagrantPlugins @max_tries = 20 if @max_tries == UNSET_VALUE @timeout = 1800 if @timeout == UNSET_VALUE @ssl = false if @ssl == UNSET_VALUE + @ssl_peer_verification = true if @ssl_peer_verification == UNSET_VALUE end def validate(machine) @@ -41,6 +43,9 @@ module VagrantPlugins errors << "winrm.guest_port cannot be nil." if @guest_port.nil? errors << "winrm.max_tries cannot be nil." if @max_tries.nil? errors << "winrm.timeout cannot be nil." if @timeout.nil? + unless @ssl_peer_verification == true || @ssl_peer_verification == false + errors << "winrm.ssl_peer_verification must be a boolean." + end { "WinRM" => errors } end diff --git a/plugins/communicators/winrm/shell.rb b/plugins/communicators/winrm/shell.rb index 8889819b2..f851d3805 100644 --- a/plugins/communicators/winrm/shell.rb +++ b/plugins/communicators/winrm/shell.rb @@ -39,18 +39,20 @@ module VagrantPlugins attr_reader :timeout_in_seconds attr_reader :max_tries attr_reader :ssl + attr_reader :ssl_peer_verification def initialize(host, username, password, options = {}) @logger = Log4r::Logger.new("vagrant::communication::winrmshell") @logger.debug("initializing WinRMShell") - @host = host - @port = options[:port] || (options[:ssl] ? 5986 : 5985) - @username = username - @password = password - @timeout_in_seconds = options[:timeout_in_seconds] || 60 - @max_tries = options[:max_tries] || 20 - @ssl = options[:ssl] || false + @host = host + @port = options[:port] || (options[:ssl] ? 5986 : 5985) + @username = username + @password = password + @timeout_in_seconds = options[:timeout_in_seconds] || 60 + @max_tries = options[:max_tries] || 20 + @ssl = options[:ssl] || false + @ssl_peer_verification = options[:ssl_peer_verification] || true end def powershell(command, &block) @@ -144,7 +146,7 @@ module VagrantPlugins port: @port, operation_timeout: @timeout_in_seconds, basic_auth_only: true, - no_ssl_peer_verification: true } + no_ssl_peer_verification: !@ssl_peer_verification } end end #WinShell class end diff --git a/test/unit/plugins/communicators/winrm/shell_test.rb b/test/unit/plugins/communicators/winrm/shell_test.rb index 3948cf336..6a61f67b0 100644 --- a/test/unit/plugins/communicators/winrm/shell_test.rb +++ b/test/unit/plugins/communicators/winrm/shell_test.rb @@ -51,7 +51,7 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do it "should create endpoint options" do expect(subject.send(:endpoint_options)).to eq( { user: "username", pass: "password", host: "localhost", port: 5985, - operation_timeout: 60, basic_auth_only: true, no_ssl_peer_verification: true }) + operation_timeout: 60, basic_auth_only: true, no_ssl_peer_verification: false }) end end