winrm 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/lib/winrm/http/transport.rb +1 -1
  3. data/lib/winrm/psrp/message.rb +128 -128
  4. data/lib/winrm/shells/power_shell.rb +0 -1
  5. data/lib/winrm/version.rb +1 -1
  6. metadata +12 -85
  7. data/.gitignore +0 -10
  8. data/.rubocop.yml +0 -38
  9. data/.travis.yml +0 -10
  10. data/Gemfile +0 -2
  11. data/Rakefile +0 -33
  12. data/Vagrantfile +0 -6
  13. data/WinrmAppveyor.psm1 +0 -32
  14. data/appveyor.yml +0 -50
  15. data/changelog.md +0 -133
  16. data/preamble +0 -17
  17. data/tests/integration/auth_timeout_spec.rb +0 -17
  18. data/tests/integration/cmd_spec.rb +0 -130
  19. data/tests/integration/config-example.yml +0 -16
  20. data/tests/integration/issue_59_spec.rb +0 -25
  21. data/tests/integration/powershell_spec.rb +0 -164
  22. data/tests/integration/spec_helper.rb +0 -62
  23. data/tests/integration/transport_spec.rb +0 -98
  24. data/tests/integration/wql_spec.rb +0 -33
  25. data/tests/matchers.rb +0 -59
  26. data/tests/spec/configuration_spec.rb +0 -183
  27. data/tests/spec/connection_spec.rb +0 -37
  28. data/tests/spec/exception_spec.rb +0 -49
  29. data/tests/spec/http/transport_factory_spec.rb +0 -66
  30. data/tests/spec/http/transport_spec.rb +0 -43
  31. data/tests/spec/output_spec.rb +0 -128
  32. data/tests/spec/psrp/fragment_spec.rb +0 -60
  33. data/tests/spec/psrp/message_data/base_spec.rb +0 -11
  34. data/tests/spec/psrp/message_data/error_record_spec.rb +0 -39
  35. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -23
  36. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -30
  37. data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -38
  38. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -23
  39. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -14
  40. data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -28
  41. data/tests/spec/psrp/message_data_spec.rb +0 -33
  42. data/tests/spec/psrp/message_defragmenter_spec.rb +0 -45
  43. data/tests/spec/psrp/message_fragmenter_spec.rb +0 -103
  44. data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -98
  45. data/tests/spec/psrp/psrp_message_spec.rb +0 -73
  46. data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -170
  47. data/tests/spec/psrp/uuid_spec.rb +0 -28
  48. data/tests/spec/response_handler_spec.rb +0 -69
  49. data/tests/spec/shells/base_spec.rb +0 -227
  50. data/tests/spec/shells/cmd_spec.rb +0 -75
  51. data/tests/spec/shells/powershell_spec.rb +0 -221
  52. data/tests/spec/spec_helper.rb +0 -46
  53. data/tests/spec/stubs/clixml/error_record.xml.erb +0 -84
  54. data/tests/spec/stubs/clixml/pipeline_state.xml.erb +0 -88
  55. data/tests/spec/stubs/responses/get_command_output_response.xml.erb +0 -13
  56. data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +0 -10
  57. data/tests/spec/stubs/responses/get_omi_command_output_response.xml.erb +0 -23
  58. data/tests/spec/stubs/responses/get_omi_command_output_response_not_done.xml.erb +0 -24
  59. data/tests/spec/stubs/responses/get_omi_config_response.xml +0 -45
  60. data/tests/spec/stubs/responses/get_omi_powershell_keepalive_response.xml.erb +0 -33
  61. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +0 -10
  62. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +0 -12
  63. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +0 -9
  64. data/tests/spec/stubs/responses/open_shell_omi.xml +0 -43
  65. data/tests/spec/stubs/responses/open_shell_v1.xml +0 -19
  66. data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
  67. data/tests/spec/stubs/responses/soap_fault_omi.xml +0 -31
  68. data/tests/spec/stubs/responses/soap_fault_v1.xml +0 -36
  69. data/tests/spec/stubs/responses/soap_fault_v2.xml +0 -42
  70. data/tests/spec/stubs/responses/wmi_error_v2.xml +0 -41
  71. data/tests/spec/wsmv/cleanup_command_spec.rb +0 -20
  72. data/tests/spec/wsmv/close_shell_spec.rb +0 -15
  73. data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -35
  74. data/tests/spec/wsmv/command_output_spec.rb +0 -43
  75. data/tests/spec/wsmv/command_spec.rb +0 -17
  76. data/tests/spec/wsmv/configuration_spec.rb +0 -15
  77. data/tests/spec/wsmv/create_pipeline_spec.rb +0 -30
  78. data/tests/spec/wsmv/create_shell_spec.rb +0 -39
  79. data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -38
  80. data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
  81. data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -124
  82. data/tests/spec/wsmv/send_data_spec.rb +0 -30
  83. data/tests/spec/wsmv/wql_query_spec.rb +0 -11
  84. data/tests/spec/wsmv/write_stdin_spec.rb +0 -20
  85. data/winrm.gemspec +0 -46
@@ -1,15 +0,0 @@
1
- require 'winrm/wsmv/close_shell'
2
-
3
- describe WinRM::WSMV::CloseShell do
4
- context 'default session options' do
5
- subject do
6
- described_class.new(default_connection_opts, shell_id: 'F4A2622B-B842-4EB8-8A78-0225C8A993DF')
7
- end
8
- let(:xml) { subject.build }
9
- it 'creates a well formed message' do
10
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
11
- expect(xml).to include('<a:Action mustUnderstand="true">' \
12
- 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete</a:Action>')
13
- end
14
- end
15
- end
@@ -1,35 +0,0 @@
1
- require 'winrm/wsmv/command_output_decoder'
2
-
3
- describe WinRM::WSMV::CommandOutputDecoder do
4
- let(:raw_output_with_bom) do
5
- '77u/' \
6
- 'ICAgQ29ubmVjdGlvbi1zcGVjaWZpYyBETlMgU3VmZml4ICAuIDogDQogICBMaW5rLWxvY2FsIElQdjYgQWRkcmVzcyA' \
7
- 'uIC4gLiAuIC4gOiBmZTgwOjo5MTFkOjE2OTQ6NTcwNDo1YjI5JTEyDQogICBJUHY0IEFkZHJlc3MuIC4gLiAuIC4gLi' \
8
- 'AuIC4gLiAuIC4gOiAxMC4wLjIuMTUNCiAgIFN1Ym5ldCBNYXNrIC4gLiAuIC4gLiAuIC4gLiAuIC4gLiA6IDI1NS4yN' \
9
- 'TUuMjU1LjANCiAgIERlZmF1bHQgR2F0ZXdheSAuIC4gLiAuIC4gLiAuIC4gLiA6IDEwLjAuMi4yDQoNClR1bm5lbCBh' \
10
- 'ZGFwdGVyIGlzYXRhcC57RjBENTY2RDgtNzlCMS00QUYwLUJENUQtMkM5RkVEOEI3MTE3fToNCg0KICAgTWVkaWEgU3R' \
11
- 'hdGUgLiAuIC4gLiAuIC4gLiAuIC4gLiAuIDogTWVkaWEgZGlzY29ubmVjdGVkDQogICBDb25uZWN0aW9uLXNwZWNpZm' \
12
- 'ljIEROUyBTdWZmaXggIC4gOiANCg0KVHVubmVsIGFkYXB0ZXIgVGVyZWRvIFR1bm5lbGluZyBQc2V1ZG8tSW50ZXJmY' \
13
- 'WNlOg0KDQogICBDb25uZWN0aW9uLXNwZWNpZmljIEROUyBTdWZmaXggIC4gOiANCiAgIElQdjYgQWRkcmVzcy4gLiAu' \
14
- 'IC4gLiAuIC4gLiAuIC4gLiA6IDIwMDE6MDo5ZDM4OjZhYmQ6NGJiOjI4YjU6ZjVmZjpmZGYwDQogICBMaW5rLWxvY2F' \
15
- 'sIElQdjYgQWRkcmVzcyAuIC4gLiAuIC4gOiBmZTgwOjo0YmI6MjhiNTpmNWZmOmZkZjAlMTQNCiAgIERlZmF1bHQgR2' \
16
- 'F0ZXdheSAuIC4gLiAuIC4gLiAuIC4gLiA6IDo6DQo='
17
- end
18
- let(:expected) do
19
- " Connection-specific DNS Suffix . : \r\n Link-local IPv6 Address . . . . . : fe80::911" \
20
- "d:1694:5704:5b29%12\r\n IPv4 Address. . . . . . . . . . . : 10.0.2.15\r\n Subnet Mask ." \
21
- " . . . . . . . . . . : 255.255.255.0\r\n Default Gateway . . . . . . . . . : 10.0.2.2\r\n" \
22
- "\r\nTunnel adapter isatap.{F0D566D8-79B1-4AF0-BD5D-2C9FED8B7117}:\r\n\r\n Media State . ." \
23
- " . . . . . . . . . : Media disconnected\r\n Connection-specific DNS Suffix . : \r\n\r\nT" \
24
- "unnel adapter Teredo Tunneling Pseudo-Interface:\r\n\r\n Connection-specific DNS Suffix " \
25
- ". : \r\n IPv6 Address. . . . . . . . . . . : 2001:0:9d38:6abd:4bb:28b5:f5ff:fdf0\r\n Li" \
26
- "nk-local IPv6 Address . . . . . : fe80::4bb:28b5:f5ff:fdf0%14\r\n Default Gateway . . . ." \
27
- " . . . . . : ::\r\n"
28
- end
29
- subject { described_class.new }
30
- context 'valid UTF-8 raw output' do
31
- it 'decodes' do
32
- expect(subject.decode(raw_output_with_bom)).to eq(expected)
33
- end
34
- end
35
- end
@@ -1,43 +0,0 @@
1
- require 'winrm/wsmv/command_output'
2
- require 'winrm/wsmv/header'
3
-
4
- describe WinRM::WSMV::CommandOutput do
5
- context 'default session options' do
6
- let(:cmd_out_opts) do
7
- {
8
- shell_id: 'F4A2622B-B842-4EB8-8A78-0225C8A993DF',
9
- command_id: 'A2A2622B-B842-4EB8-8A78-0225C8A993DF'
10
- }
11
- end
12
- subject { described_class.new(default_connection_opts, cmd_out_opts) }
13
- let(:xml) { subject.build }
14
- it 'creates a well formed message' do
15
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
16
- expect(xml).to include('<w:Option Name="WSMAN_CMDSHELL_OPTION_KEEPALIVE">TRUE</w:Option>')
17
- expect(xml).to include('w:ResourceURI mustUnderstand="true">' \
18
- 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd</w:ResourceURI>')
19
- expect(xml).to include('<rsp:DesiredStream ' \
20
- 'CommandId="A2A2622B-B842-4EB8-8A78-0225C8A993DF">stdout stderr</rsp:DesiredStream>')
21
- end
22
- end
23
- context 'powershell' do
24
- let(:cmd_out_opts) do
25
- {
26
- shell_id: 'F4A2622B-B842-4EB8-8A78-0225C8A993DF',
27
- command_id: 'A2A2622B-B842-4EB8-8A78-0225C8A993DF',
28
- shell_uri: WinRM::WSMV::Header::RESOURCE_URI_POWERSHELL,
29
- out_streams: %w[stdout]
30
- }
31
- end
32
- subject { described_class.new(default_connection_opts, cmd_out_opts) }
33
- let(:xml) { subject.build }
34
- it 'creates a well formed message' do
35
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
36
- expect(xml).to include('<w:Option Name="WSMAN_CMDSHELL_OPTION_KEEPALIVE">TRUE</w:Option>')
37
- expect(xml).to include('w:ResourceURI mustUnderstand="true">' \
38
- 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell</w:ResourceURI>')
39
- expect(xml).to include('<rsp:DesiredStream ' \
40
- 'CommandId="A2A2622B-B842-4EB8-8A78-0225C8A993DF">stdout</rsp:DesiredStream>')
41
- end
42
- end
43
- end
@@ -1,17 +0,0 @@
1
- require 'winrm/wsmv/command'
2
-
3
- describe WinRM::WSMV::Command do
4
- context 'default session options' do
5
- let(:cmd_opts) do
6
- {
7
- shell_id: 'D5A2622B-B842-4EB8-8A78-0225C8A993DF',
8
- command: 'ipconfig'
9
- }
10
- end
11
- subject { described_class.new(default_connection_opts, cmd_opts) }
12
- let(:xml) { subject.build }
13
- it 'creates a well formed message' do
14
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- require 'winrm/wsmv/configuration'
2
-
3
- describe WinRM::WSMV::Configuration do
4
- subject do
5
- described_class.new(default_connection_opts)
6
- end
7
- let(:xml) { subject.build }
8
- it 'creates a well formed message' do
9
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
10
- expect(xml).to include('<a:Action mustUnderstand="true">' \
11
- 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get</a:Action>')
12
- expect(xml).to include('w:ResourceURI mustUnderstand="true">' \
13
- 'http://schemas.microsoft.com/wbem/wsman/1/config</w:ResourceURI>')
14
- end
15
- end
@@ -1,30 +0,0 @@
1
- require 'winrm/wsmv/create_pipeline'
2
-
3
- describe WinRM::WSMV::CreatePipeline do
4
- context 'default session options' do
5
- let(:shell_id) { 'D5A2622B-B842-4EB8-8A78-0225C8A993DF' }
6
- let(:command_id) { 'D5A2622B-B842-4EB8-8A78-0225C8A993DF' }
7
- let(:fragment) { WinRM::PSRP::Fragment.new(0, [1, 2, 3]) }
8
- let(:pipeline) { Base64.strict_encode64(fragment.bytes.pack('C*')) }
9
-
10
- subject do
11
- WinRM::WSMV::CreatePipeline.new(
12
- default_connection_opts,
13
- shell_id,
14
- command_id,
15
- fragment
16
- )
17
- end
18
- let(:xml) { subject.build }
19
- it 'creates a well formed message' do
20
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
21
- expect(xml).to include(
22
- '<w:SelectorSet><w:Selector Name="ShellId">' \
23
- "#{shell_id}</w:Selector></w:SelectorSet>"
24
- )
25
- expect(xml).to include("<rsp:CommandLine CommandId=\"#{command_id}\">")
26
- expect(xml).to include('<rsp:Command>Invoke-Expression</rsp:Command>')
27
- expect(xml).to include("<rsp:Arguments>#{pipeline}</rsp:Arguments>")
28
- end
29
- end
30
- end
@@ -1,39 +0,0 @@
1
- require 'winrm/wsmv/create_shell'
2
-
3
- describe WinRM::WSMV::CreateShell do
4
- context 'default session options' do
5
- subject { described_class.new(default_connection_opts) }
6
- let(:xml) { subject.build }
7
- it 'creates a well formed message' do
8
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
9
- expect(xml).to include('<w:Locale xml:lang="en-US" mustUnderstand="false"/>')
10
- expect(xml).to include('<p:DataLocale xml:lang="en-US" mustUnderstand="false"/>')
11
- expect(xml).to include(
12
- '<p:SessionId mustUnderstand="false">' \
13
- 'uuid:05A2622B-B842-4EB8-8A78-0225C8A993DF</p:SessionId>'
14
- )
15
- expect(xml).to include('<w:MaxEnvelopeSize mustUnderstand="true">153600</w:MaxEnvelopeSize>')
16
- expect(xml).to include('<a:To>http://localhost:5985/wsman</a:To>')
17
- expect(xml).to include('<rsp:InputStreams>stdin</rsp:InputStreams>')
18
- expect(xml).to include('<rsp:OutputStreams>stdout stderr</rsp:OutputStreams>')
19
- expect(xml).to include(
20
- '<w:ResourceURI mustUnderstand="true">' \
21
- 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd</w:ResourceURI>'
22
- )
23
- end
24
- context 'shell options w/env vars' do
25
- let(:shell_opts) do
26
- {
27
- env_vars: { 'FOO' => 'BAR' }
28
- }
29
- end
30
- subject { described_class.new(default_connection_opts, shell_opts) }
31
- let(:xml) { subject.build }
32
- it 'includes environemt vars' do
33
- expect(xml).to include(
34
- '<rsp:Environment><rsp:Variable Name="FOO">BAR</rsp:Variable></rsp:Environment>'
35
- )
36
- end
37
- end
38
- end
39
- end
@@ -1,38 +0,0 @@
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,21 +0,0 @@
1
- require 'winrm/wsmv/keep_alive'
2
-
3
- describe WinRM::WSMV::KeepAlive do
4
- context 'default session options' do
5
- let(:shell_id) { 'F4A2622B-B842-4EB8-8A78-0225C8A993DF' }
6
- subject { described_class.new(default_connection_opts, shell_id) }
7
- let(:xml) { subject.build }
8
- it 'creates a well formed message' do
9
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
10
- expect(xml).to include(
11
- '<w:OptionSet><w:Option Name="WSMAN_CMDSHELL_OPTION_KEEPALIVE">' \
12
- 'TRUE</w:Option></w:OptionSet>'
13
- )
14
- expect(xml).to include(
15
- '<w:SelectorSet><w:Selector Name="ShellId">' \
16
- "#{shell_id}</w:Selector></w:SelectorSet>"
17
- )
18
- expect(xml).to include('<rsp:DesiredStream>stdout</rsp:DesiredStream>')
19
- end
20
- end
21
- end
@@ -1,124 +0,0 @@
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
@@ -1,30 +0,0 @@
1
- require 'winrm/wsmv/send_data'
2
-
3
- describe WinRM::WSMV::SendData do
4
- context 'default session options' do
5
- let(:shell_id) { 'D5A2622B-B842-4EB8-8A78-0225C8A993DF' }
6
- let(:command_id) { 'D5A2622B-B842-4EB8-8A78-0225C8A993DF' }
7
- let(:fragment) { WinRM::PSRP::Fragment.new(1, [1, 2, 3]) }
8
- let(:pipeline) { Base64.strict_encode64(fragment.bytes.pack('C*')) }
9
-
10
- subject do
11
- described_class.new(
12
- default_connection_opts,
13
- shell_id,
14
- command_id,
15
- fragment
16
- )
17
- end
18
- let(:xml) { subject.build }
19
- it 'creates a well formed message' do
20
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
21
- expect(xml).to include(
22
- '<w:SelectorSet><w:Selector Name="ShellId">' \
23
- "#{shell_id}</w:Selector></w:SelectorSet>"
24
- )
25
- expect(xml).to include(
26
- "<rsp:Stream Name=\"stdin\" CommandId=\"#{command_id}\">#{pipeline}</rsp:Stream>"
27
- )
28
- end
29
- end
30
- end
@@ -1,11 +0,0 @@
1
- require 'winrm/wsmv/wql_query'
2
-
3
- describe WinRM::WSMV::WqlQuery do
4
- context 'default session options' do
5
- subject { described_class.new(nil, default_connection_opts, 'SELECT * FROM Win32') }
6
- let(:xml) { subject.build }
7
- it 'creates a well formed message' do
8
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
9
- end
10
- end
11
- end
@@ -1,20 +0,0 @@
1
- require 'base64'
2
- require 'winrm/wsmv/write_stdin'
3
-
4
- describe WinRM::WSMV::WriteStdin do
5
- context 'default session options' do
6
- stdin_opts = {
7
- shell_id: 'D5A2622B-B842-4EB8-8A78-0225C8A993DF',
8
- command_id: 'A2A2622B-B842-4EB8-8A78-0225C8A993DF',
9
- stdin: 'dir'
10
- }
11
- subject { described_class.new(default_connection_opts, stdin_opts) }
12
- let(:xml) { subject.build }
13
- it 'creates a well formed message' do
14
- b64_stdin = Base64.encode64(stdin_opts[:stdin])
15
- expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
16
- expect(xml).to include('<rsp:Stream Name="stdin" ' \
17
- "CommandId=\"A2A2622B-B842-4EB8-8A78-0225C8A993DF\">#{b64_stdin}</rsp:Stream>")
18
- end
19
- end
20
- end