winrm 1.8.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -11
- data/.rubocop.yml +26 -22
- data/.travis.yml +11 -12
- data/Gemfile +3 -9
- data/LICENSE +202 -202
- data/README.md +232 -215
- data/Rakefile +34 -36
- data/Vagrantfile +6 -9
- data/WinrmAppveyor.psm1 +31 -31
- data/appveyor.yml +51 -51
- data/bin/rwinrm +97 -97
- data/changelog.md +86 -86
- data/lib/winrm.rb +39 -42
- data/lib/winrm/connection.rb +82 -0
- data/lib/winrm/connection_opts.rb +87 -0
- data/lib/winrm/{exceptions/exceptions.rb → exceptions.rb} +76 -57
- data/lib/winrm/http/response_handler.rb +96 -82
- data/lib/winrm/http/transport.rb +424 -435
- data/lib/winrm/http/transport_factory.rb +68 -0
- data/lib/winrm/output.rb +59 -43
- data/lib/winrm/psrp/create_pipeline.xml.erb +167 -0
- data/lib/winrm/psrp/fragment.rb +70 -0
- data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -0
- data/lib/winrm/psrp/message.rb +130 -0
- data/lib/winrm/psrp/message_data.rb +41 -0
- data/lib/winrm/psrp/message_data/base.rb +49 -0
- data/lib/winrm/psrp/message_data/error_record.rb +68 -0
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -0
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -0
- data/lib/winrm/psrp/message_data/session_capability.rb +36 -0
- data/lib/winrm/psrp/message_defragmenter.rb +62 -0
- data/lib/winrm/psrp/message_factory.rb +75 -0
- data/lib/winrm/psrp/message_fragmenter.rb +60 -0
- data/lib/winrm/psrp/powershell_output_decoder.rb +120 -0
- data/lib/winrm/psrp/receive_response_reader.rb +93 -0
- data/lib/winrm/psrp/session_capability.xml.erb +7 -0
- data/lib/winrm/psrp/uuid.rb +40 -0
- data/lib/winrm/shells/base.rb +175 -0
- data/lib/winrm/shells/cmd.rb +65 -0
- data/lib/winrm/shells/power_shell.rb +201 -0
- data/lib/winrm/shells/retryable.rb +45 -0
- data/lib/winrm/shells/shell_factory.rb +50 -0
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/wsmv/base.rb +59 -0
- data/lib/winrm/wsmv/cleanup_command.rb +61 -0
- data/lib/winrm/wsmv/close_shell.rb +50 -0
- data/lib/winrm/wsmv/command.rb +101 -0
- data/lib/winrm/wsmv/command_output.rb +76 -0
- data/lib/winrm/wsmv/command_output_decoder.rb +55 -0
- data/lib/winrm/wsmv/configuration.rb +46 -0
- data/lib/winrm/wsmv/create_pipeline.rb +66 -0
- data/lib/winrm/wsmv/create_shell.rb +119 -0
- data/lib/winrm/wsmv/header.rb +203 -0
- data/lib/winrm/wsmv/init_runspace_pool.rb +95 -0
- data/lib/winrm/wsmv/iso8601_duration.rb +60 -0
- data/lib/winrm/wsmv/keep_alive.rb +68 -0
- data/lib/winrm/wsmv/receive_response_reader.rb +128 -0
- data/lib/winrm/wsmv/send_data.rb +68 -0
- data/lib/winrm/wsmv/soap.rb +51 -0
- data/lib/winrm/wsmv/wql_query.rb +79 -0
- data/lib/winrm/wsmv/write_stdin.rb +88 -0
- data/preamble +17 -17
- data/{spec → tests/integration}/auth_timeout_spec.rb +18 -16
- data/{spec → tests/integration}/cmd_spec.rb +104 -102
- data/{spec → tests/integration}/config-example.yml +16 -19
- data/{spec → tests/integration}/issue_59_spec.rb +26 -23
- data/tests/integration/powershell_spec.rb +154 -0
- data/{spec → tests/integration}/spec_helper.rb +65 -73
- data/{spec → tests/integration}/transport_spec.rb +99 -139
- data/{spec → tests/integration}/wql_spec.rb +16 -14
- data/{spec → tests}/matchers.rb +60 -74
- data/tests/spec/configuration_spec.rb +93 -0
- data/tests/spec/connection_spec.rb +39 -0
- data/{spec → tests/spec}/exception_spec.rb +50 -50
- data/tests/spec/http/transport_factory_spec.rb +68 -0
- data/tests/spec/http/transport_spec.rb +44 -0
- data/{spec → tests/spec}/output_spec.rb +127 -110
- data/tests/spec/psrp/fragment_spec.rb +62 -0
- data/tests/spec/psrp/message_data/base_spec.rb +13 -0
- data/tests/spec/psrp/message_data/error_record_spec.rb +41 -0
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -0
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -0
- data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -0
- data/tests/spec/psrp/message_data_spec.rb +35 -0
- data/tests/spec/psrp/message_defragmenter_spec.rb +47 -0
- data/tests/spec/psrp/message_fragmenter_spec.rb +105 -0
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +84 -0
- data/tests/spec/psrp/psrp_message_spec.rb +70 -0
- data/tests/spec/psrp/recieve_response_reader_spec.rb +154 -0
- data/tests/spec/psrp/uuid_spec.rb +28 -0
- data/{spec → tests/spec}/response_handler_spec.rb +61 -61
- data/tests/spec/shells/base_spec.rb +202 -0
- data/tests/spec/shells/cmd_spec.rb +75 -0
- data/tests/spec/shells/powershell_spec.rb +175 -0
- data/tests/spec/spec_helper.rb +47 -0
- data/tests/spec/stubs/clixml/error_record.xml.erb +84 -0
- data/{spec → tests/spec}/stubs/responses/get_command_output_response.xml.erb +13 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -0
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -0
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -0
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -0
- data/{spec → tests/spec}/stubs/responses/open_shell_v1.xml +19 -19
- data/{spec → tests/spec}/stubs/responses/open_shell_v2.xml +20 -20
- data/{spec → tests/spec}/stubs/responses/soap_fault_v1.xml +36 -36
- data/{spec → tests/spec}/stubs/responses/soap_fault_v2.xml +42 -42
- data/{spec → tests/spec}/stubs/responses/wmi_error_v2.xml +41 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +22 -0
- data/tests/spec/wsmv/close_shell_spec.rb +17 -0
- data/{spec → tests/spec/wsmv}/command_output_decoder_spec.rb +37 -37
- data/tests/spec/wsmv/command_output_spec.rb +45 -0
- data/tests/spec/wsmv/command_spec.rb +19 -0
- data/tests/spec/wsmv/configuration_spec.rb +17 -0
- data/tests/spec/wsmv/create_pipeline_spec.rb +31 -0
- data/tests/spec/wsmv/create_shell_spec.rb +38 -0
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -0
- data/tests/spec/wsmv/keep_alive_spec.rb +21 -0
- data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -0
- data/tests/spec/wsmv/send_data_spec.rb +30 -0
- data/tests/spec/wsmv/wql_query_spec.rb +13 -0
- data/tests/spec/wsmv/write_stdin_spec.rb +22 -0
- data/winrm.gemspec +42 -40
- metadata +140 -38
- data/.rspec +0 -3
- data/lib/winrm/command_executor.rb +0 -243
- data/lib/winrm/command_output_decoder.rb +0 -53
- data/lib/winrm/helpers/iso8601_duration.rb +0 -58
- data/lib/winrm/helpers/powershell_script.rb +0 -42
- data/lib/winrm/soap_provider.rb +0 -39
- data/lib/winrm/winrm_service.rb +0 -550
- data/spec/command_executor_spec.rb +0 -475
- data/spec/issue_184_spec.rb +0 -67
- data/spec/powershell_spec.rb +0 -97
- data/spec/winrm_options_spec.rb +0 -76
- data/spec/winrm_primitives_spec.rb +0 -51
@@ -1,23 +1,26 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
expect(
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe 'issue 59' do
|
5
|
+
describe 'long running script without output' do
|
6
|
+
let(:logged_output) { StringIO.new }
|
7
|
+
let(:logger) { Logging.logger(logged_output) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
opts = connection_opts.dup
|
11
|
+
opts[:operation_timeout] = 1
|
12
|
+
conn = WinRM::Connection.new(opts)
|
13
|
+
conn.logger = logger
|
14
|
+
@powershell = conn.shell(:powershell)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should not error' do
|
18
|
+
out = @powershell.run('$ProgressPreference="SilentlyContinue";sleep 3; Write-Host "Hello"')
|
19
|
+
|
20
|
+
expect(out).to have_exit_code 0
|
21
|
+
expect(out).to have_stdout_match(/Hello/)
|
22
|
+
expect(out).to have_no_stderr
|
23
|
+
expect(logged_output.string).to match(/retrying receive request/)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe 'winrm client powershell' do
|
5
|
+
before(:all) do
|
6
|
+
@powershell = winrm_connection.shell(:powershell)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'ipconfig' do
|
10
|
+
subject(:output) { @powershell.run('ipconfig') }
|
11
|
+
it { should have_exit_code 0 }
|
12
|
+
it { should have_stdout_match(/Windows IP Configuration/) }
|
13
|
+
it { should have_no_stderr }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'exit' do
|
17
|
+
subject(:output) { @powershell.run('exit 5') }
|
18
|
+
it { should have_exit_code 5 }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'echo \'hello world\' using apostrophes' do
|
22
|
+
subject(:output) { @powershell.run("echo 'hello world'") }
|
23
|
+
it { should have_exit_code 0 }
|
24
|
+
it { should have_stdout_match(/hello world/) }
|
25
|
+
it { should have_no_stderr }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'handling special XML characters' do
|
29
|
+
subject(:output) { @powershell.run("echo 'hello & <world>'") }
|
30
|
+
it { should have_exit_code 0 }
|
31
|
+
it { should have_stdout_match(/hello & <world>/) }
|
32
|
+
it { should have_no_stderr }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'dir with incorrect argument /z' do
|
36
|
+
subject(:output) { @powershell.run('dir /z') }
|
37
|
+
it { should have_stderr_match(/Cannot find path/) }
|
38
|
+
it { should have_no_stdout }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'Math area calculation' do
|
42
|
+
subject(:output) do
|
43
|
+
@powershell.run <<-EOH
|
44
|
+
$diameter = 4.5
|
45
|
+
$area = [Math]::pow([Math]::PI * ($diameter/2), 2)
|
46
|
+
Write-Host $area
|
47
|
+
EOH
|
48
|
+
end
|
49
|
+
it { should have_exit_code 0 }
|
50
|
+
it { should have_stdout_match(/49.9648722805149/) }
|
51
|
+
it { should have_no_stderr }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'ipconfig with a block' do
|
55
|
+
subject(:stdout) do
|
56
|
+
outvar = ''
|
57
|
+
@powershell.run('ipconfig') do |stdout, _stderr|
|
58
|
+
outvar << stdout
|
59
|
+
end
|
60
|
+
outvar
|
61
|
+
end
|
62
|
+
it { should match(/Windows IP Configuration/) }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'capturing output from Write-Host and Write-Error' do
|
66
|
+
subject(:output) do
|
67
|
+
script = <<-eos
|
68
|
+
Write-Host 'Hello'
|
69
|
+
$host.ui.WriteErrorLine(', world!')
|
70
|
+
eos
|
71
|
+
|
72
|
+
@captured_stdout = ''
|
73
|
+
@captured_stderr = ''
|
74
|
+
@powershell.run(script) do |stdout, stderr|
|
75
|
+
@captured_stdout << stdout if stdout
|
76
|
+
@captured_stderr << stderr if stderr
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should have stdout' do
|
81
|
+
expect(output.stdout).to eq("Hello\r\n")
|
82
|
+
expect(output.stdout).to eq(@captured_stdout)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should have stderr' do
|
86
|
+
expect(output.stderr).to eq(", world!\r\n")
|
87
|
+
expect(output.stderr).to eq(@captured_stderr)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should have output' do
|
91
|
+
expect(output.output).to eq("Hello\r\n, world!\r\n")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'capturing output from pipeline followed by Host' do
|
96
|
+
subject(:output) do
|
97
|
+
script = <<-eos
|
98
|
+
Write-Output 'output'
|
99
|
+
$host.UI.Writeline('host')
|
100
|
+
eos
|
101
|
+
|
102
|
+
@captured_stdout = ''
|
103
|
+
@captured_stderr = ''
|
104
|
+
@powershell.run(script) do |stdout, stderr|
|
105
|
+
@captured_stdout << stdout if stdout
|
106
|
+
@captured_stderr << stderr if stderr
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should print from the pipeline first' do
|
111
|
+
expect(output.stdout).to start_with("output\r\n")
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should write to host last' do
|
115
|
+
expect(output.stdout).to end_with("host\r\n")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'it should handle utf-8 characters' do
|
120
|
+
subject(:output) { @powershell.run('echo "✓1234-äöü"') }
|
121
|
+
it { should have_exit_code 0 }
|
122
|
+
it { should have_stdout_match(/✓1234-äöü/) }
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'output exceeds a single fragment' do
|
126
|
+
subject(:output) { @powershell.run('Write-Output $("a"*600000)') }
|
127
|
+
it { should have_exit_code 0 }
|
128
|
+
it 'has assebled the output' do
|
129
|
+
expect(output.stdout).to eq('a' * 600000 + "\r\n")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'command exceeds a single fragment' do
|
134
|
+
subject(:output) { @powershell.run("$var='#{'a' * 600000}';Write-Output 'long var'") }
|
135
|
+
it { should have_exit_code 0 }
|
136
|
+
it 'has sent the output' do
|
137
|
+
expect(output.stdout).to eq("long var\r\n")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'reading pipeline messages' do
|
142
|
+
subject(:messages) { @powershell.send_pipeline_command('ipconfig') }
|
143
|
+
|
144
|
+
it 'returns multiple messages' do
|
145
|
+
expect(messages.length).to be > 1
|
146
|
+
end
|
147
|
+
it 'first message is pipeline output' do
|
148
|
+
expect(messages.first.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output])
|
149
|
+
end
|
150
|
+
it 'last message is pipeline state' do
|
151
|
+
expect(messages.last.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -1,73 +1,65 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'winrm'
|
5
|
-
require 'json'
|
6
|
-
require_relative 'matchers'
|
7
|
-
|
8
|
-
# Creates a WinRM connection for integration tests
|
9
|
-
module ConnectionHelper
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
# rubocop:enable Metrics/MethodLength
|
69
|
-
end
|
70
|
-
|
71
|
-
RSpec.configure do |config|
|
72
|
-
config.include(ConnectionHelper)
|
73
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'winrm'
|
5
|
+
require 'json'
|
6
|
+
require_relative '../matchers'
|
7
|
+
|
8
|
+
# Creates a WinRM connection for integration tests
|
9
|
+
module ConnectionHelper
|
10
|
+
def winrm_connection
|
11
|
+
WinRM::Connection.new(connection_opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
def connection_opts
|
15
|
+
@config ||= begin
|
16
|
+
cfg = symbolize_keys(YAML.load(File.read(winrm_config_path)))
|
17
|
+
merge_environment(cfg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def merge_environment(config)
|
22
|
+
merge_config_option_from_environment(config, 'user')
|
23
|
+
merge_config_option_from_environment(config, 'password')
|
24
|
+
merge_config_option_from_environment(config, 'no_ssl_peer_verification')
|
25
|
+
if ENV['use_ssl_peer_fingerprint']
|
26
|
+
config[:ssl_peer_fingerprint] = ENV['winrm_cert']
|
27
|
+
end
|
28
|
+
config[:endpoint] = ENV['winrm_endpoint'] if ENV['winrm_endpoint']
|
29
|
+
config
|
30
|
+
end
|
31
|
+
|
32
|
+
def merge_config_option_from_environment(config, key)
|
33
|
+
env_key = 'winrm_' + key
|
34
|
+
config[key.to_sym] = ENV[env_key] if ENV[env_key]
|
35
|
+
end
|
36
|
+
|
37
|
+
def winrm_config_path
|
38
|
+
# Copy config-example.yml to config.yml and edit for your local ConnectionOpts
|
39
|
+
path = File.expand_path("#{File.dirname(__FILE__)}/config.yml")
|
40
|
+
unless File.exist?(path)
|
41
|
+
# user hasn't done this, so use sane defaults for unit tests
|
42
|
+
path = File.expand_path("#{File.dirname(__FILE__)}/config-example.yml")
|
43
|
+
end
|
44
|
+
path
|
45
|
+
end
|
46
|
+
|
47
|
+
def symbolize_keys(hash)
|
48
|
+
hash.each_with_object({}) do |(key, value), result|
|
49
|
+
new_key = case key
|
50
|
+
when String then key.to_sym
|
51
|
+
else key
|
52
|
+
end
|
53
|
+
new_value = case value
|
54
|
+
when Hash then symbolize_keys(value)
|
55
|
+
else value
|
56
|
+
end
|
57
|
+
result[new_key] = new_value
|
58
|
+
result
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
RSpec.configure do |config|
|
64
|
+
config.include(ConnectionHelper)
|
65
|
+
end
|
@@ -1,139 +1,99 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
let(:
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
context 'HttpNegotiate' do
|
102
|
-
let(:auth_type) { :negotiate }
|
103
|
-
|
104
|
-
it_behaves_like 'a valid_connection'
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'BasicAuthSSL', skip: ENV['winrm_cert'].nil? do
|
108
|
-
let(:basic_auth_only) { true }
|
109
|
-
let(:auth_type) { :ssl }
|
110
|
-
let(:no_ssl_peer_verification) { true }
|
111
|
-
|
112
|
-
it_behaves_like 'a valid_connection'
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'ClientCertAuthSSL', skip: ENV['user_cert'].nil? do
|
116
|
-
let(:auth_type) { :ssl }
|
117
|
-
let(:no_ssl_peer_verification) { true }
|
118
|
-
let(:user_cert) { ENV['user_cert'] }
|
119
|
-
let(:user_key) { ENV['user_key'] }
|
120
|
-
|
121
|
-
before { options[:pass] = nil }
|
122
|
-
|
123
|
-
it_behaves_like 'a valid_connection'
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'Negotiate over SSL', skip: ENV['winrm_cert'].nil? do
|
127
|
-
let(:auth_type) { :ssl }
|
128
|
-
let(:no_ssl_peer_verification) { true }
|
129
|
-
|
130
|
-
it_behaves_like 'a valid_connection'
|
131
|
-
end
|
132
|
-
|
133
|
-
context 'SSL fingerprint', skip: ENV['winrm_cert'].nil? do
|
134
|
-
let(:auth_type) { :ssl }
|
135
|
-
let(:ssl_peer_fingerprint) { ENV['winrm_cert'] }
|
136
|
-
|
137
|
-
it_behaves_like 'a valid_connection'
|
138
|
-
end
|
139
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe 'WinRM connection' do
|
5
|
+
let(:connection) do
|
6
|
+
endpoint = connection_opts[:endpoint].dup
|
7
|
+
if auth_type == :ssl
|
8
|
+
endpoint.sub!('5985', '5986')
|
9
|
+
endpoint.sub!('http', 'https')
|
10
|
+
end
|
11
|
+
conn_options = {
|
12
|
+
transport: auth_type,
|
13
|
+
endpoint: endpoint
|
14
|
+
}.merge(options)
|
15
|
+
WinRM::Connection.new(conn_options).shell(:cmd)
|
16
|
+
end
|
17
|
+
let(:options) do
|
18
|
+
opts = {}
|
19
|
+
opts[:user] = connection_opts[:user]
|
20
|
+
opts[:password] = connection_opts[:password]
|
21
|
+
opts[:basic_auth_only] = basic_auth_only
|
22
|
+
opts[:no_ssl_peer_verification] = no_ssl_peer_verification
|
23
|
+
opts[:ssl_peer_fingerprint] = ssl_peer_fingerprint
|
24
|
+
opts[:client_cert] = user_cert
|
25
|
+
opts[:client_key] = user_key
|
26
|
+
opts
|
27
|
+
end
|
28
|
+
let(:basic_auth_only) { false }
|
29
|
+
let(:no_ssl_peer_verification) { false }
|
30
|
+
let(:ssl_peer_fingerprint) { nil }
|
31
|
+
let(:user_cert) { nil }
|
32
|
+
let(:user_key) { nil }
|
33
|
+
|
34
|
+
subject(:output) { connection.run('ipconfig') }
|
35
|
+
|
36
|
+
after(:each) do
|
37
|
+
connection.close
|
38
|
+
end
|
39
|
+
|
40
|
+
shared_examples 'a valid_connection' do
|
41
|
+
it 'has a 0 exit code' do
|
42
|
+
expect(subject).to have_exit_code 0
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'includes command output' do
|
46
|
+
expect(subject).to have_stdout_match(/Windows IP Configuration/)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'has no errors' do
|
50
|
+
expect(subject).to have_no_stderr
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'HttpPlaintext' do
|
55
|
+
let(:basic_auth_only) { true }
|
56
|
+
let(:auth_type) { :plaintext }
|
57
|
+
|
58
|
+
it_behaves_like 'a valid_connection'
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'HttpNegotiate' do
|
62
|
+
let(:auth_type) { :negotiate }
|
63
|
+
|
64
|
+
it_behaves_like 'a valid_connection'
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'BasicAuthSSL', skip: ENV['winrm_cert'].nil? do
|
68
|
+
let(:basic_auth_only) { true }
|
69
|
+
let(:auth_type) { :ssl }
|
70
|
+
let(:no_ssl_peer_verification) { true }
|
71
|
+
|
72
|
+
it_behaves_like 'a valid_connection'
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'ClientCertAuthSSL', skip: ENV['user_cert'].nil? do
|
76
|
+
let(:auth_type) { :ssl }
|
77
|
+
let(:no_ssl_peer_verification) { true }
|
78
|
+
let(:user_cert) { ENV['user_cert'] }
|
79
|
+
let(:user_key) { ENV['user_key'] }
|
80
|
+
|
81
|
+
before { options[:pass] = nil }
|
82
|
+
|
83
|
+
it_behaves_like 'a valid_connection'
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'Negotiate over SSL', skip: ENV['winrm_cert'].nil? do
|
87
|
+
let(:auth_type) { :ssl }
|
88
|
+
let(:no_ssl_peer_verification) { true }
|
89
|
+
|
90
|
+
it_behaves_like 'a valid_connection'
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'SSL fingerprint', skip: ENV['winrm_cert'].nil? do
|
94
|
+
let(:auth_type) { :ssl }
|
95
|
+
let(:ssl_peer_fingerprint) { ENV['winrm_cert'] }
|
96
|
+
|
97
|
+
it_behaves_like 'a valid_connection'
|
98
|
+
end
|
99
|
+
end
|