Change @ssl to @transport

This commit is contained in:
Max Lincoln 2014-07-22 19:58:27 -04:00
parent b3480049ad
commit 072bb26a30
5 changed files with 40 additions and 11 deletions

View File

@ -8,7 +8,7 @@ module VagrantPlugins
attr_accessor :guest_port
attr_accessor :max_tries
attr_accessor :timeout
attr_accessor :ssl
attr_accessor :transport
def initialize
@username = UNSET_VALUE
@ -18,19 +18,20 @@ module VagrantPlugins
@guest_port = UNSET_VALUE
@max_tries = UNSET_VALUE
@timeout = UNSET_VALUE
@ssl = UNSET_VALUE
@transport = UNSET_VALUE
@ssl_peer_verification = UNSET_VALUE
end
def finalize!
@username = "vagrant" if @username == UNSET_VALUE
@password = "vagrant" if @password == UNSET_VALUE
@transport = :ssl if @transport == UNSET_VALUE
@host = nil if @host == UNSET_VALUE
@port = (@ssl ? 5986 : 5985) if @port == UNSET_VALUE
@guest_port = (@ssl ? 5986 : 5985) if @guest_port == UNSET_VALUE
is_ssl = @transport == :ssl
@port = (is_ssl ? 5986 : 5985) if @port == UNSET_VALUE
@guest_port = (is_ssl ? 5986 : 5985) if @guest_port == UNSET_VALUE
@max_tries = 20 if @max_tries == UNSET_VALUE
@timeout = 60 if @timeout == UNSET_VALUE
@ssl = false if @ssl == UNSET_VALUE
@ssl_peer_verification = true if @ssl_peer_verification == UNSET_VALUE
end

View File

@ -29,6 +29,10 @@ module VagrantPlugins
class WinRMFileTransferError < WinRMError
error_key(:winrm_file_transfer_error)
end
class WinRMInvalidTransport < WinRMError
error_key(:invalid_transport)
end
end
end
end

View File

@ -115,7 +115,7 @@ module VagrantPlugins
@logger.info(" - Username: #{@config.username}")
@logger.info(" - Transport: #{@config.transport}")
client = ::WinRM::WinRMWebService.new(endpoint, transport.to_sym, endpoint_options)
client = ::WinRM::WinRMWebService.new(endpoint, @config.transport.to_sym, endpoint_options)
client.set_timeout(@config.timeout)
client.toggle_nori_type_casting(:off) #we don't want coersion of types
client
@ -126,7 +126,14 @@ module VagrantPlugins
end
def endpoint
"http#{@ssl ? 's' : ''}://#{@host}:#{@port}/wsman"
case @config.transport
when :ssl
"https://#{@host}:#{@port}/wsman"
when :plaintext
"http://#{@host}:#{@port}/wsman"
else
raise Errors::WinRMInvalidTransport, transport: @config.transport
end
end
def endpoint_options

View File

@ -29,6 +29,8 @@ en:
Message: %{message}
invalid_shell: |-
%{shell} is not a supported type of Windows shell.
invalid_transport: |-
%{transport} is not a supported WinRM transport.
winrm_not_ready: |-
The box is not able to report an address for WinRM to connect to yet.
WinRM cannot access this Vagrant environment. Please wait for the

View File

@ -7,6 +7,7 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
include_context "unit"
let(:session) { double("winrm_session") }
let(:port) { config.transport == :ssl ? 5986 : 5985 }
let(:config) {
VagrantPlugins::CommunicatorWinRM::Config.new.tap do |c|
c.username = 'username'
@ -16,7 +17,7 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
}
subject do
described_class.new('localhost', 5985, config).tap do |comm|
described_class.new('localhost', port, config).tap do |comm|
allow(comm).to receive(:new_session).and_return(session)
end
end
@ -50,15 +51,29 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
end
describe ".endpoint" do
it "should create winrm endpoint address" do
expect(subject.send(:endpoint)).to eq("http://localhost:5985/wsman")
context 'when transport is :ssl' do
it "should create winrm endpoint address using https" do
expect(subject.send(:endpoint)).to eq("https://localhost:5986/wsman")
end
end
context "when transport is :plaintext" do
let(:config) {
VagrantPlugins::CommunicatorWinRM::Config.new.tap do |c|
c.transport = :plaintext
c.finalize!
end
}
it "should create winrm endpoint address using http" do
expect(subject.send(:endpoint)).to eq("http://localhost:5985/wsman")
end
end
end
describe ".endpoint_options" do
it "should create endpoint options" do
expect(subject.send(:endpoint_options)).to eq(
{ user: "username", pass: "password", host: "localhost", port: 5985,
{ user: "username", pass: "password", host: "localhost", port: 5986,
basic_auth_only: true, no_ssl_peer_verification: false })
end
end