winrm 2.2.3 → 2.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -1
  3. data/bin/rwinrm +90 -97
  4. data/lib/winrm/connection.rb +84 -86
  5. data/lib/winrm/connection_opts.rb +90 -91
  6. data/lib/winrm/exceptions.rb +14 -2
  7. data/lib/winrm/http/response_handler.rb +127 -96
  8. data/lib/winrm/http/transport.rb +462 -427
  9. data/lib/winrm/http/transport_factory.rb +1 -5
  10. data/lib/winrm/output.rb +1 -2
  11. data/lib/winrm/psrp/fragment.rb +0 -2
  12. data/lib/winrm/psrp/message.rb +128 -130
  13. data/lib/winrm/psrp/message_data/base.rb +0 -2
  14. data/lib/winrm/psrp/message_data/error_record.rb +2 -2
  15. data/lib/winrm/psrp/message_data/pipeline_host_call.rb +0 -2
  16. data/lib/winrm/psrp/message_data/pipeline_output.rb +48 -54
  17. data/lib/winrm/psrp/message_data/pipeline_state.rb +0 -2
  18. data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +0 -2
  19. data/lib/winrm/psrp/message_data/runspacepool_state.rb +0 -2
  20. data/lib/winrm/psrp/message_data/session_capability.rb +0 -2
  21. data/lib/winrm/psrp/message_data.rb +0 -2
  22. data/lib/winrm/psrp/message_defragmenter.rb +2 -2
  23. data/lib/winrm/psrp/message_factory.rb +16 -5
  24. data/lib/winrm/psrp/message_fragmenter.rb +1 -3
  25. data/lib/winrm/psrp/powershell_output_decoder.rb +142 -144
  26. data/lib/winrm/psrp/receive_response_reader.rb +3 -5
  27. data/lib/winrm/psrp/uuid.rb +1 -2
  28. data/lib/winrm/shells/base.rb +7 -4
  29. data/lib/winrm/shells/cmd.rb +63 -65
  30. data/lib/winrm/shells/power_shell.rb +207 -202
  31. data/lib/winrm/shells/retryable.rb +44 -45
  32. data/lib/winrm/shells/shell_factory.rb +0 -2
  33. data/lib/winrm/version.rb +1 -3
  34. data/lib/winrm/wsmv/base.rb +0 -2
  35. data/lib/winrm/wsmv/cleanup_command.rb +1 -2
  36. data/lib/winrm/wsmv/close_shell.rb +1 -2
  37. data/lib/winrm/wsmv/command.rb +2 -3
  38. data/lib/winrm/wsmv/command_output.rb +2 -3
  39. data/lib/winrm/wsmv/command_output_decoder.rb +1 -2
  40. data/lib/winrm/wsmv/configuration.rb +0 -2
  41. data/lib/winrm/wsmv/create_pipeline.rb +0 -2
  42. data/lib/winrm/wsmv/create_shell.rb +2 -6
  43. data/lib/winrm/wsmv/header.rb +213 -215
  44. data/lib/winrm/wsmv/init_runspace_pool.rb +96 -95
  45. data/lib/winrm/wsmv/iso8601_duration.rb +0 -2
  46. data/lib/winrm/wsmv/keep_alive.rb +0 -2
  47. data/lib/winrm/wsmv/receive_response_reader.rb +128 -126
  48. data/lib/winrm/wsmv/send_data.rb +0 -2
  49. data/lib/winrm/wsmv/soap.rb +0 -2
  50. data/lib/winrm/wsmv/wql_pull.rb +54 -56
  51. data/lib/winrm/wsmv/wql_query.rb +98 -99
  52. data/lib/winrm/wsmv/write_stdin.rb +0 -2
  53. data/lib/winrm.rb +3 -5
  54. metadata +81 -135
  55. data/.gitignore +0 -10
  56. data/.rubocop.yml +0 -26
  57. data/.travis.yml +0 -11
  58. data/Gemfile +0 -3
  59. data/Rakefile +0 -34
  60. data/Vagrantfile +0 -6
  61. data/WinrmAppveyor.psm1 +0 -32
  62. data/appveyor.yml +0 -51
  63. data/changelog.md +0 -128
  64. data/preamble +0 -17
  65. data/tests/integration/auth_timeout_spec.rb +0 -18
  66. data/tests/integration/cmd_spec.rb +0 -131
  67. data/tests/integration/config-example.yml +0 -16
  68. data/tests/integration/issue_59_spec.rb +0 -26
  69. data/tests/integration/powershell_spec.rb +0 -165
  70. data/tests/integration/spec_helper.rb +0 -65
  71. data/tests/integration/transport_spec.rb +0 -99
  72. data/tests/integration/wql_spec.rb +0 -34
  73. data/tests/matchers.rb +0 -60
  74. data/tests/spec/configuration_spec.rb +0 -184
  75. data/tests/spec/connection_spec.rb +0 -39
  76. data/tests/spec/exception_spec.rb +0 -50
  77. data/tests/spec/http/transport_factory_spec.rb +0 -68
  78. data/tests/spec/http/transport_spec.rb +0 -44
  79. data/tests/spec/output_spec.rb +0 -127
  80. data/tests/spec/psrp/fragment_spec.rb +0 -62
  81. data/tests/spec/psrp/message_data/base_spec.rb +0 -13
  82. data/tests/spec/psrp/message_data/error_record_spec.rb +0 -41
  83. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -25
  84. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -32
  85. data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -40
  86. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -25
  87. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -16
  88. data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -30
  89. data/tests/spec/psrp/message_data_spec.rb +0 -35
  90. data/tests/spec/psrp/message_defragmenter_spec.rb +0 -47
  91. data/tests/spec/psrp/message_fragmenter_spec.rb +0 -105
  92. data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -100
  93. data/tests/spec/psrp/psrp_message_spec.rb +0 -70
  94. data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -172
  95. data/tests/spec/psrp/uuid_spec.rb +0 -28
  96. data/tests/spec/response_handler_spec.rb +0 -61
  97. data/tests/spec/shells/base_spec.rb +0 -225
  98. data/tests/spec/shells/cmd_spec.rb +0 -75
  99. data/tests/spec/shells/powershell_spec.rb +0 -175
  100. data/tests/spec/spec_helper.rb +0 -47
  101. data/tests/spec/stubs/clixml/error_record.xml.erb +0 -84
  102. data/tests/spec/stubs/clixml/pipeline_state.xml.erb +0 -88
  103. data/tests/spec/stubs/responses/get_command_output_response.xml.erb +0 -13
  104. data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +0 -10
  105. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +0 -10
  106. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +0 -12
  107. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +0 -9
  108. data/tests/spec/stubs/responses/open_shell_v1.xml +0 -19
  109. data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
  110. data/tests/spec/stubs/responses/soap_fault_v1.xml +0 -36
  111. data/tests/spec/stubs/responses/soap_fault_v2.xml +0 -42
  112. data/tests/spec/stubs/responses/wmi_error_v2.xml +0 -41
  113. data/tests/spec/wsmv/cleanup_command_spec.rb +0 -22
  114. data/tests/spec/wsmv/close_shell_spec.rb +0 -17
  115. data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -37
  116. data/tests/spec/wsmv/command_output_spec.rb +0 -45
  117. data/tests/spec/wsmv/command_spec.rb +0 -19
  118. data/tests/spec/wsmv/configuration_spec.rb +0 -17
  119. data/tests/spec/wsmv/create_pipeline_spec.rb +0 -31
  120. data/tests/spec/wsmv/create_shell_spec.rb +0 -38
  121. data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -36
  122. data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
  123. data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -123
  124. data/tests/spec/wsmv/send_data_spec.rb +0 -30
  125. data/tests/spec/wsmv/wql_query_spec.rb +0 -13
  126. data/tests/spec/wsmv/write_stdin_spec.rb +0 -22
  127. data/winrm.gemspec +0 -47
data/preamble DELETED
@@ -1,17 +0,0 @@
1
- =begin
2
- This file is part of WinRM; the Ruby library for Microsoft WinRM.
3
-
4
- Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License.
8
- You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- =end
@@ -1,18 +0,0 @@
1
- # encoding: UTF-8
2
- require_relative 'spec_helper'
3
-
4
- # This test may only be meaningful with kerberos auth
5
- # Against server 2012, a kerberos connection will require reauth (get a 401)
6
- # if there are no requests for >= 15 seconds
7
-
8
- describe 'Verify kerberos will reauth when necessary', kerberos: true do
9
- before(:all) do
10
- @powershell = winrm_connection.shell(:powershell)
11
- end
12
-
13
- it 'work with a 18 second sleep' do
14
- ps_command = 'Start-Sleep -s 18'
15
- output = @powershell.run(ps_command)
16
- expect(output.exitcode).to eq(0)
17
- end
18
- end
@@ -1,131 +0,0 @@
1
- # encoding: UTF-8
2
- require_relative 'spec_helper'
3
-
4
- describe 'winrm client cmd' do
5
- before(:all) do
6
- @cmd_shell = winrm_connection.shell(:cmd)
7
- end
8
-
9
- describe 'empty string' do
10
- subject(:output) { @cmd_shell.run('') }
11
- it { should have_exit_code 0 }
12
- it { should have_no_stdout }
13
- it { should have_no_stderr }
14
- end
15
-
16
- describe 'ipconfig' do
17
- subject(:output) { @cmd_shell.run('ipconfig') }
18
- it { should have_exit_code 0 }
19
- it { should have_stdout_match(/Windows IP Configuration/) }
20
- it { should have_no_stderr }
21
- end
22
-
23
- describe 'codepage' do
24
- let(:options) { Hash.new }
25
- let(:shell) { winrm_connection.shell(:cmd, options) }
26
-
27
- after { shell.close }
28
-
29
- subject(:output) { shell.run('chcp') }
30
-
31
- it 'should default to UTF-8 (65001)' do
32
- should have_stdout_match(/Active code page: 65001/)
33
- end
34
-
35
- context 'when changing the codepage' do
36
- let(:options) { { codepage: 437 } }
37
-
38
- it 'sets the codepage to the one given' do
39
- should have_stdout_match(/Active code page: 437/)
40
- end
41
- end
42
- end
43
-
44
- describe 'echo \'hello world\' using apostrophes' do
45
- subject(:output) { @cmd_shell.run("echo 'hello world'") }
46
- it { should have_exit_code 0 }
47
- it { should have_stdout_match(/'hello world'/) }
48
- it { should have_no_stderr }
49
- end
50
-
51
- describe 'multi stream output from large file' do
52
- subject(:output) { @cmd_shell.run('type c:\windows\logs\dism\dism.log') }
53
- it { should have_exit_code 0 }
54
- it { should have_no_stderr }
55
- end
56
-
57
- describe 'echo "string with trailing \\" using double quotes' do
58
- # This is a regression test for #131. " is converted to &quot; when serializing
59
- # the command to SOAP/XML. Any naive substitution performed on such a serialized
60
- # string can result in any \& sequence being interpreted as a back-substitution.
61
- subject(:output) { @cmd_shell.run('echo "string with trailing \\"') }
62
- it { should have_exit_code 0 }
63
- it { should have_stdout_match(/string with trailing \\/) }
64
- it { should have_no_stderr }
65
- end
66
-
67
- describe 'capturing output from stdout and stderr' do
68
- subject(:output) do
69
- # Note: Multiple lines doesn't work:
70
- # script = <<-eos
71
- # echo Hello
72
- # echo , world! 1>&2
73
- # eos
74
-
75
- script = 'echo Hello & echo , world! 1>&2'
76
-
77
- @captured_stdout = ''
78
- @captured_stderr = ''
79
- @cmd_shell.run(script) do |stdout, stderr|
80
- @captured_stdout << stdout if stdout
81
- @captured_stderr << stderr if stderr
82
- end
83
- end
84
-
85
- it 'should have stdout' do
86
- expect(output.stdout).to eq("Hello \r\n")
87
- expect(output.stdout).to eq(@captured_stdout)
88
- end
89
-
90
- it 'should have stderr' do
91
- expect(output.stderr).to eq(", world! \r\n")
92
- expect(output.stderr).to eq(@captured_stderr)
93
- end
94
-
95
- it 'should have output' do
96
- expect(output.output).to eq("Hello \r\n, world! \r\n")
97
- end
98
- end
99
-
100
- describe 'ipconfig with /all argument' do
101
- subject(:output) { @cmd_shell.run('ipconfig', %w(/all)) }
102
- it { should have_exit_code 0 }
103
- it { should have_stdout_match(/Windows IP Configuration/) }
104
- it { should have_no_stderr }
105
- end
106
-
107
- describe 'dir with incorrect argument /z' do
108
- subject(:output) { @cmd_shell.run('dir /z') }
109
- it { should have_exit_code 1 }
110
- it { should have_no_stdout }
111
- it { should have_stderr_match(/Invalid switch/) }
112
- end
113
-
114
- describe 'ipconfig && echo error 1>&2' do
115
- subject(:output) { @cmd_shell.run('ipconfig && echo error 1>&2') }
116
- it { should have_exit_code 0 }
117
- it { should have_stdout_match(/Windows IP Configuration/) }
118
- it { should have_stderr_match(/error/) }
119
- end
120
-
121
- describe 'ipconfig with a block' do
122
- subject(:stdout) do
123
- outvar = ''
124
- @cmd_shell.run('ipconfig') do |stdout, _stderr|
125
- outvar << stdout
126
- end
127
- outvar
128
- end
129
- it { should match(/Windows IP Configuration/) }
130
- end
131
- end
@@ -1,16 +0,0 @@
1
- # Copy this file to config.yml and edit the settings below.
2
- # This should work out of the box for vagrant provisioned boxes.
3
-
4
- ## Kerberos
5
- # auth_type: kerberos
6
- # realm: "your.realm"
7
- # endpoint: "http://<yourserver>:5985/wsman"
8
-
9
- # If you are running this in a vagrant provisioned box using NAT,
10
- # this will be the forwarded WinRM HTTP port to your VM.
11
- # If you are running this on the VM, the default HTTP port is 5985.
12
- # See README.md#Troubleshooting.
13
-
14
- endpoint: "http://localhost:55985/wsman"
15
- user: vagrant
16
- password: vagrant
@@ -1,26 +0,0 @@
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
@@ -1,165 +0,0 @@
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 'ipconfig with invalid args' do
17
- subject(:output) { @powershell.run('ipconfig blah') }
18
- it { should have_exit_code 1 }
19
- end
20
-
21
- describe 'throw' do
22
- subject(:output) { @powershell.run("throw 'an error occured'") }
23
- it { should have_exit_code 0 }
24
- it { should have_stderr_match(/an error occured/) }
25
- end
26
-
27
- describe 'exit' do
28
- subject(:output) { @powershell.run('exit 5') }
29
- it { should have_exit_code 5 }
30
- end
31
-
32
- describe 'echo \'hello world\' using apostrophes' do
33
- subject(:output) { @powershell.run("echo 'hello world'") }
34
- it { should have_exit_code 0 }
35
- it { should have_stdout_match(/hello world/) }
36
- it { should have_no_stderr }
37
- end
38
-
39
- describe 'handling special XML characters' do
40
- subject(:output) { @powershell.run("echo 'hello & <world>'") }
41
- it { should have_exit_code 0 }
42
- it { should have_stdout_match(/hello & <world>/) }
43
- it { should have_no_stderr }
44
- end
45
-
46
- describe 'dir with incorrect argument /z' do
47
- subject(:output) { @powershell.run('dir /z') }
48
- it { should have_stderr_match(/Cannot find path/) }
49
- it { should have_no_stdout }
50
- end
51
-
52
- describe 'Math area calculation' do
53
- subject(:output) do
54
- @powershell.run <<-EOH
55
- $diameter = 4.5
56
- $area = [Math]::pow([Math]::PI * ($diameter/2), 2)
57
- Write-Host $area
58
- EOH
59
- end
60
- it { should have_exit_code 0 }
61
- it { should have_stdout_match(/49.9648722805149/) }
62
- it { should have_no_stderr }
63
- end
64
-
65
- describe 'ipconfig with a block' do
66
- subject(:stdout) do
67
- outvar = ''
68
- @powershell.run('ipconfig') do |stdout, _stderr|
69
- outvar << stdout
70
- end
71
- outvar
72
- end
73
- it { should match(/Windows IP Configuration/) }
74
- end
75
-
76
- describe 'capturing output from Write-Host and Write-Error' do
77
- subject(:output) do
78
- script = <<-eos
79
- Write-Host 'Hello'
80
- $host.ui.WriteErrorLine(', world!')
81
- eos
82
-
83
- @captured_stdout = ''
84
- @captured_stderr = ''
85
- @powershell.run(script) do |stdout, stderr|
86
- @captured_stdout << stdout if stdout
87
- @captured_stderr << stderr if stderr
88
- end
89
- end
90
-
91
- it 'should have stdout' do
92
- expect(output.stdout).to eq("Hello\r\n")
93
- expect(output.stdout).to eq(@captured_stdout)
94
- end
95
-
96
- it 'should have stderr' do
97
- expect(output.stderr).to eq(", world!\r\n")
98
- expect(output.stderr).to eq(@captured_stderr)
99
- end
100
-
101
- it 'should have output' do
102
- expect(output.output).to eq("Hello\r\n, world!\r\n")
103
- end
104
- end
105
-
106
- describe 'capturing output from pipeline followed by Host' do
107
- subject(:output) do
108
- script = <<-eos
109
- Write-Output 'output'
110
- $host.UI.Writeline('host')
111
- eos
112
-
113
- @captured_stdout = ''
114
- @captured_stderr = ''
115
- @powershell.run(script) do |stdout, stderr|
116
- @captured_stdout << stdout if stdout
117
- @captured_stderr << stderr if stderr
118
- end
119
- end
120
-
121
- it 'should print from the pipeline first' do
122
- expect(output.stdout).to start_with("output\r\n")
123
- end
124
-
125
- it 'should write to host last' do
126
- expect(output.stdout).to end_with("host\r\n")
127
- end
128
- end
129
-
130
- describe 'it should handle utf-8 characters' do
131
- subject(:output) { @powershell.run('echo "✓1234-äöü"') }
132
- it { should have_exit_code 0 }
133
- it { should have_stdout_match(/✓1234-äöü/) }
134
- end
135
-
136
- describe 'output exceeds a single fragment' do
137
- subject(:output) { @powershell.run('Write-Output $("a"*600000)') }
138
- it { should have_exit_code 0 }
139
- it 'has assebled the output' do
140
- expect(output.stdout).to eq('a' * 600000 + "\r\n")
141
- end
142
- end
143
-
144
- describe 'command exceeds a single fragment' do
145
- subject(:output) { @powershell.run("$var='#{'a' * 600000}';Write-Output 'long var'") }
146
- it { should have_exit_code 0 }
147
- it 'has sent the output' do
148
- expect(output.stdout).to eq("long var\r\n")
149
- end
150
- end
151
-
152
- describe 'reading pipeline messages' do
153
- subject(:messages) { @powershell.send_pipeline_command('ipconfig') }
154
-
155
- it 'returns multiple messages' do
156
- expect(messages.length).to be > 1
157
- end
158
- it 'first message is pipeline output' do
159
- expect(messages.first.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output])
160
- end
161
- it 'last message is pipeline state' do
162
- expect(messages.last.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state])
163
- end
164
- end
165
- end
@@ -1,65 +0,0 @@
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,99 +0,0 @@
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
@@ -1,34 +0,0 @@
1
- # encoding: UTF-8
2
- require_relative 'spec_helper'
3
-
4
- describe 'winrm client wql' do
5
- before(:all) do
6
- @winrm = winrm_connection
7
- end
8
-
9
- it 'should query Win32_OperatingSystem' do
10
- output = @winrm.run_wql('select * from Win32_OperatingSystem')
11
- expect(output).to_not be_empty
12
- output_caption = output[:win32_operating_system][0][:caption]
13
- expect(output_caption).to include('Microsoft')
14
- expect(output_caption).to include('Windows')
15
- end
16
-
17
- it 'should query Win32_Process' do
18
- output = @winrm.run_wql('select * from Win32_Process')
19
- expect(output).to_not be_empty
20
- process_count = output[:win32_process].count
21
- expect(process_count).to be > 1
22
- expect(output[:win32_process]).to all(include(:command_line))
23
- end
24
-
25
- it 'should query Win32_Process with block' do
26
- count = 0
27
- @winrm.run_wql('select * from Win32_Process') do |type, item|
28
- expect(type).to eq(:win32_process)
29
- expect(item).to include(:command_line)
30
- count += 1
31
- end
32
- expect(count).to be > 1
33
- end
34
- end
data/tests/matchers.rb DELETED
@@ -1,60 +0,0 @@
1
- # encoding: UTF-8
2
- require 'rspec/expectations'
3
-
4
- # rspec matchers
5
- RSpec::Matchers.define :have_stdout_match do |expected_stdout|
6
- match do |actual_output|
7
- !expected_stdout.match(actual_output.stdout).nil?
8
- end
9
- failure_message do |actual_output|
10
- "expected that '#{actual_output.stdout}' would match #{expected_stdout}"
11
- end
12
- end
13
-
14
- RSpec::Matchers.define :have_stderr_match do |expected_stderr|
15
- match do |actual_output|
16
- !expected_stderr.match(actual_output.stderr).nil?
17
- end
18
- failure_message do |actual_output|
19
- "expected that '#{actual_output.stderr}' would match #{expected_stderr}"
20
- end
21
- end
22
-
23
- RSpec::Matchers.define :have_no_stdout do
24
- match do |actual_output|
25
- stdout = actual_output.stdout
26
- stdout == '\r\n' || stdout == ''
27
- end
28
- failure_message do |actual_output|
29
- "expected that '#{actual_output.stdout}' would have no stdout"
30
- end
31
- end
32
-
33
- RSpec::Matchers.define :have_no_stderr do
34
- match do |actual_output|
35
- stderr = actual_output.stderr
36
- stderr == '\r\n' || stderr == ''
37
- end
38
- failure_message do |actual_output|
39
- "expected that '#{actual_output.stderr}' would have no stderr"
40
- end
41
- end
42
-
43
- RSpec::Matchers.define :have_exit_code do |expected_exit_code|
44
- match do |actual_output|
45
- expected_exit_code == actual_output.exitcode
46
- end
47
- failure_message do |actual_output|
48
- "expected exit code #{expected_exit_code}, but got #{actual_output.exitcode}"
49
- end
50
- end
51
-
52
- RSpec::Matchers.define :be_a_uid do
53
- match do |actual|
54
- # WinRM1.1 returns uuid's prefixed with 'uuid:' where as later versions do not
55
- actual && actual.to_s.match(/^(uuid:)*\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/)
56
- end
57
- failure_message do |actual|
58
- "expected a uid, but got '#{actual}'"
59
- end
60
- end