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
@@ -0,0 +1,45 @@
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>
14
+ http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
15
+ </wsa:To>
16
+ <wsa:Action>
17
+ http://schemas.dmtf.org/wbem/wsman/1/wsman/fault
18
+ </wsa:Action>
19
+ <wsa:MessageID>
20
+ uuid:5825BEA8-76AB-0005-0000-000001A80000
21
+ </wsa:MessageID>
22
+ <wsa:RelatesTo>
23
+ uuid:01022086-C0D6-45DA-85F2-21FA2B476FCA
24
+ </wsa:RelatesTo>
25
+ </SOAP-ENV:Header>
26
+ <SOAP-ENV:Body>
27
+ <SOAP-ENV:Fault>
28
+ <SOAP-ENV:Code>
29
+ <SOAP-ENV:Value>
30
+ SOAP-ENV:Receiver
31
+ </SOAP-ENV:Value>
32
+ <SOAP-ENV:Subcode>
33
+ <SOAP-ENV:Value>
34
+ wsman:InternalError
35
+ </SOAP-ENV:Value>
36
+ </SOAP-ENV:Subcode>
37
+ </SOAP-ENV:Code>
38
+ <SOAP-ENV:Reason>
39
+ <SOAP-ENV:Text xml:lang="en-US">
40
+ get-instance: instance name parameter is missing
41
+ </SOAP-ENV:Text>
42
+ </SOAP-ENV:Reason>
43
+ </SOAP-ENV:Fault>
44
+ </SOAP-ENV:Body>
45
+ </SOAP-ENV:Envelope>
@@ -0,0 +1,33 @@
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>
14
+ http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
15
+ </wsa:To>
16
+ <wsa:Action>
17
+ http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse
18
+ </wsa:Action>
19
+ <wsa:MessageID>
20
+ uuid:5825BEA8-76AB-0005-0000-000000510000
21
+ </wsa:MessageID>
22
+ <wsa:RelatesTo>
23
+ uuid:28C42606-83D7-4948-A06A-47B75E7575D3
24
+ </wsa:RelatesTo>
25
+ </SOAP-ENV:Header>
26
+ <SOAP-ENV:Body>
27
+ <p:ReceiveResponse xmlns:p="http://schemas.microsoft.com/wbem/wsman/1/windows/shell">
28
+ <p:Stream Name="stdout"><%= test_data_stdout2 %></p:Stream>
29
+ <p:CommandState State="http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Running">
30
+ </p:CommandState>
31
+ </p:ReceiveResponse>
32
+ </SOAP-ENV:Body>
33
+ </SOAP-ENV:Envelope>
@@ -0,0 +1,43 @@
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>
14
+ http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
15
+ </wsa:To>
16
+ <wsa:Action>
17
+ http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse
18
+ </wsa:Action>
19
+ <wsa:MessageID>
20
+ uuid:5825BEA8-76AB-0005-0000-000001A90000
21
+ </wsa:MessageID>
22
+ <wsa:RelatesTo>
23
+ uuid:C872AD16-50F1-4CD3-908B-35AED7E485B7
24
+ </wsa:RelatesTo>
25
+ </SOAP-ENV:Header>
26
+ <SOAP-ENV:Body>
27
+ <wxf:ResourceCreated>
28
+ <wsa:Address>
29
+ http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
30
+ </wsa:Address>
31
+ <wsa:ReferenceParameters>
32
+ <wsman:ResourceURI>
33
+ http://schemas.microsoft.com/powershell/Microsoft.PowerShell
34
+ </wsman:ResourceURI>
35
+ <wsman:SelectorSet>
36
+ <wsman:Selector Name="ShellId">
37
+ 74142DC5-E14D-4FCC-86ED-63DA3EE8407E
38
+ </wsman:Selector>
39
+ </wsman:SelectorSet>
40
+ </wsa:ReferenceParameters>
41
+ </wxf:ResourceCreated>
42
+ </SOAP-ENV:Body>
43
+ </SOAP-ENV:Envelope>
@@ -0,0 +1,31 @@
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.dmtf.org/wbem/wsman/1/wsman/fault</wsa:Action>
15
+ <wsa:MessageID>uuid:F803101F-76B9-0005-0000-000000010000</wsa:MessageID>
16
+ <wsa:RelatesTo>uuid:AC61AF91-4AA9-428E-9294-670B4C5752A8</wsa:RelatesTo>
17
+ </SOAP-ENV:Header>
18
+ <SOAP-ENV:Body>
19
+ <SOAP-ENV:Fault>
20
+ <SOAP-ENV:Code>
21
+ <SOAP-ENV:Value>SOAP-ENV:Receiver</SOAP-ENV:Value>
22
+ <SOAP-ENV:Subcode>
23
+ <SOAP-ENV:Value>wsman:InternalError</SOAP-ENV:Value>
24
+ </SOAP-ENV:Subcode>
25
+ </SOAP-ENV:Code>
26
+ <SOAP-ENV:Reason>
27
+ <SOAP-ENV:Text xml:lang="en-US">get-instance: instance name parameter is missing</SOAP-ENV:Text>
28
+ </SOAP-ENV:Reason>
29
+ </SOAP-ENV:Fault>
30
+ </SOAP-ENV:Body>
31
+ </SOAP-ENV:Envelope>
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'winrm/wsmv/cleanup_command'
4
2
 
5
3
  describe WinRM::WSMV::CleanupCommand do
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'winrm/wsmv/close_shell'
4
2
 
5
3
  describe WinRM::WSMV::CloseShell do
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'winrm/wsmv/command_output_decoder'
4
2
 
5
3
  describe WinRM::WSMV::CommandOutputDecoder do
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'winrm/wsmv/command_output'
4
2
  require 'winrm/wsmv/header'
5
3
 
@@ -28,7 +26,7 @@ describe WinRM::WSMV::CommandOutput do
28
26
  shell_id: 'F4A2622B-B842-4EB8-8A78-0225C8A993DF',
29
27
  command_id: 'A2A2622B-B842-4EB8-8A78-0225C8A993DF',
30
28
  shell_uri: WinRM::WSMV::Header::RESOURCE_URI_POWERSHELL,
31
- out_streams: %w(stdout)
29
+ out_streams: %w[stdout]
32
30
  }
33
31
  end
34
32
  subject { described_class.new(default_connection_opts, cmd_out_opts) }
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'winrm/wsmv/command'
4
2
 
5
3
  describe WinRM::WSMV::Command do
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'winrm/wsmv/configuration'
4
2
 
5
3
  describe WinRM::WSMV::Configuration do
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'winrm/wsmv/create_pipeline'
4
2
 
5
3
  describe WinRM::WSMV::CreatePipeline do
@@ -22,7 +20,8 @@ describe WinRM::WSMV::CreatePipeline do
22
20
  expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
23
21
  expect(xml).to include(
24
22
  '<w:SelectorSet><w:Selector Name="ShellId">' \
25
- "#{shell_id}</w:Selector></w:SelectorSet>")
23
+ "#{shell_id}</w:Selector></w:SelectorSet>"
24
+ )
26
25
  expect(xml).to include("<rsp:CommandLine CommandId=\"#{command_id}\">")
27
26
  expect(xml).to include('<rsp:Command>Invoke-Expression</rsp:Command>')
28
27
  expect(xml).to include("<rsp:Arguments>#{pipeline}</rsp:Arguments>")
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'winrm/wsmv/create_shell'
4
2
 
5
3
  describe WinRM::WSMV::CreateShell do
@@ -12,14 +10,16 @@ describe WinRM::WSMV::CreateShell do
12
10
  expect(xml).to include('<p:DataLocale xml:lang="en-US" mustUnderstand="false"/>')
13
11
  expect(xml).to include(
14
12
  '<p:SessionId mustUnderstand="false">' \
15
- 'uuid:05A2622B-B842-4EB8-8A78-0225C8A993DF</p:SessionId>')
13
+ 'uuid:05A2622B-B842-4EB8-8A78-0225C8A993DF</p:SessionId>'
14
+ )
16
15
  expect(xml).to include('<w:MaxEnvelopeSize mustUnderstand="true">153600</w:MaxEnvelopeSize>')
17
16
  expect(xml).to include('<a:To>http://localhost:5985/wsman</a:To>')
18
17
  expect(xml).to include('<rsp:InputStreams>stdin</rsp:InputStreams>')
19
18
  expect(xml).to include('<rsp:OutputStreams>stdout stderr</rsp:OutputStreams>')
20
19
  expect(xml).to include(
21
20
  '<w:ResourceURI mustUnderstand="true">' \
22
- 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd</w:ResourceURI>')
21
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd</w:ResourceURI>'
22
+ )
23
23
  end
24
24
  context 'shell options w/env vars' do
25
25
  let(:shell_opts) do
@@ -31,7 +31,8 @@ describe WinRM::WSMV::CreateShell do
31
31
  let(:xml) { subject.build }
32
32
  it 'includes environemt vars' do
33
33
  expect(xml).to include(
34
- '<rsp:Environment><rsp:Variable Name="FOO">BAR</rsp:Variable></rsp:Environment>')
34
+ '<rsp:Environment><rsp:Variable Name="FOO">BAR</rsp:Variable></rsp:Environment>'
35
+ )
35
36
  end
36
37
  end
37
38
  end
@@ -1,36 +1,38 @@
1
- # encoding: UTF-8
2
-
3
- require 'winrm/wsmv/init_runspace_pool'
4
-
5
- describe WinRM::WSMV::InitRunspacePool do
6
- context 'default session options' do
7
- let(:shell_id) { SecureRandom.uuid.to_s.upcase }
8
- let(:payload) { 'blah'.bytes }
9
-
10
- subject { described_class.new(default_connection_opts, shell_id, payload) }
11
-
12
- it 'creates a well formed message' do
13
- xml = subject.build
14
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
15
- expect(xml).to include('<w:Locale xml:lang="en-US" mustUnderstand="false"/>')
16
- expect(xml).to include('<p:DataLocale xml:lang="en-US" mustUnderstand="false"/>')
17
- expect(xml).to include(
18
- '<p:SessionId mustUnderstand="false">' \
19
- 'uuid:05A2622B-B842-4EB8-8A78-0225C8A993DF</p:SessionId>')
20
- expect(xml).to include('<w:MaxEnvelopeSize mustUnderstand="true">153600</w:MaxEnvelopeSize>')
21
- expect(xml).to include('<a:To>http://localhost:5985/wsman</a:To>')
22
- expect(xml).to include(
23
- '<w:OptionSet env:mustUnderstand="true">' \
24
- '<w:Option Name="protocolversion" MustComply="true">2.3</w:Option></w:OptionSet>')
25
- expect(xml).to include('<rsp:InputStreams>stdin pr</rsp:InputStreams>')
26
- expect(xml).to include('<rsp:OutputStreams>stdout</rsp:OutputStreams>')
27
- expect(xml).to include("<rsp:Shell ShellId=\"#{subject.shell_id}\">")
28
- expect(xml).to include(
29
- '<w:ResourceURI mustUnderstand="true">' \
30
- 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell')
31
- expect(xml).to include(
32
- '<creationXml xmlns="http://schemas.microsoft.com/powershell">' \
33
- "#{Base64.strict_encode64(payload.pack('C*'))}</creationXml>")
34
- end
35
- end
36
- end
1
+ require 'winrm/wsmv/init_runspace_pool'
2
+
3
+ describe WinRM::WSMV::InitRunspacePool do
4
+ context 'default session options' do
5
+ let(:shell_id) { SecureRandom.uuid.to_s.upcase }
6
+ let(:payload) { 'blah'.bytes }
7
+
8
+ subject { described_class.new(default_connection_opts, shell_id, payload) }
9
+
10
+ it 'creates a well formed message' do
11
+ xml = subject.build
12
+ expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
13
+ expect(xml).to include('<w:Locale xml:lang="en-US" mustUnderstand="false"/>')
14
+ expect(xml).to include('<p:DataLocale xml:lang="en-US" mustUnderstand="false"/>')
15
+ expect(xml).to include(
16
+ '<p:SessionId mustUnderstand="false">' \
17
+ 'uuid:05A2622B-B842-4EB8-8A78-0225C8A993DF</p:SessionId>'
18
+ )
19
+ expect(xml).to include('<w:MaxEnvelopeSize mustUnderstand="true">153600</w:MaxEnvelopeSize>')
20
+ expect(xml).to include('<a:To>http://localhost:5985/wsman</a:To>')
21
+ expect(xml).to include(
22
+ '<w:OptionSet env:mustUnderstand="true">' \
23
+ '<w:Option Name="protocolversion" MustComply="true">2.3</w:Option></w:OptionSet>'
24
+ )
25
+ expect(xml).to include('<rsp:InputStreams>stdin pr</rsp:InputStreams>')
26
+ expect(xml).to include('<rsp:OutputStreams>stdout</rsp:OutputStreams>')
27
+ expect(xml).to include("<rsp:Shell ShellId=\"#{subject.shell_id}\" Name=\"Runspace\">")
28
+ expect(xml).to include(
29
+ '<w:ResourceURI mustUnderstand="true">' \
30
+ 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell'
31
+ )
32
+ expect(xml).to include(
33
+ '<creationXml xmlns="http://schemas.microsoft.com/powershell">' \
34
+ "#{Base64.strict_encode64(payload.pack('C*'))}</creationXml>"
35
+ )
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'winrm/wsmv/keep_alive'
4
2
 
5
3
  describe WinRM::WSMV::KeepAlive do
@@ -11,10 +9,12 @@ describe WinRM::WSMV::KeepAlive do
11
9
  expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
12
10
  expect(xml).to include(
13
11
  '<w:OptionSet><w:Option Name="WSMAN_CMDSHELL_OPTION_KEEPALIVE">' \
14
- 'TRUE</w:Option></w:OptionSet>')
12
+ 'TRUE</w:Option></w:OptionSet>'
13
+ )
15
14
  expect(xml).to include(
16
15
  '<w:SelectorSet><w:Selector Name="ShellId">' \
17
- "#{shell_id}</w:Selector></w:SelectorSet>")
16
+ "#{shell_id}</w:Selector></w:SelectorSet>"
17
+ )
18
18
  expect(xml).to include('<rsp:DesiredStream>stdout</rsp:DesiredStream>')
19
19
  end
20
20
  end
@@ -1,123 +1,124 @@
1
- # encoding: UTF-8
2
-
3
- require 'winrm/wsmv/receive_response_reader'
4
-
5
- describe WinRM::WSMV::ReceiveResponseReader do
6
- let(:shell_id) { 'F4A2622B-B842-4EB8-8A78-0225C8A993DF' }
7
- let(:command_id) { 'A2A2622B-B842-4EB8-8A78-0225C8A993DF' }
8
- let(:output_message) { double('output_message', build: 'output_message') }
9
- let(:test_data_xml_template) do
10
- ERB.new(stubbed_response('get_command_output_response.xml.erb'))
11
- end
12
- let(:test_data_xml_template_not_done) do
13
- ERB.new(stubbed_response('get_command_output_response_not_done.xml.erb'))
14
- end
15
- let(:transport) do
16
- {}
17
- end
18
-
19
- subject do
20
- described_class.new(
21
- transport,
22
- Logging.logger['test']
23
- )
24
- end
25
-
26
- describe '#read_output' do
27
- context 'response doc stdout with invalid UTF-8 characters, issue 184' do
28
- let(:test_data_stdout) { 'ffff' } # Base64-decodes to '}\xF7\xDF', an invalid sequence
29
- let(:test_data_stderr) { '' }
30
- let(:test_data_xml) { test_data_xml_template.result(binding) }
31
-
32
- before do
33
- allow(transport).to receive(:send_request).and_return(
34
- REXML::Document.new(test_data_xml)
35
- )
36
- end
37
-
38
- it 'does not raise an ArgumentError: invalid byte sequence in UTF-8' do
39
- begin
40
- expect(
41
- subject.read_output(output_message)
42
- ).not_to raise_error
43
- rescue RSpec::Expectations::ExpectationNotMetError => e
44
- expect(e.message).not_to include 'ArgumentError'
45
- end
46
- end
47
-
48
- it 'does not have an empty stdout' do
49
- expect(
50
- subject.read_output(output_message).stdout
51
- ).not_to be_empty
52
- end
53
- end
54
-
55
- context 'response doc stdout with valid UTF-8' do
56
- let(:test_data_raw) { '✓1234-äöü' }
57
- let(:test_data_stdout) { Base64.encode64(test_data_raw) }
58
- let(:test_data_stderr) { '' }
59
- let(:test_data_xml) { test_data_xml_template.result(binding) }
60
-
61
- before do
62
- allow(transport).to receive(:send_request).and_return(
63
- REXML::Document.new(test_data_xml)
64
- )
65
- end
66
-
67
- it 'decodes to match input data' do
68
- expect(
69
- subject.read_output(output_message).stdout
70
- ).to eq(test_data_raw)
71
- end
72
- end
73
- end
74
-
75
- describe '#read_response' do
76
- context 'do not wait for done state' do
77
- let(:test_data_raw) { 'output text' }
78
- let(:test_error_raw) { 'error text' }
79
- let(:test_data_stdout) { Base64.encode64(test_data_raw) }
80
- let(:test_data_stderr) { Base64.encode64(test_error_raw) }
81
- let(:test_data_xml) { test_data_xml_template.result(binding) }
82
-
83
- before do
84
- allow(transport).to receive(:send_request).and_return(
85
- REXML::Document.new(test_data_xml)
86
- ).once
87
- end
88
-
89
- it 'yields stream and document' do
90
- subject.read_response(output_message) do |stream, doc|
91
- expect(stream[:text]).to eq(test_data_stdout) if stream[:type] == :stdout
92
- expect(stream[:text]).to eq(test_data_stderr) if stream[:type] == :stderr
93
- expect(doc.to_s).to eq(REXML::Document.new(test_data_xml).to_s)
94
- end
95
- end
96
- end
97
-
98
- context 'wait for done state' do
99
- let(:test_data_raw) { 'output text' }
100
- let(:test_error_raw) { 'error text' }
101
- let(:test_data_stdout) { Base64.encode64(test_data_raw) }
102
- let(:test_data_stderr) { Base64.encode64(test_error_raw) }
103
- let(:test_data_xml_not_done) { test_data_xml_template_not_done.result(binding) }
104
- let(:test_data_xml_done) { test_data_xml_template.result(binding) }
105
-
106
- it 'yields streams and both documents' do
107
- allow(transport).to receive(:send_request).and_return(
108
- REXML::Document.new(test_data_xml_not_done),
109
- REXML::Document.new(test_data_xml_done)
110
- )
111
- times = 1
112
-
113
- subject.read_response(output_message, true) do |stream, doc|
114
- expect(stream[:text]).to eq(test_data_stdout) if stream[:type] == :stdout
115
- expect(stream[:text]).to eq(test_data_stderr) if stream[:type] == :stderr
116
- expect(doc.to_s).to eq(REXML::Document.new(test_data_xml_not_done).to_s) if times == 1
117
- expect(doc.to_s).to eq(REXML::Document.new(test_data_xml_done).to_s) if times > 2
118
- times += 1
119
- end
120
- end
121
- end
122
- end
123
- end
1
+ require 'winrm/wsmv/receive_response_reader'
2
+
3
+ describe WinRM::WSMV::ReceiveResponseReader do
4
+ let(:shell_id) { 'F4A2622B-B842-4EB8-8A78-0225C8A993DF' }
5
+ let(:command_id) { 'A2A2622B-B842-4EB8-8A78-0225C8A993DF' }
6
+ let(:output_message) { double('output_message', build: 'output_message') }
7
+ let(:transport) do
8
+ {}
9
+ end
10
+
11
+ subject do
12
+ described_class.new(
13
+ transport,
14
+ Logging.logger['test']
15
+ )
16
+ end
17
+
18
+ # Output from PowerShell endpoint and output from OMI Server endpoint
19
+ {
20
+ 'get_command_output_response.xml.erb' => 'get_command_output_response_not_done.xml.erb',
21
+ 'get_omi_command_output_response.xml.erb' => 'get_omi_command_output_response_not_done.xml.erb'
22
+ }.each_pair do |template, template_not_done|
23
+ describe "#read_output for #{template}" do
24
+ context 'response doc stdout with invalid UTF-8 characters, issue 184' do
25
+ let(:test_data_stdout) { 'ffff' } # Base64-decodes to '}\xF7\xDF', an invalid sequence
26
+ let(:test_data_stderr) { '' }
27
+ let(:test_data_xml) { ERB.new(stubbed_response(template)).result(binding) }
28
+ let(:test_data) { REXML::Document.new(test_data_xml) }
29
+ let(:stdout_xpath) { "//*[local-name() = 'Stream' and @Name = 'stdout']" }
30
+
31
+ before do
32
+ allow(transport).to receive(:send_request).and_return(test_data)
33
+ end
34
+
35
+ # OMI server messages do not appear to include stdout when CommandState/Done
36
+ it 'does not raise an ArgumentError: invalid byte sequence in UTF-8' do
37
+ begin
38
+ expect(
39
+ subject.read_output(output_message)
40
+ ).not_to raise_error
41
+ rescue RSpec::Expectations::ExpectationNotMetError => e
42
+ expect(e.message).not_to include 'ArgumentError'
43
+ end
44
+ end
45
+
46
+ it 'does not have an empty stdout' do
47
+ skip('response has no stdout') if REXML::XPath.match(test_data, stdout_xpath).empty?
48
+ expect(
49
+ subject.read_output(output_message).stdout
50
+ ).not_to be_empty
51
+ end
52
+ end
53
+
54
+ context 'response doc stdout with valid UTF-8' do
55
+ let(:test_data_raw) { '✓1234-äöü' }
56
+ let(:test_data_stdout) { Base64.encode64(test_data_raw) }
57
+ let(:test_data_stderr) { '' }
58
+ let(:test_data_xml) { ERB.new(stubbed_response(template)).result(binding) }
59
+ let(:test_data) { REXML::Document.new(test_data_xml) }
60
+ let(:stdout_xpath) { "//*[local-name() = 'Stream' and @Name = 'stdout']" }
61
+
62
+ before do
63
+ allow(transport).to receive(:send_request).and_return(test_data)
64
+ end
65
+
66
+ it 'decodes to match input data' do
67
+ skip('response has no stdout') if REXML::XPath.match(test_data, stdout_xpath).empty?
68
+ expect(
69
+ subject.read_output(output_message).stdout
70
+ ).to eq(test_data_raw)
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "#read_response for #{template}" do
76
+ context 'do not wait for done state' do
77
+ let(:test_data_raw) { 'output text' }
78
+ let(:test_error_raw) { 'error text' }
79
+ let(:test_data_stdout) { Base64.encode64(test_data_raw) }
80
+ let(:test_data_stderr) { Base64.encode64(test_error_raw) }
81
+ let(:test_data_xml) { ERB.new(stubbed_response(template)).result(binding) }
82
+
83
+ before do
84
+ allow(transport).to receive(:send_request).and_return(
85
+ REXML::Document.new(test_data_xml)
86
+ ).once
87
+ end
88
+
89
+ it 'yields stream and document' do
90
+ subject.read_response(output_message) do |stream, doc|
91
+ expect(stream[:text]).to eq(test_data_stdout) if stream[:type] == :stdout
92
+ expect(stream[:text]).to eq(test_data_stderr) if stream[:type] == :stderr
93
+ expect(doc.to_s).to eq(REXML::Document.new(test_data_xml).to_s)
94
+ end
95
+ end
96
+ end
97
+
98
+ context 'wait for done state' do
99
+ let(:test_data_raw) { 'output text' }
100
+ let(:test_error_raw) { 'error text' }
101
+ let(:test_data_stdout) { Base64.encode64(test_data_raw) }
102
+ let(:test_data_stderr) { Base64.encode64(test_error_raw) }
103
+ let(:test_data_xml_notdone) { ERB.new(stubbed_response(template_not_done)).result(binding) }
104
+ let(:test_data_xml_done) { ERB.new(stubbed_response(template)).result(binding) }
105
+
106
+ it 'yields streams and both documents' do
107
+ allow(transport).to receive(:send_request).and_return(
108
+ REXML::Document.new(test_data_xml_notdone),
109
+ REXML::Document.new(test_data_xml_done)
110
+ )
111
+ times = 1
112
+
113
+ subject.read_response(output_message, true) do |stream, doc|
114
+ expect(stream[:text]).to eq(test_data_stdout) if stream[:type] == :stdout
115
+ expect(stream[:text]).to eq(test_data_stderr) if stream[:type] == :stderr
116
+ expect(doc.to_s).to eq(REXML::Document.new(test_data_xml_notdone).to_s) if times == 1
117
+ expect(doc.to_s).to eq(REXML::Document.new(test_data_xml_done).to_s) if times > 2
118
+ times += 1
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end