winrm 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -10
  3. data/.rubocop.yml +26 -26
  4. data/.travis.yml +11 -11
  5. data/Gemfile +3 -3
  6. data/README.md +260 -233
  7. data/Rakefile +34 -34
  8. data/Vagrantfile +6 -6
  9. data/WinrmAppveyor.psm1 +31 -31
  10. data/appveyor.yml +51 -51
  11. data/changelog.md +104 -101
  12. data/lib/winrm.rb +39 -39
  13. data/lib/winrm/connection.rb +83 -82
  14. data/lib/winrm/connection_opts.rb +91 -91
  15. data/lib/winrm/exceptions.rb +76 -76
  16. data/lib/winrm/http/response_handler.rb +96 -96
  17. data/lib/winrm/http/transport.rb +424 -424
  18. data/lib/winrm/http/transport_factory.rb +68 -68
  19. data/lib/winrm/output.rb +59 -59
  20. data/lib/winrm/psrp/create_pipeline.xml.erb +167 -167
  21. data/lib/winrm/psrp/fragment.rb +70 -70
  22. data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -224
  23. data/lib/winrm/psrp/message.rb +130 -130
  24. data/lib/winrm/psrp/message_data.rb +42 -42
  25. data/lib/winrm/psrp/message_data/base.rb +49 -49
  26. data/lib/winrm/psrp/message_data/error_record.rb +68 -68
  27. data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -32
  28. data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -49
  29. data/lib/winrm/psrp/message_data/pipeline_state.rb +40 -40
  30. data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -32
  31. data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -39
  32. data/lib/winrm/psrp/message_data/session_capability.rb +36 -36
  33. data/lib/winrm/psrp/message_defragmenter.rb +62 -62
  34. data/lib/winrm/psrp/message_factory.rb +75 -75
  35. data/lib/winrm/psrp/message_fragmenter.rb +60 -60
  36. data/lib/winrm/psrp/powershell_output_decoder.rb +139 -139
  37. data/lib/winrm/psrp/receive_response_reader.rb +97 -97
  38. data/lib/winrm/psrp/session_capability.xml.erb +7 -7
  39. data/lib/winrm/psrp/uuid.rb +40 -40
  40. data/lib/winrm/shells/base.rb +180 -175
  41. data/lib/winrm/shells/cmd.rb +65 -65
  42. data/lib/winrm/shells/power_shell.rb +202 -202
  43. data/lib/winrm/shells/retryable.rb +45 -45
  44. data/lib/winrm/shells/shell_factory.rb +58 -50
  45. data/lib/winrm/version.rb +7 -7
  46. data/lib/winrm/wsmv/base.rb +59 -59
  47. data/lib/winrm/wsmv/cleanup_command.rb +61 -61
  48. data/lib/winrm/wsmv/close_shell.rb +50 -50
  49. data/lib/winrm/wsmv/command.rb +101 -101
  50. data/lib/winrm/wsmv/command_output.rb +76 -76
  51. data/lib/winrm/wsmv/command_output_decoder.rb +55 -55
  52. data/lib/winrm/wsmv/configuration.rb +46 -46
  53. data/lib/winrm/wsmv/create_pipeline.rb +66 -66
  54. data/lib/winrm/wsmv/create_shell.rb +119 -119
  55. data/lib/winrm/wsmv/header.rb +203 -203
  56. data/lib/winrm/wsmv/init_runspace_pool.rb +95 -95
  57. data/lib/winrm/wsmv/iso8601_duration.rb +60 -60
  58. data/lib/winrm/wsmv/keep_alive.rb +68 -68
  59. data/lib/winrm/wsmv/receive_response_reader.rb +126 -126
  60. data/lib/winrm/wsmv/send_data.rb +68 -68
  61. data/lib/winrm/wsmv/soap.rb +51 -51
  62. data/lib/winrm/wsmv/wql_query.rb +79 -79
  63. data/lib/winrm/wsmv/write_stdin.rb +88 -88
  64. data/tests/integration/auth_timeout_spec.rb +18 -18
  65. data/tests/integration/cmd_spec.rb +131 -110
  66. data/tests/integration/config-example.yml +16 -16
  67. data/tests/integration/issue_59_spec.rb +26 -26
  68. data/tests/integration/powershell_spec.rb +165 -165
  69. data/tests/integration/spec_helper.rb +65 -65
  70. data/tests/integration/transport_spec.rb +99 -99
  71. data/tests/integration/wql_spec.rb +16 -16
  72. data/tests/matchers.rb +60 -60
  73. data/tests/spec/configuration_spec.rb +184 -184
  74. data/tests/spec/connection_spec.rb +39 -39
  75. data/tests/spec/exception_spec.rb +50 -50
  76. data/tests/spec/http/transport_factory_spec.rb +68 -68
  77. data/tests/spec/http/transport_spec.rb +44 -44
  78. data/tests/spec/output_spec.rb +127 -127
  79. data/tests/spec/psrp/fragment_spec.rb +62 -62
  80. data/tests/spec/psrp/message_data/base_spec.rb +13 -13
  81. data/tests/spec/psrp/message_data/error_record_spec.rb +41 -41
  82. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -25
  83. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -32
  84. data/tests/spec/psrp/message_data/pipeline_state_spec.rb +40 -40
  85. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -25
  86. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -16
  87. data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -30
  88. data/tests/spec/psrp/message_data_spec.rb +35 -35
  89. data/tests/spec/psrp/message_defragmenter_spec.rb +47 -47
  90. data/tests/spec/psrp/message_fragmenter_spec.rb +105 -105
  91. data/tests/spec/psrp/powershell_output_decoder_spec.rb +100 -100
  92. data/tests/spec/psrp/psrp_message_spec.rb +70 -70
  93. data/tests/spec/psrp/recieve_response_reader_spec.rb +172 -172
  94. data/tests/spec/psrp/uuid_spec.rb +28 -28
  95. data/tests/spec/response_handler_spec.rb +61 -61
  96. data/tests/spec/shells/base_spec.rb +202 -202
  97. data/tests/spec/shells/cmd_spec.rb +75 -75
  98. data/tests/spec/shells/powershell_spec.rb +175 -175
  99. data/tests/spec/spec_helper.rb +47 -47
  100. data/tests/spec/stubs/clixml/error_record.xml.erb +84 -84
  101. data/tests/spec/stubs/clixml/pipeline_state.xml.erb +88 -88
  102. data/tests/spec/stubs/responses/get_command_output_response.xml.erb +13 -13
  103. data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -10
  104. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -10
  105. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -12
  106. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -9
  107. data/tests/spec/stubs/responses/open_shell_v1.xml +19 -19
  108. data/tests/spec/stubs/responses/open_shell_v2.xml +20 -20
  109. data/tests/spec/stubs/responses/soap_fault_v1.xml +36 -36
  110. data/tests/spec/stubs/responses/soap_fault_v2.xml +42 -42
  111. data/tests/spec/stubs/responses/wmi_error_v2.xml +41 -41
  112. data/tests/spec/wsmv/cleanup_command_spec.rb +22 -22
  113. data/tests/spec/wsmv/close_shell_spec.rb +17 -17
  114. data/tests/spec/wsmv/command_output_decoder_spec.rb +37 -37
  115. data/tests/spec/wsmv/command_output_spec.rb +45 -45
  116. data/tests/spec/wsmv/command_spec.rb +19 -19
  117. data/tests/spec/wsmv/configuration_spec.rb +17 -17
  118. data/tests/spec/wsmv/create_pipeline_spec.rb +31 -31
  119. data/tests/spec/wsmv/create_shell_spec.rb +38 -38
  120. data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -36
  121. data/tests/spec/wsmv/keep_alive_spec.rb +21 -21
  122. data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -123
  123. data/tests/spec/wsmv/send_data_spec.rb +30 -30
  124. data/tests/spec/wsmv/wql_query_spec.rb +13 -13
  125. data/tests/spec/wsmv/write_stdin_spec.rb +22 -22
  126. data/winrm.gemspec +42 -42
  127. metadata +2 -2
@@ -1,100 +1,100 @@
1
- # encoding: UTF-8
2
-
3
- require 'winrm/psrp/powershell_output_decoder'
4
-
5
- describe WinRM::PSRP::PowershellOutputDecoder do
6
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:error_record] }
7
- let(:data) { 'blah' }
8
- let(:message) do
9
- WinRM::PSRP::Message.new(
10
- 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
11
- message_type,
12
- data,
13
- '4218a578-0f18-4b19-82c3-46b433319126'
14
- )
15
- end
16
-
17
- subject { described_class.new.decode(message) }
18
-
19
- context 'undecodable message type' do
20
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:public_key] }
21
-
22
- it 'ignores message' do
23
- expect(subject).to be nil
24
- end
25
- end
26
-
27
- context 'undecodable method identifier' do
28
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call] }
29
- let(:data) do
30
- "\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I64 N=\"ci\">-100</I64><Obj N=\"mi\" RefId=\"1\">"\
31
- '<TN RefId="0"><T>System.Management.Automation.Remoting.RemoteHostMethodId</T>'\
32
- '<T>System.Enum</T><T>System.ValueType</T><T>System.Object</T></TN>'\
33
- '<ToString>WriteProgress</ToString><I32>17</I32></Obj><Obj N="mp" RefId="2">'\
34
- '<TN RefId="1"><T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST>'\
35
- '<I32>7</I32><I32>0</I32><S>some_x000D__x000A_data</S></LST></Obj></MS></Obj>'
36
- end
37
-
38
- it 'ignores message' do
39
- expect(subject).to be nil
40
- end
41
- end
42
-
43
- context 'receiving pipeline output' do
44
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
45
- let(:data) { '<obj><S>some data</S></obj>' }
46
-
47
- it 'decodes output' do
48
- expect(subject).to eq("some data\r\n")
49
- end
50
- end
51
-
52
- context 'writeline with new line in middle' do
53
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call] }
54
- let(:data) do
55
- "\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I64 N=\"ci\">-100</I64><Obj N=\"mi\" RefId=\"1\">"\
56
- '<TN RefId="0"><T>System.Management.Automation.Remoting.RemoteHostMethodId</T>'\
57
- '<T>System.Enum</T><T>System.ValueType</T><T>System.Object</T></TN>'\
58
- '<ToString>WriteLine3</ToString><I32>17</I32></Obj><Obj N="mp" RefId="2">'\
59
- '<TN RefId="1"><T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST>'\
60
- '<I32>7</I32><I32>0</I32><S>some_x000D__x000A_data</S></LST></Obj></MS></Obj>'
61
- end
62
-
63
- it 'decodes and replaces newline' do
64
- expect(subject).to eq("some\r\ndata\r\n")
65
- end
66
- end
67
-
68
- context 'receiving error record' do
69
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:error_record] }
70
- let(:test_data_error_xml_template) do
71
- ERB.new(stubbed_clixml('error_record.xml.erb'))
72
- end
73
- let(:error_message) { 'an error' }
74
- let(:script_root) { 'script_root' }
75
- let(:category_message) { 'category message' }
76
- let(:stack_trace) { 'stack trace' }
77
- let(:error_id) { 'Microsoft.PowerShell.Commands.WriteErrorException' }
78
- let(:data) { test_data_error_xml_template.result(binding) }
79
-
80
- it 'decodes error record' do
81
- expect(subject).to match(/#{error_message}/)
82
- end
83
- end
84
-
85
- context 'receiving error record in pipeline state' do
86
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state] }
87
- let(:test_data_error_xml_template) do
88
- ERB.new(stubbed_clixml('pipeline_state.xml.erb'))
89
- end
90
- let(:pipeline_state) { WinRM::PSRP::MessageData::PipelineState::FAILED }
91
- let(:error_message) { 'an error' }
92
- let(:category_message) { 'category message' }
93
- let(:error_id) { 'an error' }
94
- let(:data) { test_data_error_xml_template.result(binding) }
95
-
96
- it 'decodes error record' do
97
- expect(subject).to match(/#{error_message}/)
98
- end
99
- end
100
- end
1
+ # encoding: UTF-8
2
+
3
+ require 'winrm/psrp/powershell_output_decoder'
4
+
5
+ describe WinRM::PSRP::PowershellOutputDecoder do
6
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:error_record] }
7
+ let(:data) { 'blah' }
8
+ let(:message) do
9
+ WinRM::PSRP::Message.new(
10
+ 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
11
+ message_type,
12
+ data,
13
+ '4218a578-0f18-4b19-82c3-46b433319126'
14
+ )
15
+ end
16
+
17
+ subject { described_class.new.decode(message) }
18
+
19
+ context 'undecodable message type' do
20
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:public_key] }
21
+
22
+ it 'ignores message' do
23
+ expect(subject).to be nil
24
+ end
25
+ end
26
+
27
+ context 'undecodable method identifier' do
28
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call] }
29
+ let(:data) do
30
+ "\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I64 N=\"ci\">-100</I64><Obj N=\"mi\" RefId=\"1\">"\
31
+ '<TN RefId="0"><T>System.Management.Automation.Remoting.RemoteHostMethodId</T>'\
32
+ '<T>System.Enum</T><T>System.ValueType</T><T>System.Object</T></TN>'\
33
+ '<ToString>WriteProgress</ToString><I32>17</I32></Obj><Obj N="mp" RefId="2">'\
34
+ '<TN RefId="1"><T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST>'\
35
+ '<I32>7</I32><I32>0</I32><S>some_x000D__x000A_data</S></LST></Obj></MS></Obj>'
36
+ end
37
+
38
+ it 'ignores message' do
39
+ expect(subject).to be nil
40
+ end
41
+ end
42
+
43
+ context 'receiving pipeline output' do
44
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
45
+ let(:data) { '<obj><S>some data</S></obj>' }
46
+
47
+ it 'decodes output' do
48
+ expect(subject).to eq("some data\r\n")
49
+ end
50
+ end
51
+
52
+ context 'writeline with new line in middle' do
53
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call] }
54
+ let(:data) do
55
+ "\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I64 N=\"ci\">-100</I64><Obj N=\"mi\" RefId=\"1\">"\
56
+ '<TN RefId="0"><T>System.Management.Automation.Remoting.RemoteHostMethodId</T>'\
57
+ '<T>System.Enum</T><T>System.ValueType</T><T>System.Object</T></TN>'\
58
+ '<ToString>WriteLine3</ToString><I32>17</I32></Obj><Obj N="mp" RefId="2">'\
59
+ '<TN RefId="1"><T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST>'\
60
+ '<I32>7</I32><I32>0</I32><S>some_x000D__x000A_data</S></LST></Obj></MS></Obj>'
61
+ end
62
+
63
+ it 'decodes and replaces newline' do
64
+ expect(subject).to eq("some\r\ndata\r\n")
65
+ end
66
+ end
67
+
68
+ context 'receiving error record' do
69
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:error_record] }
70
+ let(:test_data_error_xml_template) do
71
+ ERB.new(stubbed_clixml('error_record.xml.erb'))
72
+ end
73
+ let(:error_message) { 'an error' }
74
+ let(:script_root) { 'script_root' }
75
+ let(:category_message) { 'category message' }
76
+ let(:stack_trace) { 'stack trace' }
77
+ let(:error_id) { 'Microsoft.PowerShell.Commands.WriteErrorException' }
78
+ let(:data) { test_data_error_xml_template.result(binding) }
79
+
80
+ it 'decodes error record' do
81
+ expect(subject).to match(/#{error_message}/)
82
+ end
83
+ end
84
+
85
+ context 'receiving error record in pipeline state' do
86
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state] }
87
+ let(:test_data_error_xml_template) do
88
+ ERB.new(stubbed_clixml('pipeline_state.xml.erb'))
89
+ end
90
+ let(:pipeline_state) { WinRM::PSRP::MessageData::PipelineState::FAILED }
91
+ let(:error_message) { 'an error' }
92
+ let(:category_message) { 'category message' }
93
+ let(:error_id) { 'an error' }
94
+ let(:data) { test_data_error_xml_template.result(binding) }
95
+
96
+ it 'decodes error record' do
97
+ expect(subject).to match(/#{error_message}/)
98
+ end
99
+ end
100
+ end
@@ -1,70 +1,70 @@
1
- # encoding: UTF-8
2
-
3
- require 'winrm/psrp/message'
4
-
5
- describe WinRM::PSRP::Message do
6
- context 'all fields provided' do
7
- let(:payload) { 'this is my payload' }
8
- subject do
9
- described_class.new(
10
- 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
11
- WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output],
12
- payload,
13
- '4218a578-0f18-4b19-82c3-46b433319126')
14
- end
15
-
16
- it 'sets the destination to server LE' do
17
- expect(subject.bytes[0..3]).to eq([2, 0, 0, 0])
18
- end
19
- it 'sets the message type LE' do
20
- expect(subject.bytes[4..7]).to eq([4, 16, 4, 0])
21
- end
22
- it 'sets the runspace pool id' do
23
- expect(subject.bytes[8..23]).to eq(
24
- [186, 251, 27, 188, 21, 130, 4, 74, 178, 223, 122, 58, 192, 49, 14, 22])
25
- end
26
- it 'sets the pipeline id' do
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])
29
- end
30
- it 'prefixes the blob with BOM' do
31
- expect(subject.bytes[40..42]).to eq([239, 187, 191])
32
- end
33
- it 'contains at least the first 8 bytes of the XML payload' do
34
- expect(subject.bytes[43..-1]).to eq(payload.bytes)
35
- end
36
- it 'parses the data' do
37
- expect(subject.parsed_data).to be_a(WinRM::PSRP::MessageData::PipelineOutput)
38
- end
39
- end
40
-
41
- context 'create' do
42
- it 'raises error when message type is not valid' do
43
- expect do
44
- WinRM::PSRP::Message.new(
45
- 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
46
- 0x00000000,
47
- %(<Obj RefId="0"/>),
48
- '4218a578-0f18-4b19-82c3-46b433319126')
49
- end.to raise_error(RuntimeError)
50
- end
51
- end
52
-
53
- context 'no command id' do
54
- subject(:msg) do
55
- payload = <<-HERE.unindent
56
- <Obj RefId="0"><MS><Version N="protocolversion">2.3</Version>
57
- <Version N="PSVersion">2.0</Version><Version N="SerializationVersion">1.1.0.1</Version></MS>
58
- </Obj>
59
- HERE
60
- WinRM::PSRP::Message.new(
61
- 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
62
- WinRM::PSRP::Message::MESSAGE_TYPES[:session_capability],
63
- payload)
64
- end
65
-
66
- it 'sets the pipeline id to empty' do
67
- expect(msg.bytes[24..39]).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
68
- end
69
- end
70
- end
1
+ # encoding: UTF-8
2
+
3
+ require 'winrm/psrp/message'
4
+
5
+ describe WinRM::PSRP::Message do
6
+ context 'all fields provided' do
7
+ let(:payload) { 'this is my payload' }
8
+ subject do
9
+ described_class.new(
10
+ 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
11
+ WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output],
12
+ payload,
13
+ '4218a578-0f18-4b19-82c3-46b433319126')
14
+ end
15
+
16
+ it 'sets the destination to server LE' do
17
+ expect(subject.bytes[0..3]).to eq([2, 0, 0, 0])
18
+ end
19
+ it 'sets the message type LE' do
20
+ expect(subject.bytes[4..7]).to eq([4, 16, 4, 0])
21
+ end
22
+ it 'sets the runspace pool id' do
23
+ expect(subject.bytes[8..23]).to eq(
24
+ [186, 251, 27, 188, 21, 130, 4, 74, 178, 223, 122, 58, 192, 49, 14, 22])
25
+ end
26
+ it 'sets the pipeline id' do
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])
29
+ end
30
+ it 'prefixes the blob with BOM' do
31
+ expect(subject.bytes[40..42]).to eq([239, 187, 191])
32
+ end
33
+ it 'contains at least the first 8 bytes of the XML payload' do
34
+ expect(subject.bytes[43..-1]).to eq(payload.bytes)
35
+ end
36
+ it 'parses the data' do
37
+ expect(subject.parsed_data).to be_a(WinRM::PSRP::MessageData::PipelineOutput)
38
+ end
39
+ end
40
+
41
+ context 'create' do
42
+ it 'raises error when message type is not valid' do
43
+ expect do
44
+ WinRM::PSRP::Message.new(
45
+ 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
46
+ 0x00000000,
47
+ %(<Obj RefId="0"/>),
48
+ '4218a578-0f18-4b19-82c3-46b433319126')
49
+ end.to raise_error(RuntimeError)
50
+ end
51
+ end
52
+
53
+ context 'no command id' do
54
+ subject(:msg) do
55
+ payload = <<-HERE.unindent
56
+ <Obj RefId="0"><MS><Version N="protocolversion">2.3</Version>
57
+ <Version N="PSVersion">2.0</Version><Version N="SerializationVersion">1.1.0.1</Version></MS>
58
+ </Obj>
59
+ HERE
60
+ WinRM::PSRP::Message.new(
61
+ 'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
62
+ WinRM::PSRP::Message::MESSAGE_TYPES[:session_capability],
63
+ payload)
64
+ end
65
+
66
+ it 'sets the pipeline id to empty' do
67
+ expect(msg.bytes[24..39]).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
68
+ end
69
+ end
70
+ end
@@ -1,172 +1,172 @@
1
- # encoding: UTF-8
2
-
3
- require 'winrm/psrp/receive_response_reader'
4
-
5
- describe WinRM::PSRP::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_powershell_output_response.xml.erb'))
11
- end
12
- let(:test_data_xml_template_not_done) do
13
- ERB.new(stubbed_response('get_powershell_output_response_not_done.xml.erb'))
14
- end
15
- let(:test_data_text) { 'some data' }
16
- let(:test_data) { "<obj><S>#{test_data_text}</S></obj>" }
17
- let(:message) do
18
- WinRM::PSRP::Message.new(
19
- shell_id,
20
- message_type,
21
- test_data,
22
- command_id
23
- )
24
- end
25
- let(:fragment) { WinRM::PSRP::Fragment.new(1, message.bytes) }
26
- let(:test_data_stdout) { Base64.strict_encode64(fragment.bytes.pack('C*')) }
27
- let(:transport) { {} }
28
-
29
- before do
30
- allow(transport).to receive(:send_request).and_return(
31
- REXML::Document.new(test_data_xml_template.result(binding))
32
- )
33
- end
34
-
35
- subject do
36
- described_class.new(
37
- transport,
38
- Logging.logger['test']
39
- )
40
- end
41
-
42
- describe '#read_output' do
43
- context 'response doc stdout with pipeline output' do
44
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
45
-
46
- it 'outputs to stdout' do
47
- expect(
48
- subject.read_output(output_message).stdout
49
- ).to eq("#{test_data_text}\r\n")
50
- end
51
- end
52
-
53
- context 'response doc stdout error record' do
54
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:error_record] }
55
- let(:test_data_error_xml_template) do
56
- ERB.new(stubbed_clixml('error_record.xml.erb'))
57
- end
58
- let(:error_message) { 'an error' }
59
- let(:script_root) { 'script_root' }
60
- let(:category_message) { 'category message' }
61
- let(:stack_trace) { 'stack trace' }
62
- let(:error_id) { 'Microsoft.PowerShell.Commands.WriteErrorException' }
63
- let(:test_data) { test_data_error_xml_template.result(binding) }
64
-
65
- it 'outputs to stderr' do
66
- expect(
67
- subject.read_output(output_message).stderr
68
- ).to match(/#{error_message}/)
69
- end
70
- end
71
-
72
- context 'response doc failed pipeline state' do
73
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state] }
74
- let(:test_data_error_xml_template) do
75
- ERB.new(stubbed_clixml('pipeline_state.xml.erb'))
76
- end
77
- let(:pipeline_state) { WinRM::PSRP::MessageData::PipelineState::FAILED }
78
- let(:error_message) { 'an error' }
79
- let(:category_message) { 'category message' }
80
- let(:error_id) { 'Microsoft.PowerShell.Commands.WriteErrorException' }
81
- let(:test_data) { test_data_error_xml_template.result(binding) }
82
-
83
- it 'outputs to stderr' do
84
- expect(
85
- subject.read_output(output_message).stderr
86
- ).to match(/#{error_message}/)
87
- end
88
- end
89
-
90
- context 'response doc writing error to host' do
91
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call] }
92
- let(:test_data) do
93
- "<Obj RefId='0'><MS><I64 N='ci'>-100</I64><Obj N='mi' RefId='1'><TN RefId='0'>" \
94
- '<T>System.Management.Automation.Remoting.RemoteHostMethodId</T><T>System.Enum</T>' \
95
- '<T>System.ValueType</T><T>System.Object</T></TN><ToString>WriteErrorLine</ToString>' \
96
- "<I32>18</I32></Obj><Obj N='mp' RefId='2'><TN RefId='1'>" \
97
- '<T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST><S>errors</S></LST>' \
98
- '</Obj></MS></Obj>'
99
- end
100
-
101
- it 'outputs to stderr' do
102
- expect(
103
- subject.read_output(output_message).stderr
104
- ).to eq("errors\r\n")
105
- end
106
- end
107
-
108
- context 'response doc writing output to host' do
109
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call] }
110
- let(:test_data) do
111
- "<Obj RefId='0'><MS><I64 N='ci'>-100</I64><Obj N='mi' RefId='1'><TN RefId='0'>" \
112
- '<T>System.Management.Automation.Remoting.RemoteHostMethodId</T><T>System.Enum</T>' \
113
- '<T>System.ValueType</T><T>System.Object</T></TN><ToString>WriteLine</ToString>' \
114
- "<I32>18</I32></Obj><Obj N='mp' RefId='2'><TN RefId='1'>" \
115
- '<T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST><S>output</S></LST>' \
116
- '</Obj></MS></Obj>'
117
- end
118
-
119
- it 'outputs to stdout' do
120
- expect(
121
- subject.read_output(output_message).stdout
122
- ).to eq("output\r\n")
123
- end
124
- end
125
- end
126
-
127
- describe '#read_message' do
128
- context 'do not wait for done state' do
129
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
130
-
131
- it 'outputs the message in an array' do
132
- expect(subject.read_message(output_message).length).to eq(1)
133
- expect(subject.read_message(output_message)[0].data).to end_with(message.data)
134
- end
135
- end
136
-
137
- context 'read in a block' do
138
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
139
-
140
- it 'outputs the message in an array' do
141
- subject.read_message(output_message) do |msg|
142
- expect(msg.data).to end_with(message.data)
143
- end
144
- end
145
- end
146
-
147
- context 'wait for done state' do
148
- let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
149
- let(:test_data_xml_not_done) { test_data_xml_template_not_done.result(binding) }
150
- let(:test_data_xml_done) { test_data_xml_template.result(binding) }
151
-
152
- before do
153
- allow(transport).to receive(:send_request).and_return(
154
- REXML::Document.new(test_data_xml_not_done),
155
- REXML::Document.new(test_data_xml_done)
156
- )
157
- end
158
-
159
- it 'outputs two messages' do
160
- expect(subject.read_message(output_message, true).length).to eq(2)
161
- end
162
-
163
- it 'outputs the first message' do
164
- expect(subject.read_message(output_message, true)[0].data).to end_with(message.data)
165
- end
166
-
167
- it 'outputs the second message' do
168
- expect(subject.read_message(output_message, true)[1].data).to end_with(message.data)
169
- end
170
- end
171
- end
172
- end
1
+ # encoding: UTF-8
2
+
3
+ require 'winrm/psrp/receive_response_reader'
4
+
5
+ describe WinRM::PSRP::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_powershell_output_response.xml.erb'))
11
+ end
12
+ let(:test_data_xml_template_not_done) do
13
+ ERB.new(stubbed_response('get_powershell_output_response_not_done.xml.erb'))
14
+ end
15
+ let(:test_data_text) { 'some data' }
16
+ let(:test_data) { "<obj><S>#{test_data_text}</S></obj>" }
17
+ let(:message) do
18
+ WinRM::PSRP::Message.new(
19
+ shell_id,
20
+ message_type,
21
+ test_data,
22
+ command_id
23
+ )
24
+ end
25
+ let(:fragment) { WinRM::PSRP::Fragment.new(1, message.bytes) }
26
+ let(:test_data_stdout) { Base64.strict_encode64(fragment.bytes.pack('C*')) }
27
+ let(:transport) { {} }
28
+
29
+ before do
30
+ allow(transport).to receive(:send_request).and_return(
31
+ REXML::Document.new(test_data_xml_template.result(binding))
32
+ )
33
+ end
34
+
35
+ subject do
36
+ described_class.new(
37
+ transport,
38
+ Logging.logger['test']
39
+ )
40
+ end
41
+
42
+ describe '#read_output' do
43
+ context 'response doc stdout with pipeline output' do
44
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
45
+
46
+ it 'outputs to stdout' do
47
+ expect(
48
+ subject.read_output(output_message).stdout
49
+ ).to eq("#{test_data_text}\r\n")
50
+ end
51
+ end
52
+
53
+ context 'response doc stdout error record' do
54
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:error_record] }
55
+ let(:test_data_error_xml_template) do
56
+ ERB.new(stubbed_clixml('error_record.xml.erb'))
57
+ end
58
+ let(:error_message) { 'an error' }
59
+ let(:script_root) { 'script_root' }
60
+ let(:category_message) { 'category message' }
61
+ let(:stack_trace) { 'stack trace' }
62
+ let(:error_id) { 'Microsoft.PowerShell.Commands.WriteErrorException' }
63
+ let(:test_data) { test_data_error_xml_template.result(binding) }
64
+
65
+ it 'outputs to stderr' do
66
+ expect(
67
+ subject.read_output(output_message).stderr
68
+ ).to match(/#{error_message}/)
69
+ end
70
+ end
71
+
72
+ context 'response doc failed pipeline state' do
73
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state] }
74
+ let(:test_data_error_xml_template) do
75
+ ERB.new(stubbed_clixml('pipeline_state.xml.erb'))
76
+ end
77
+ let(:pipeline_state) { WinRM::PSRP::MessageData::PipelineState::FAILED }
78
+ let(:error_message) { 'an error' }
79
+ let(:category_message) { 'category message' }
80
+ let(:error_id) { 'Microsoft.PowerShell.Commands.WriteErrorException' }
81
+ let(:test_data) { test_data_error_xml_template.result(binding) }
82
+
83
+ it 'outputs to stderr' do
84
+ expect(
85
+ subject.read_output(output_message).stderr
86
+ ).to match(/#{error_message}/)
87
+ end
88
+ end
89
+
90
+ context 'response doc writing error to host' do
91
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call] }
92
+ let(:test_data) do
93
+ "<Obj RefId='0'><MS><I64 N='ci'>-100</I64><Obj N='mi' RefId='1'><TN RefId='0'>" \
94
+ '<T>System.Management.Automation.Remoting.RemoteHostMethodId</T><T>System.Enum</T>' \
95
+ '<T>System.ValueType</T><T>System.Object</T></TN><ToString>WriteErrorLine</ToString>' \
96
+ "<I32>18</I32></Obj><Obj N='mp' RefId='2'><TN RefId='1'>" \
97
+ '<T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST><S>errors</S></LST>' \
98
+ '</Obj></MS></Obj>'
99
+ end
100
+
101
+ it 'outputs to stderr' do
102
+ expect(
103
+ subject.read_output(output_message).stderr
104
+ ).to eq("errors\r\n")
105
+ end
106
+ end
107
+
108
+ context 'response doc writing output to host' do
109
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call] }
110
+ let(:test_data) do
111
+ "<Obj RefId='0'><MS><I64 N='ci'>-100</I64><Obj N='mi' RefId='1'><TN RefId='0'>" \
112
+ '<T>System.Management.Automation.Remoting.RemoteHostMethodId</T><T>System.Enum</T>' \
113
+ '<T>System.ValueType</T><T>System.Object</T></TN><ToString>WriteLine</ToString>' \
114
+ "<I32>18</I32></Obj><Obj N='mp' RefId='2'><TN RefId='1'>" \
115
+ '<T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST><S>output</S></LST>' \
116
+ '</Obj></MS></Obj>'
117
+ end
118
+
119
+ it 'outputs to stdout' do
120
+ expect(
121
+ subject.read_output(output_message).stdout
122
+ ).to eq("output\r\n")
123
+ end
124
+ end
125
+ end
126
+
127
+ describe '#read_message' do
128
+ context 'do not wait for done state' do
129
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
130
+
131
+ it 'outputs the message in an array' do
132
+ expect(subject.read_message(output_message).length).to eq(1)
133
+ expect(subject.read_message(output_message)[0].data).to end_with(message.data)
134
+ end
135
+ end
136
+
137
+ context 'read in a block' do
138
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
139
+
140
+ it 'outputs the message in an array' do
141
+ subject.read_message(output_message) do |msg|
142
+ expect(msg.data).to end_with(message.data)
143
+ end
144
+ end
145
+ end
146
+
147
+ context 'wait for done state' do
148
+ let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
149
+ let(:test_data_xml_not_done) { test_data_xml_template_not_done.result(binding) }
150
+ let(:test_data_xml_done) { test_data_xml_template.result(binding) }
151
+
152
+ before do
153
+ allow(transport).to receive(:send_request).and_return(
154
+ REXML::Document.new(test_data_xml_not_done),
155
+ REXML::Document.new(test_data_xml_done)
156
+ )
157
+ end
158
+
159
+ it 'outputs two messages' do
160
+ expect(subject.read_message(output_message, true).length).to eq(2)
161
+ end
162
+
163
+ it 'outputs the first message' do
164
+ expect(subject.read_message(output_message, true)[0].data).to end_with(message.data)
165
+ end
166
+
167
+ it 'outputs the second message' do
168
+ expect(subject.read_message(output_message, true)[1].data).to end_with(message.data)
169
+ end
170
+ end
171
+ end
172
+ end