winrm 2.2.3 → 2.3.0
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.
- checksums.yaml +5 -5
- data/.rubocop.yml +13 -1
- data/.travis.yml +10 -11
- data/Gemfile +2 -3
- data/README.md +1 -1
- data/Rakefile +3 -4
- data/appveyor.yml +1 -2
- data/bin/rwinrm +90 -97
- data/changelog.md +5 -0
- data/lib/winrm.rb +3 -5
- data/lib/winrm/connection.rb +84 -86
- data/lib/winrm/connection_opts.rb +90 -91
- data/lib/winrm/exceptions.rb +14 -2
- data/lib/winrm/http/response_handler.rb +127 -96
- data/lib/winrm/http/transport.rb +462 -427
- data/lib/winrm/http/transport_factory.rb +1 -5
- data/lib/winrm/output.rb +1 -2
- data/lib/winrm/psrp/fragment.rb +0 -2
- data/lib/winrm/psrp/message.rb +1 -3
- data/lib/winrm/psrp/message_data.rb +0 -2
- data/lib/winrm/psrp/message_data/base.rb +0 -2
- data/lib/winrm/psrp/message_data/error_record.rb +0 -2
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +0 -2
- data/lib/winrm/psrp/message_data/pipeline_output.rb +48 -54
- data/lib/winrm/psrp/message_data/pipeline_state.rb +0 -2
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +0 -2
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +0 -2
- data/lib/winrm/psrp/message_data/session_capability.rb +0 -2
- data/lib/winrm/psrp/message_defragmenter.rb +2 -2
- data/lib/winrm/psrp/message_factory.rb +2 -3
- data/lib/winrm/psrp/message_fragmenter.rb +1 -3
- data/lib/winrm/psrp/powershell_output_decoder.rb +0 -2
- data/lib/winrm/psrp/receive_response_reader.rb +3 -5
- data/lib/winrm/psrp/uuid.rb +1 -2
- data/lib/winrm/shells/base.rb +6 -4
- data/lib/winrm/shells/cmd.rb +63 -65
- data/lib/winrm/shells/power_shell.rb +207 -202
- data/lib/winrm/shells/retryable.rb +44 -45
- data/lib/winrm/shells/shell_factory.rb +0 -2
- data/lib/winrm/version.rb +1 -3
- data/lib/winrm/wsmv/base.rb +0 -2
- data/lib/winrm/wsmv/cleanup_command.rb +1 -2
- data/lib/winrm/wsmv/close_shell.rb +1 -2
- data/lib/winrm/wsmv/command.rb +2 -3
- data/lib/winrm/wsmv/command_output.rb +2 -3
- data/lib/winrm/wsmv/command_output_decoder.rb +1 -2
- data/lib/winrm/wsmv/configuration.rb +0 -2
- data/lib/winrm/wsmv/create_pipeline.rb +0 -2
- data/lib/winrm/wsmv/create_shell.rb +2 -6
- data/lib/winrm/wsmv/header.rb +213 -215
- data/lib/winrm/wsmv/init_runspace_pool.rb +96 -95
- data/lib/winrm/wsmv/iso8601_duration.rb +0 -2
- data/lib/winrm/wsmv/keep_alive.rb +0 -2
- data/lib/winrm/wsmv/receive_response_reader.rb +128 -126
- data/lib/winrm/wsmv/send_data.rb +0 -2
- data/lib/winrm/wsmv/soap.rb +0 -2
- data/lib/winrm/wsmv/wql_pull.rb +54 -56
- data/lib/winrm/wsmv/wql_query.rb +98 -99
- data/lib/winrm/wsmv/write_stdin.rb +0 -2
- data/tests/integration/auth_timeout_spec.rb +0 -1
- data/tests/integration/cmd_spec.rb +2 -3
- data/tests/integration/issue_59_spec.rb +0 -1
- data/tests/integration/powershell_spec.rb +4 -5
- data/tests/integration/spec_helper.rb +3 -6
- data/tests/integration/transport_spec.rb +0 -1
- data/tests/integration/wql_spec.rb +33 -34
- data/tests/matchers.rb +2 -3
- data/tests/spec/configuration_spec.rb +0 -1
- data/tests/spec/connection_spec.rb +0 -2
- data/tests/spec/exception_spec.rb +0 -1
- data/tests/spec/http/transport_factory_spec.rb +1 -3
- data/tests/spec/http/transport_spec.rb +0 -1
- data/tests/spec/output_spec.rb +4 -3
- data/tests/spec/psrp/fragment_spec.rb +0 -2
- data/tests/spec/psrp/message_data/base_spec.rb +0 -2
- data/tests/spec/psrp/message_data/error_record_spec.rb +0 -2
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -2
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -2
- data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -2
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -2
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -2
- data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -2
- data/tests/spec/psrp/message_data_spec.rb +0 -2
- data/tests/spec/psrp/message_defragmenter_spec.rb +0 -2
- data/tests/spec/psrp/message_fragmenter_spec.rb +0 -2
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -2
- data/tests/spec/psrp/psrp_message_spec.rb +10 -7
- data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -2
- data/tests/spec/psrp/uuid_spec.rb +2 -2
- data/tests/spec/response_handler_spec.rb +69 -61
- data/tests/spec/shells/base_spec.rb +7 -5
- data/tests/spec/shells/cmd_spec.rb +4 -4
- data/tests/spec/shells/powershell_spec.rb +221 -175
- data/tests/spec/spec_helper.rb +0 -1
- data/tests/spec/stubs/responses/get_omi_command_output_response.xml.erb +23 -0
- data/tests/spec/stubs/responses/get_omi_command_output_response_not_done.xml.erb +24 -0
- data/tests/spec/stubs/responses/get_omi_config_response.xml +45 -0
- data/tests/spec/stubs/responses/get_omi_powershell_keepalive_response.xml.erb +33 -0
- data/tests/spec/stubs/responses/open_shell_omi.xml +43 -0
- data/tests/spec/stubs/responses/soap_fault_omi.xml +31 -0
- data/tests/spec/wsmv/cleanup_command_spec.rb +0 -2
- data/tests/spec/wsmv/close_shell_spec.rb +0 -2
- data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -2
- data/tests/spec/wsmv/command_output_spec.rb +1 -3
- data/tests/spec/wsmv/command_spec.rb +0 -2
- data/tests/spec/wsmv/configuration_spec.rb +0 -2
- data/tests/spec/wsmv/create_pipeline_spec.rb +2 -3
- data/tests/spec/wsmv/create_shell_spec.rb +6 -5
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +38 -36
- data/tests/spec/wsmv/keep_alive_spec.rb +4 -4
- data/tests/spec/wsmv/receive_response_reader_spec.rb +124 -123
- data/tests/spec/wsmv/send_data_spec.rb +4 -4
- data/tests/spec/wsmv/wql_query_spec.rb +11 -13
- data/tests/spec/wsmv/write_stdin_spec.rb +0 -2
- data/winrm.gemspec +11 -12
- metadata +73 -67
data/tests/matchers.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require 'rspec/expectations'
|
3
2
|
|
4
3
|
# rspec matchers
|
@@ -23,7 +22,7 @@ end
|
|
23
22
|
RSpec::Matchers.define :have_no_stdout do
|
24
23
|
match do |actual_output|
|
25
24
|
stdout = actual_output.stdout
|
26
|
-
|
25
|
+
['\r\n', ''].include?(stdout)
|
27
26
|
end
|
28
27
|
failure_message do |actual_output|
|
29
28
|
"expected that '#{actual_output.stdout}' would have no stdout"
|
@@ -33,7 +32,7 @@ end
|
|
33
32
|
RSpec::Matchers.define :have_no_stderr do
|
34
33
|
match do |actual_output|
|
35
34
|
stderr = actual_output.stderr
|
36
|
-
|
35
|
+
['\r\n', ''].include?(stderr)
|
37
36
|
end
|
38
37
|
failure_message do |actual_output|
|
39
38
|
"expected that '#{actual_output.stderr}' would have no stderr"
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require 'winrm/exceptions'
|
3
2
|
require 'winrm/http/transport_factory'
|
4
3
|
|
@@ -6,8 +5,7 @@ module WinRM
|
|
6
5
|
module HTTP
|
7
6
|
# Remove the gssapi stuff in kerberos init for tests
|
8
7
|
class HttpGSSAPI < HttpTransport
|
9
|
-
def initialize(endpoint, realm, opts, service = nil)
|
10
|
-
end
|
8
|
+
def initialize(endpoint, realm, opts, service = nil) end
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
data/tests/spec/output_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
describe WinRM::Output do
|
3
2
|
subject { WinRM::Output.new }
|
4
3
|
|
@@ -87,7 +86,8 @@ describe WinRM::Output do
|
|
87
86
|
describe '#stdout' do
|
88
87
|
it 'is equal to that line' do
|
89
88
|
expect(subject.stdout).to eq(
|
90
|
-
'I can have a newline\nanywhere, or stdout or nothing! (above)'
|
89
|
+
'I can have a newline\nanywhere, or stdout or nothing! (above)'
|
90
|
+
)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -101,7 +101,8 @@ describe WinRM::Output do
|
|
101
101
|
it 'is equal to stdout + stderr' do
|
102
102
|
expect(subject.output).to eq(
|
103
103
|
'I can have a newline\nanywhere, I can also have stderror stdout ' \
|
104
|
-
'and stderr or nothing! (above)'
|
104
|
+
'and stderr or nothing! (above)'
|
105
|
+
)
|
105
106
|
end
|
106
107
|
end
|
107
108
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
require 'winrm/psrp/message'
|
4
2
|
|
5
3
|
describe WinRM::PSRP::Message do
|
@@ -10,7 +8,8 @@ describe WinRM::PSRP::Message do
|
|
10
8
|
'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
|
11
9
|
WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output],
|
12
10
|
payload,
|
13
|
-
'4218a578-0f18-4b19-82c3-46b433319126'
|
11
|
+
'4218a578-0f18-4b19-82c3-46b433319126'
|
12
|
+
)
|
14
13
|
end
|
15
14
|
|
16
15
|
it 'sets the destination to server LE' do
|
@@ -21,11 +20,13 @@ describe WinRM::PSRP::Message do
|
|
21
20
|
end
|
22
21
|
it 'sets the runspace pool id' do
|
23
22
|
expect(subject.bytes[8..23]).to eq(
|
24
|
-
[186, 251, 27, 188, 21, 130, 4, 74, 178, 223, 122, 58, 192, 49, 14, 22]
|
23
|
+
[186, 251, 27, 188, 21, 130, 4, 74, 178, 223, 122, 58, 192, 49, 14, 22]
|
24
|
+
)
|
25
25
|
end
|
26
26
|
it 'sets the pipeline id' do
|
27
27
|
expect(subject.bytes[24..39]).to eq(
|
28
|
-
[120, 165, 24, 66, 24, 15, 25, 75, 130, 195, 70, 180, 51, 49, 145, 38]
|
28
|
+
[120, 165, 24, 66, 24, 15, 25, 75, 130, 195, 70, 180, 51, 49, 145, 38]
|
29
|
+
)
|
29
30
|
end
|
30
31
|
it 'prefixes the blob with BOM' do
|
31
32
|
expect(subject.bytes[40..42]).to eq([239, 187, 191])
|
@@ -45,7 +46,8 @@ describe WinRM::PSRP::Message do
|
|
45
46
|
'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
|
46
47
|
0x00000000,
|
47
48
|
%(<Obj RefId="0"/>),
|
48
|
-
'4218a578-0f18-4b19-82c3-46b433319126'
|
49
|
+
'4218a578-0f18-4b19-82c3-46b433319126'
|
50
|
+
)
|
49
51
|
end.to raise_error(RuntimeError)
|
50
52
|
end
|
51
53
|
end
|
@@ -60,7 +62,8 @@ describe WinRM::PSRP::Message do
|
|
60
62
|
WinRM::PSRP::Message.new(
|
61
63
|
'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
|
62
64
|
WinRM::PSRP::Message::MESSAGE_TYPES[:session_capability],
|
63
|
-
payload
|
65
|
+
payload
|
66
|
+
)
|
64
67
|
end
|
65
68
|
|
66
69
|
it 'sets the pipeline id to empty' do
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
describe WinRM::PSRP::UUID do
|
3
2
|
subject(:uuid_helper) do
|
4
3
|
Object.new.extend(WinRM::PSRP::UUID)
|
@@ -22,7 +21,8 @@ describe WinRM::PSRP::UUID do
|
|
22
21
|
it 'should return a Windows GUID struct compatible little endian byte array' do
|
23
22
|
bytes = uuid_helper.uuid_to_windows_guid_bytes(uuid)
|
24
23
|
expect(bytes).to eq(
|
25
|
-
[157, 225, 249, 69, 119, 139, 148, 67, 171, 12, 25, 116, 151, 102, 22, 104]
|
24
|
+
[157, 225, 249, 69, 119, 139, 148, 67, 171, 12, 25, 116, 151, 102, 22, 104]
|
25
|
+
)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -1,61 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
let(:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
xml_doc
|
14
|
-
expect(xml_doc).to
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
handler
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
handler
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
rescue WinRM::WinRMWSManFault => e
|
39
|
-
expect(e.fault_code).to eq('2150858778')
|
40
|
-
expect(e.fault_description).to include(
|
41
|
-
'The specified class does not exist in the given namespace'
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
1
|
+
require 'winrm/http/response_handler'
|
2
|
+
|
3
|
+
describe 'response handler', unit: true do
|
4
|
+
%w[v1 v2 omi].each do |winrm_version|
|
5
|
+
context "winrm_version #{winrm_version}" do
|
6
|
+
let(:soap_fault) { stubbed_response("soap_fault_#{winrm_version}.xml") }
|
7
|
+
let(:open_shell) { stubbed_response("open_shell_#{winrm_version}.xml") }
|
8
|
+
|
9
|
+
describe "successful 200 #{winrm_version} response" do
|
10
|
+
it 'returns an xml doc' do
|
11
|
+
handler = WinRM::ResponseHandler.new(open_shell, 200)
|
12
|
+
xml_doc = handler.parse_to_xml
|
13
|
+
expect(xml_doc).to be_instance_of(REXML::Document)
|
14
|
+
expect(xml_doc.to_s).to eq(REXML::Document.new(open_shell).to_s)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "failed 500 #{winrm_version} response" do
|
19
|
+
it 'raises a WinRMHTTPTransportError' do
|
20
|
+
handler = WinRM::ResponseHandler.new('', 500)
|
21
|
+
expect { handler.parse_to_xml }.to raise_error(WinRM::WinRMHTTPTransportError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "failed 401 #{winrm_version} response" do
|
26
|
+
it 'raises a WinRMAuthorizationError' do
|
27
|
+
handler = WinRM::ResponseHandler.new('', 401)
|
28
|
+
expect { handler.parse_to_xml }.to raise_error(WinRM::WinRMAuthorizationError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "failed 400 #{winrm_version} response" do
|
33
|
+
it 'raises a WinRMWSManFault' do
|
34
|
+
handler = WinRM::ResponseHandler.new(soap_fault, 400)
|
35
|
+
begin
|
36
|
+
handler.parse_to_xml
|
37
|
+
# PowerShell
|
38
|
+
rescue WinRM::WinRMWSManFault => e
|
39
|
+
expect(e.fault_code).to eq('2150858778')
|
40
|
+
expect(e.fault_description).to include(
|
41
|
+
'The specified class does not exist in the given namespace'
|
42
|
+
)
|
43
|
+
# OMI
|
44
|
+
rescue WinRM::WinRMSoapFault => e
|
45
|
+
expect(e.code).to eq('SOAP-ENV:Receiver')
|
46
|
+
expect(e.subcode).to eq('wsman:InternalError')
|
47
|
+
expect(e.reason).to eq(
|
48
|
+
'get-instance: instance name parameter is missing'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'failed 500 WMI error response' do
|
57
|
+
let(:wmi_error) { stubbed_response('wmi_error_v2.xml') }
|
58
|
+
|
59
|
+
it 'raises a WinRMWMIError' do
|
60
|
+
handler = WinRM::ResponseHandler.new(wmi_error, 500)
|
61
|
+
begin
|
62
|
+
handler.parse_to_xml
|
63
|
+
rescue WinRM::WinRMWMIError => e
|
64
|
+
expect(e.error_code).to eq('2150859173')
|
65
|
+
expect(e.error).to include('The WS-Management service cannot process the request.')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
require 'winrm/shells/base'
|
4
2
|
|
5
3
|
# Dummy shell class
|
@@ -28,7 +26,7 @@ class DummyShell < WinRM::Shells::Base
|
|
28
26
|
end
|
29
27
|
|
30
28
|
def out_streams
|
31
|
-
%w
|
29
|
+
%w[std]
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
@@ -47,7 +45,8 @@ describe DummyShell do
|
|
47
45
|
|
48
46
|
before do
|
49
47
|
allow(subject).to receive(:response_reader).and_return(reader)
|
50
|
-
allow(subject).to receive(:command_output_message)
|
48
|
+
allow(subject).to receive(:command_output_message)
|
49
|
+
.with(shell_id, command_id)
|
51
50
|
.and_return(output_message)
|
52
51
|
allow(reader).to receive(:read_output).with(output_message).and_return(output)
|
53
52
|
allow(transport).to receive(:send_request)
|
@@ -144,6 +143,7 @@ describe DummyShell do
|
|
144
143
|
allow(subject).to receive(:send_command) do
|
145
144
|
@times_called += 1
|
146
145
|
raise WinRM::WinRMWSManFault.new('oops', fault) if @times_called == 1
|
146
|
+
|
147
147
|
command_id
|
148
148
|
end
|
149
149
|
end
|
@@ -179,13 +179,15 @@ describe DummyShell do
|
|
179
179
|
|
180
180
|
it 'retries and returns shell on success' do
|
181
181
|
@times = 0
|
182
|
-
allow(subject).to receive(:command_output_message)
|
182
|
+
allow(subject).to receive(:command_output_message)
|
183
|
+
.with('shell_id 2', command_id)
|
183
184
|
.and_return(output_message2)
|
184
185
|
allow(reader).to receive(:read_output)
|
185
186
|
.with(output_message2).and_return(output)
|
186
187
|
allow(subject).to receive(:open_shell) do
|
187
188
|
@times += 1
|
188
189
|
raise(Errno::ECONNREFUSED) if @times == 1
|
190
|
+
|
189
191
|
"shell_id #{@times}"
|
190
192
|
end
|
191
193
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
require 'winrm/shells/cmd'
|
4
2
|
|
5
3
|
describe WinRM::Shells::Cmd do
|
@@ -24,9 +22,11 @@ describe WinRM::Shells::Cmd do
|
|
24
22
|
.and_return(cleanup_payload)
|
25
23
|
allow_any_instance_of(WinRM::WSMV::ReceiveResponseReader).to receive(:read_output)
|
26
24
|
.and_return(output)
|
27
|
-
allow(transport).to receive(:send_request)
|
25
|
+
allow(transport).to receive(:send_request)
|
26
|
+
.with(create_shell_payload)
|
28
27
|
.and_return(REXML::Document.new("<blah Name='ShellId'>#{shell_id}</blah>"))
|
29
|
-
allow(transport).to receive(:send_request)
|
28
|
+
allow(transport).to receive(:send_request)
|
29
|
+
.with(/#{command}/)
|
30
30
|
.and_return(REXML::Document.new(command_response))
|
31
31
|
end
|
32
32
|
|