winrm 2.2.3 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +13 -1
  3. data/.travis.yml +10 -11
  4. data/Gemfile +2 -3
  5. data/README.md +1 -1
  6. data/Rakefile +3 -4
  7. data/appveyor.yml +1 -2
  8. data/bin/rwinrm +90 -97
  9. data/changelog.md +5 -0
  10. data/lib/winrm.rb +3 -5
  11. data/lib/winrm/connection.rb +84 -86
  12. data/lib/winrm/connection_opts.rb +90 -91
  13. data/lib/winrm/exceptions.rb +14 -2
  14. data/lib/winrm/http/response_handler.rb +127 -96
  15. data/lib/winrm/http/transport.rb +462 -427
  16. data/lib/winrm/http/transport_factory.rb +1 -5
  17. data/lib/winrm/output.rb +1 -2
  18. data/lib/winrm/psrp/fragment.rb +0 -2
  19. data/lib/winrm/psrp/message.rb +1 -3
  20. data/lib/winrm/psrp/message_data.rb +0 -2
  21. data/lib/winrm/psrp/message_data/base.rb +0 -2
  22. data/lib/winrm/psrp/message_data/error_record.rb +0 -2
  23. data/lib/winrm/psrp/message_data/pipeline_host_call.rb +0 -2
  24. data/lib/winrm/psrp/message_data/pipeline_output.rb +48 -54
  25. data/lib/winrm/psrp/message_data/pipeline_state.rb +0 -2
  26. data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +0 -2
  27. data/lib/winrm/psrp/message_data/runspacepool_state.rb +0 -2
  28. data/lib/winrm/psrp/message_data/session_capability.rb +0 -2
  29. data/lib/winrm/psrp/message_defragmenter.rb +2 -2
  30. data/lib/winrm/psrp/message_factory.rb +2 -3
  31. data/lib/winrm/psrp/message_fragmenter.rb +1 -3
  32. data/lib/winrm/psrp/powershell_output_decoder.rb +0 -2
  33. data/lib/winrm/psrp/receive_response_reader.rb +3 -5
  34. data/lib/winrm/psrp/uuid.rb +1 -2
  35. data/lib/winrm/shells/base.rb +6 -4
  36. data/lib/winrm/shells/cmd.rb +63 -65
  37. data/lib/winrm/shells/power_shell.rb +207 -202
  38. data/lib/winrm/shells/retryable.rb +44 -45
  39. data/lib/winrm/shells/shell_factory.rb +0 -2
  40. data/lib/winrm/version.rb +1 -3
  41. data/lib/winrm/wsmv/base.rb +0 -2
  42. data/lib/winrm/wsmv/cleanup_command.rb +1 -2
  43. data/lib/winrm/wsmv/close_shell.rb +1 -2
  44. data/lib/winrm/wsmv/command.rb +2 -3
  45. data/lib/winrm/wsmv/command_output.rb +2 -3
  46. data/lib/winrm/wsmv/command_output_decoder.rb +1 -2
  47. data/lib/winrm/wsmv/configuration.rb +0 -2
  48. data/lib/winrm/wsmv/create_pipeline.rb +0 -2
  49. data/lib/winrm/wsmv/create_shell.rb +2 -6
  50. data/lib/winrm/wsmv/header.rb +213 -215
  51. data/lib/winrm/wsmv/init_runspace_pool.rb +96 -95
  52. data/lib/winrm/wsmv/iso8601_duration.rb +0 -2
  53. data/lib/winrm/wsmv/keep_alive.rb +0 -2
  54. data/lib/winrm/wsmv/receive_response_reader.rb +128 -126
  55. data/lib/winrm/wsmv/send_data.rb +0 -2
  56. data/lib/winrm/wsmv/soap.rb +0 -2
  57. data/lib/winrm/wsmv/wql_pull.rb +54 -56
  58. data/lib/winrm/wsmv/wql_query.rb +98 -99
  59. data/lib/winrm/wsmv/write_stdin.rb +0 -2
  60. data/tests/integration/auth_timeout_spec.rb +0 -1
  61. data/tests/integration/cmd_spec.rb +2 -3
  62. data/tests/integration/issue_59_spec.rb +0 -1
  63. data/tests/integration/powershell_spec.rb +4 -5
  64. data/tests/integration/spec_helper.rb +3 -6
  65. data/tests/integration/transport_spec.rb +0 -1
  66. data/tests/integration/wql_spec.rb +33 -34
  67. data/tests/matchers.rb +2 -3
  68. data/tests/spec/configuration_spec.rb +0 -1
  69. data/tests/spec/connection_spec.rb +0 -2
  70. data/tests/spec/exception_spec.rb +0 -1
  71. data/tests/spec/http/transport_factory_spec.rb +1 -3
  72. data/tests/spec/http/transport_spec.rb +0 -1
  73. data/tests/spec/output_spec.rb +4 -3
  74. data/tests/spec/psrp/fragment_spec.rb +0 -2
  75. data/tests/spec/psrp/message_data/base_spec.rb +0 -2
  76. data/tests/spec/psrp/message_data/error_record_spec.rb +0 -2
  77. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -2
  78. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -2
  79. data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -2
  80. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -2
  81. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -2
  82. data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -2
  83. data/tests/spec/psrp/message_data_spec.rb +0 -2
  84. data/tests/spec/psrp/message_defragmenter_spec.rb +0 -2
  85. data/tests/spec/psrp/message_fragmenter_spec.rb +0 -2
  86. data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -2
  87. data/tests/spec/psrp/psrp_message_spec.rb +10 -7
  88. data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -2
  89. data/tests/spec/psrp/uuid_spec.rb +2 -2
  90. data/tests/spec/response_handler_spec.rb +69 -61
  91. data/tests/spec/shells/base_spec.rb +7 -5
  92. data/tests/spec/shells/cmd_spec.rb +4 -4
  93. data/tests/spec/shells/powershell_spec.rb +221 -175
  94. data/tests/spec/spec_helper.rb +0 -1
  95. data/tests/spec/stubs/responses/get_omi_command_output_response.xml.erb +23 -0
  96. data/tests/spec/stubs/responses/get_omi_command_output_response_not_done.xml.erb +24 -0
  97. data/tests/spec/stubs/responses/get_omi_config_response.xml +45 -0
  98. data/tests/spec/stubs/responses/get_omi_powershell_keepalive_response.xml.erb +33 -0
  99. data/tests/spec/stubs/responses/open_shell_omi.xml +43 -0
  100. data/tests/spec/stubs/responses/soap_fault_omi.xml +31 -0
  101. data/tests/spec/wsmv/cleanup_command_spec.rb +0 -2
  102. data/tests/spec/wsmv/close_shell_spec.rb +0 -2
  103. data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -2
  104. data/tests/spec/wsmv/command_output_spec.rb +1 -3
  105. data/tests/spec/wsmv/command_spec.rb +0 -2
  106. data/tests/spec/wsmv/configuration_spec.rb +0 -2
  107. data/tests/spec/wsmv/create_pipeline_spec.rb +2 -3
  108. data/tests/spec/wsmv/create_shell_spec.rb +6 -5
  109. data/tests/spec/wsmv/init_runspace_pool_spec.rb +38 -36
  110. data/tests/spec/wsmv/keep_alive_spec.rb +4 -4
  111. data/tests/spec/wsmv/receive_response_reader_spec.rb +124 -123
  112. data/tests/spec/wsmv/send_data_spec.rb +4 -4
  113. data/tests/spec/wsmv/wql_query_spec.rb +11 -13
  114. data/tests/spec/wsmv/write_stdin_spec.rb +0 -2
  115. data/winrm.gemspec +11 -12
  116. metadata +73 -67
@@ -1,175 +1,221 @@
1
- # encoding: UTF-8
2
-
3
- require 'winrm/shells/power_shell'
4
-
5
- describe WinRM::Shells::Powershell do
6
- let(:retry_limit) { 1 }
7
- let(:max_envelope_size_kb) { 150 }
8
- let(:shell_id) { 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16' }
9
- let(:output) { 'output' }
10
- let(:command_id) { '4218A578-0F18-4B19-82C3-46B433319126' }
11
- let(:keepalive_payload) { 'keepalive_payload' }
12
- let(:configuration_payload) { 'configuration_payload' }
13
- let(:command_payload) { 'command_payload' }
14
- let(:create_shell_payload) { 'create_shell_payload' }
15
- let(:close_shell_payload) { 'close_shell_payload' }
16
- let(:cleanup_payload) { 'cleanup_payload' }
17
- let(:command) { 'command' }
18
- let(:output_message) { double('output_message', build: 'output_message') }
19
- let(:command_response) { "<a xmlns:rsp='foo'><rsp:CommandId>#{command_id}</rsp:CommandId></a>" }
20
- let(:configuration_response) do
21
- "<a xmlns:cfg='foo'><cfg:MaxEnvelopeSizekb>#{max_envelope_size_kb}</cfg:MaxEnvelopeSizekb></a>"
22
- end
23
- let(:connection_options) { { max_commands: 100, retry_limit: retry_limit, retry_delay: 0 } }
24
- let(:transport) { double('transport', send_request: nil) }
25
- let(:test_data_xml_template) do
26
- ERB.new(stubbed_response('get_powershell_keepalive_response.xml.erb'))
27
- end
28
- let(:protocol_version) { 2.2 }
29
- let(:test_data1) do
30
- <<-EOH
31
- <Obj RefId="0">
32
- <MS>
33
- <Version N="protocolversion">#{protocol_version}</Version>
34
- <Version N="PSVersion">2.0</Version>
35
- <Version N="SerializationVersion">1.1.0.1</Version>
36
- </MS>
37
- </Obj>
38
- EOH
39
- end
40
- let(:test_data2) { '<Obj RefId="0"><MS><I32 N="RunspaceState">2</I32></MS></Obj>' }
41
- let(:message1) do
42
- WinRM::PSRP::Message.new(
43
- shell_id,
44
- WinRM::PSRP::Message::MESSAGE_TYPES[:session_capability],
45
- test_data1,
46
- command_id
47
- )
48
- end
49
- let(:message2) do
50
- WinRM::PSRP::Message.new(
51
- shell_id,
52
- WinRM::PSRP::Message::MESSAGE_TYPES[:runspacepool_state],
53
- test_data2,
54
- command_id
55
- )
56
- end
57
- let(:fragment1) { WinRM::PSRP::Fragment.new(1, message1.bytes) }
58
- let(:fragment2) { WinRM::PSRP::Fragment.new(1, message2.bytes) }
59
- let(:test_data_stdout1) { Base64.strict_encode64(fragment1.bytes.pack('C*')) }
60
- let(:test_data_stdout2) { Base64.strict_encode64(fragment2.bytes.pack('C*')) }
61
-
62
- before do
63
- allow(SecureRandom).to receive(:uuid).and_return(command_id)
64
- allow(subject).to receive(:command_output_message).with(shell_id, command_id)
65
- .and_return(output_message)
66
- allow_any_instance_of(WinRM::WSMV::CreatePipeline).to receive(:build)
67
- .and_return(command_payload)
68
- allow_any_instance_of(WinRM::WSMV::CloseShell).to receive(:build)
69
- .and_return(close_shell_payload)
70
- allow_any_instance_of(WinRM::WSMV::InitRunspacePool).to receive(:build)
71
- .and_return(create_shell_payload)
72
- allow_any_instance_of(WinRM::WSMV::Configuration).to receive(:build)
73
- .and_return(configuration_payload)
74
- allow_any_instance_of(WinRM::WSMV::CleanupCommand).to receive(:build)
75
- .and_return(cleanup_payload)
76
- allow_any_instance_of(WinRM::WSMV::KeepAlive).to receive(:build).and_return(keepalive_payload)
77
- allow_any_instance_of(WinRM::PSRP::ReceiveResponseReader).to receive(:read_output)
78
- .with(output_message).and_return(output)
79
- allow(transport).to receive(:send_request).with(configuration_payload).and_return(
80
- REXML::Document.new(configuration_response))
81
- allow(transport).to receive(:send_request).with(create_shell_payload)
82
- .and_return(REXML::Document.new("<blah Name='ShellId'>#{shell_id}</blah>"))
83
- allow(transport).to receive(:send_request).with(command_payload)
84
- .and_return(REXML::Document.new(command_response))
85
- allow(transport).to receive(:send_request).with(keepalive_payload)
86
- .and_return(REXML::Document.new(test_data_xml_template.result(binding)))
87
- end
88
-
89
- subject { described_class.new(connection_options, transport, Logging.logger['test']) }
90
-
91
- describe '#run' do
92
- it 'opens a shell and gets shell id' do
93
- subject.run(command)
94
- expect(subject.shell_id).to eq shell_id
95
- end
96
-
97
- it 'sends create shell through transport' do
98
- expect(transport).to receive(:send_request).with(create_shell_payload)
99
- subject.run(command)
100
- end
101
-
102
- it 'sends keepalive shell through transport' do
103
- expect(transport).to receive(:send_request).with(keepalive_payload)
104
- subject.run(command)
105
- end
106
-
107
- it 'returns output from generated command' do
108
- expect(subject.run(command)).to eq output
109
- end
110
-
111
- it 'sends command through transport' do
112
- expect(transport).to receive(:send_request).with(command_payload)
113
- subject.run(command)
114
- end
115
-
116
- it 'sends cleanup message through transport' do
117
- expect(transport).to receive(:send_request).with(cleanup_payload)
118
- subject.run(command)
119
- end
120
-
121
- context 'non admin user' do
122
- before do
123
- allow(transport).to receive(:send_request).with(configuration_payload)
124
- .and_raise(WinRM::WinRMWSManFault.new('no access for you', '5'))
125
- end
126
-
127
- context 'protocol version 2.1' do
128
- let(:protocol_version) { 2.1 }
129
-
130
- it 'sets the fragmenter max_blob_length' do
131
- expect_any_instance_of(WinRM::PSRP::MessageFragmenter).to receive(:max_blob_length=)
132
- .with(153600)
133
- subject.run(command)
134
- end
135
- end
136
-
137
- context 'protocol version 2.2' do
138
- let(:protocol_version) { 2.2 }
139
-
140
- it 'sets the fragmenter max_blob_length' do
141
- expect_any_instance_of(WinRM::PSRP::MessageFragmenter).to receive(:max_blob_length=)
142
- .with(512000)
143
- subject.run(command)
144
- end
145
- end
146
- end
147
-
148
- context 'fragment large command' do
149
- let(:command) { 'c' * 200000 }
150
-
151
- it 'fragments messages as large as max envelope size' do
152
- allow_any_instance_of(WinRM::WSMV::CreatePipeline).to receive(:build).and_call_original
153
- allow(transport).to receive(:send_request).with(/CommandLine/) do |payload|
154
- expect(payload.length).to be max_envelope_size_kb * 1024
155
- end.and_return(REXML::Document.new(command_response))
156
- subject.run(command)
157
- end
158
- end
159
- end
160
-
161
- describe '#close' do
162
- it 'sends close shell through transport' do
163
- subject.run(command)
164
- expect(transport).to receive(:send_request).with(close_shell_payload)
165
- subject.close
166
- end
167
-
168
- it 'creates a shell closer with powershell uri' do
169
- allow(WinRM::WSMV::CloseShell).to receive(:new) do |_, opts|
170
- expect(opts[:shell_uri]).to be WinRM::WSMV::Header::RESOURCE_URI_POWERSHELL
171
- end.and_call_original
172
- subject.close
173
- end
174
- end
175
- end
1
+ require 'winrm/shells/power_shell'
2
+
3
+ describe WinRM::Shells::Powershell do
4
+ let(:retry_limit) { 1 }
5
+ let(:max_envelope_size_kb) { 150 }
6
+ let(:shell_id) { 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16' }
7
+ let(:output) { 'output' }
8
+ let(:command_id) { '4218A578-0F18-4B19-82C3-46B433319126' }
9
+ let(:keepalive_payload) { 'keepalive_payload' }
10
+ let(:configuration_payload) { 'configuration_payload' }
11
+ let(:command_payload) { 'command_payload' }
12
+ let(:create_shell_payload) { 'create_shell_payload' }
13
+ let(:close_shell_payload) { 'close_shell_payload' }
14
+ let(:cleanup_payload) { 'cleanup_payload' }
15
+ let(:command) { 'command' }
16
+ let(:output_message) { double('output_message', build: 'output_message') }
17
+ let(:connection_options) { { max_commands: 100, retry_limit: retry_limit, retry_delay: 0 } }
18
+ let(:transport) { double('transport', send_request: nil) }
19
+ let(:protocol_version) { 2.2 }
20
+ let(:test_data1) do
21
+ <<-EOH
22
+ <Obj RefId="0">
23
+ <MS>
24
+ <Version N="protocolversion">#{protocol_version}</Version>
25
+ <Version N="PSVersion">2.0</Version>
26
+ <Version N="SerializationVersion">1.1.0.1</Version>
27
+ </MS>
28
+ </Obj>
29
+ EOH
30
+ end
31
+ let(:test_data2) { '<Obj RefId="0"><MS><I32 N="RunspaceState">2</I32></MS></Obj>' }
32
+ let(:message1) do
33
+ WinRM::PSRP::Message.new(
34
+ shell_id,
35
+ WinRM::PSRP::Message::MESSAGE_TYPES[:session_capability],
36
+ test_data1,
37
+ command_id
38
+ )
39
+ end
40
+ let(:message2) do
41
+ WinRM::PSRP::Message.new(
42
+ shell_id,
43
+ WinRM::PSRP::Message::MESSAGE_TYPES[:runspacepool_state],
44
+ test_data2,
45
+ command_id
46
+ )
47
+ end
48
+ let(:fragment1) { WinRM::PSRP::Fragment.new(1, message1.bytes) }
49
+ let(:fragment2) { WinRM::PSRP::Fragment.new(1, message2.bytes) }
50
+ let(:test_data_stdout1) { Base64.strict_encode64(fragment1.bytes.pack('C*')) }
51
+ let(:test_data_stdout2) { Base64.strict_encode64(fragment2.bytes.pack('C*')) }
52
+
53
+ {
54
+ 'powershell' => {
55
+ keepalive_template_path: 'get_powershell_keepalive_response.xml.erb',
56
+ config: "<a xmlns:cfg='f'><cfg:MaxEnvelopeSizekb>" \
57
+ '<%= max_envelope_size_kb %></cfg:MaxEnvelopeSizekb></a>',
58
+ command: "<a xmlns:rsp='foo'><rsp:CommandId><%= command_id %></rsp:CommandId></a>"
59
+ },
60
+ 'omi' => {
61
+ keepalive_template_path: 'get_omi_powershell_keepalive_response.xml.erb',
62
+ config: File.read('tests/spec/stubs/responses/get_omi_config_response.xml'),
63
+ command: "<p:CommandResponse xmlns:p='foo'><p:CommandId>" \
64
+ '<%= command_id %></p:CommandId></p:CommandResponse>'
65
+ }
66
+ }.each_pair do |server_type, response|
67
+ context "with server type #{server_type}" do
68
+ let(:command_response) { ERB.new(response[:command]).result(binding) }
69
+
70
+ before do
71
+ config_response = ERB.new(response[:config]).result(binding)
72
+ test_data_xml_template = ERB.new(stubbed_response(response[:keepalive_template_path]))
73
+
74
+ allow(SecureRandom).to receive(:uuid).and_return(command_id)
75
+ allow(subject).to receive(:command_output_message)
76
+ .with(shell_id, command_id)
77
+ .and_return(output_message)
78
+ allow_any_instance_of(WinRM::WSMV::CreatePipeline).to receive(:build)
79
+ .and_return(command_payload)
80
+ allow_any_instance_of(WinRM::WSMV::CloseShell).to receive(:build)
81
+ .and_return(close_shell_payload)
82
+ allow_any_instance_of(WinRM::WSMV::InitRunspacePool).to receive(:build)
83
+ .and_return(create_shell_payload)
84
+ allow_any_instance_of(WinRM::WSMV::Configuration).to receive(:build)
85
+ .and_return(configuration_payload)
86
+ allow_any_instance_of(WinRM::WSMV::CleanupCommand).to receive(:build)
87
+ .and_return(cleanup_payload)
88
+ allow_any_instance_of(WinRM::WSMV::KeepAlive).to receive(:build)
89
+ .and_return(keepalive_payload)
90
+ allow_any_instance_of(WinRM::PSRP::ReceiveResponseReader).to receive(:read_output)
91
+ .with(output_message).and_return(output)
92
+ allow(transport).to receive(:send_request).with(configuration_payload) do |_|
93
+ # parse real XML with ResponseHandler to raise WinRMSoapFault
94
+ WinRM::ResponseHandler.new(config_response, 500).parse_to_xml if server_type == 'omi'
95
+ REXML::Document.new(config_response)
96
+ end
97
+ allow(transport).to receive(:send_request)
98
+ .with(create_shell_payload)
99
+ .and_return(REXML::Document.new("<blah Name='ShellId'>#{shell_id}</blah>"))
100
+ allow(transport).to receive(:send_request)
101
+ .with(command_payload)
102
+ .and_return(REXML::Document.new(command_response))
103
+ allow(transport).to receive(:send_request)
104
+ .with(keepalive_payload)
105
+ .and_return(REXML::Document.new(test_data_xml_template.result(binding)))
106
+ end
107
+
108
+ subject { described_class.new(connection_options, transport, Logging.logger['test']) }
109
+
110
+ describe '#run' do
111
+ it 'opens a shell and gets shell id' do
112
+ subject.run(command)
113
+ expect(subject.shell_id).to eq shell_id
114
+ end
115
+
116
+ it 'sends create shell through transport' do
117
+ expect(transport).to receive(:send_request).with(create_shell_payload)
118
+ subject.run(command)
119
+ end
120
+
121
+ it 'sends keepalive shell through transport' do
122
+ expect(transport).to receive(:send_request).with(keepalive_payload)
123
+ subject.run(command)
124
+ end
125
+
126
+ it 'returns output from generated command' do
127
+ expect(subject.run(command)).to eq output
128
+ end
129
+
130
+ it 'sends command through transport' do
131
+ expect(transport).to receive(:send_request).with(command_payload)
132
+ subject.run(command)
133
+ end
134
+
135
+ it 'sends cleanup message through transport' do
136
+ expect(transport).to receive(:send_request).with(cleanup_payload)
137
+ subject.run(command)
138
+ end
139
+
140
+ # OMI server doesn't respond to configuration so these tests are irrelevant there
141
+ context 'non admin user', if: server_type == 'powershell' do
142
+ before do
143
+ allow(transport).to receive(:send_request)
144
+ .with(configuration_payload)
145
+ .and_raise(WinRM::WinRMWSManFault.new('no access for you', '5'))
146
+ end
147
+
148
+ context 'protocol version 2.1' do
149
+ let(:protocol_version) { 2.1 }
150
+ let(:command) { 'c' * 200000 }
151
+
152
+ it 'sets the fragmenter max_blob_length' do
153
+ expect_any_instance_of(WinRM::PSRP::MessageFragmenter).to receive(:max_blob_length=)
154
+ .with(153600)
155
+ subject.run(command)
156
+ end
157
+
158
+ it 'fragments messages smaller than max envelope size' do
159
+ allow_any_instance_of(WinRM::WSMV::CreatePipeline).to receive(:build)
160
+ .and_call_original
161
+ allow(transport).to receive(:send_request).with(/CommandLine/) do |payload|
162
+ expect(payload.length).to eq 206512
163
+ end.and_return(REXML::Document.new(command_response))
164
+ subject.run(command)
165
+ end
166
+ end
167
+
168
+ context 'protocol version 2.2' do
169
+ let(:protocol_version) { 2.2 }
170
+ let(:command) { 'c' * 200000 }
171
+
172
+ it 'sets the fragmenter max_blob_length' do
173
+ expect_any_instance_of(WinRM::PSRP::MessageFragmenter).to receive(:max_blob_length=)
174
+ .with(512000)
175
+ subject.run(command)
176
+ end
177
+
178
+ it 'fragments messages smaller than max envelope size' do
179
+ allow_any_instance_of(WinRM::WSMV::CreatePipeline).to receive(:build)
180
+ .and_call_original
181
+ allow(transport).to receive(:send_request).with(/CommandLine/) do |payload|
182
+ expect(payload.length).to eq 276028
183
+ end.and_return(REXML::Document.new(command_response))
184
+ subject.run(command)
185
+ end
186
+ end
187
+ end
188
+
189
+ context 'fragment large command' do
190
+ let(:command) { 'c' * 200000 }
191
+
192
+ it 'fragments messages as large as max envelope size' do
193
+ allow_any_instance_of(WinRM::WSMV::CreatePipeline).to receive(:build).and_call_original
194
+ allow(transport).to receive(:send_request).with(/CommandLine/) do |payload|
195
+ fallback = subject.max_fragment_blob_size ==
196
+ WinRM::PSRP::MessageFragmenter::DEFAULT_BLOB_LENGTH
197
+ # OMI server uses default blob size b/c config endpoint unavailable
198
+ expect(payload.length).to eq fallback ? 45404 : max_envelope_size_kb * 1024
199
+ end.and_return(REXML::Document.new(command_response))
200
+ subject.run(command)
201
+ end
202
+ end
203
+ end
204
+
205
+ describe '#close' do
206
+ it 'sends close shell through transport' do
207
+ subject.run(command)
208
+ expect(transport).to receive(:send_request).with(close_shell_payload)
209
+ subject.close
210
+ end
211
+
212
+ it 'creates a shell closer with powershell uri' do
213
+ allow(WinRM::WSMV::CloseShell).to receive(:new) do |_, opts|
214
+ expect(opts[:shell_uri]).to be WinRM::WSMV::Header::RESOURCE_URI_POWERSHELL
215
+ end.and_call_original
216
+ subject.close
217
+ end
218
+ end
219
+ end
220
+ end
221
+ end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'rubygems'
3
2
  require 'bundler/setup'
4
3
  require 'winrm'
@@ -0,0 +1,23 @@
1
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV='http://www.w3.org/2003/05/soap-envelope'
2
+ xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/08/addressing'
3
+ xmlns:wsen='http://schemas.xmlsoap.org/ws/2004/09/enumeration'
4
+ xmlns:e='http://schemas.xmlsoap.org/ws/2004/08/eventing'
5
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
6
+ xmlns:wsmb='http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd'
7
+ xmlns:wsman='http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd'
8
+ xmlns:wxf='http://schemas.xmlsoap.org/ws/2004/09/transfer'
9
+ xmlns:cim='http://schemas.dmtf.org/wbem/wscim/1/common'
10
+ xmlns:msftwinrm='http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd'
11
+ xmlns:wsmid='http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd'>
12
+ <SOAP-ENV:Header>
13
+ <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
14
+ <wsa:Action>http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse</wsa:Action>
15
+ <wsa:MessageID>uuid:5825BEA8-76AB-0005-0000-000000640000</wsa:MessageID>
16
+ <wsa:RelatesTo>uuid:E22E9766-0817-4056-99F8-EB5997BC2138</wsa:RelatesTo>
17
+ </SOAP-ENV:Header>
18
+ <SOAP-ENV:Body>
19
+ <p:ReceiveResponse xmlns:p='http://schemas.microsoft.com/wbem/wsman/1/windows/shell'>
20
+ <p:CommandState State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done'/>
21
+ </p:ReceiveResponse>
22
+ </SOAP-ENV:Body>
23
+ </SOAP-ENV:Envelope>
@@ -0,0 +1,24 @@
1
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV='http://www.w3.org/2003/05/soap-envelope'
2
+ xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/08/addressing'
3
+ xmlns:wsen='http://schemas.xmlsoap.org/ws/2004/09/enumeration'
4
+ xmlns:e='http://schemas.xmlsoap.org/ws/2004/08/eventing'
5
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
6
+ xmlns:wsmb='http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd'
7
+ xmlns:wsman='http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd'
8
+ xmlns:wxf='http://schemas.xmlsoap.org/ws/2004/09/transfer'
9
+ xmlns:cim='http://schemas.dmtf.org/wbem/wscim/1/common'
10
+ xmlns:msftwinrm='http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd'
11
+ xmlns:wsmid='http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd'>
12
+ <SOAP-ENV:Header>
13
+ <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
14
+ <wsa:Action>http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse</wsa:Action>
15
+ <wsa:MessageID>uuid:5825BEA8-76AB-0005-0000-000000640000</wsa:MessageID>
16
+ <wsa:RelatesTo>uuid:E22E9766-0817-4056-99F8-EB5997BC2138</wsa:RelatesTo>
17
+ </SOAP-ENV:Header>
18
+ <SOAP-ENV:Body>
19
+ <p:ReceiveResponse xmlns:p='http://schemas.microsoft.com/wbem/wsman/1/windows/shell'>
20
+ <p:Stream Name='stdout'><%= test_data_stdout %></p:Stream>
21
+ <p:CommandState State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Running'/>
22
+ </p:ReceiveResponse>
23
+ </SOAP-ENV:Body>
24
+ </SOAP-ENV:Envelope>