winrm 2.3.0 → 2.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/winrm/http/response_handler.rb +1 -1
- data/lib/winrm/http/transport.rb +2 -2
- data/lib/winrm/psrp/message.rb +128 -128
- data/lib/winrm/psrp/message_data/error_record.rb +2 -0
- data/lib/winrm/psrp/message_data/pipeline_output.rb +1 -1
- data/lib/winrm/psrp/message_factory.rb +14 -2
- data/lib/winrm/psrp/powershell_output_decoder.rb +142 -142
- data/lib/winrm/shells/base.rb +1 -0
- data/lib/winrm/shells/power_shell.rb +4 -4
- data/lib/winrm/version.rb +1 -1
- metadata +16 -90
- data/.gitignore +0 -10
- data/.rubocop.yml +0 -38
- data/.travis.yml +0 -10
- data/Gemfile +0 -2
- data/Rakefile +0 -33
- data/Vagrantfile +0 -6
- data/WinrmAppveyor.psm1 +0 -32
- data/appveyor.yml +0 -50
- data/changelog.md +0 -133
- data/preamble +0 -17
- data/tests/integration/auth_timeout_spec.rb +0 -17
- data/tests/integration/cmd_spec.rb +0 -130
- data/tests/integration/config-example.yml +0 -16
- data/tests/integration/issue_59_spec.rb +0 -25
- data/tests/integration/powershell_spec.rb +0 -164
- data/tests/integration/spec_helper.rb +0 -62
- data/tests/integration/transport_spec.rb +0 -98
- data/tests/integration/wql_spec.rb +0 -33
- data/tests/matchers.rb +0 -59
- data/tests/spec/configuration_spec.rb +0 -183
- data/tests/spec/connection_spec.rb +0 -37
- data/tests/spec/exception_spec.rb +0 -49
- data/tests/spec/http/transport_factory_spec.rb +0 -66
- data/tests/spec/http/transport_spec.rb +0 -43
- data/tests/spec/output_spec.rb +0 -128
- data/tests/spec/psrp/fragment_spec.rb +0 -60
- data/tests/spec/psrp/message_data/base_spec.rb +0 -11
- data/tests/spec/psrp/message_data/error_record_spec.rb +0 -39
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -23
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -30
- data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -38
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -23
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -14
- data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -28
- data/tests/spec/psrp/message_data_spec.rb +0 -33
- data/tests/spec/psrp/message_defragmenter_spec.rb +0 -45
- data/tests/spec/psrp/message_fragmenter_spec.rb +0 -103
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -98
- data/tests/spec/psrp/psrp_message_spec.rb +0 -73
- data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -170
- data/tests/spec/psrp/uuid_spec.rb +0 -28
- data/tests/spec/response_handler_spec.rb +0 -69
- data/tests/spec/shells/base_spec.rb +0 -227
- data/tests/spec/shells/cmd_spec.rb +0 -75
- data/tests/spec/shells/powershell_spec.rb +0 -221
- data/tests/spec/spec_helper.rb +0 -46
- data/tests/spec/stubs/clixml/error_record.xml.erb +0 -84
- data/tests/spec/stubs/clixml/pipeline_state.xml.erb +0 -88
- data/tests/spec/stubs/responses/get_command_output_response.xml.erb +0 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +0 -10
- data/tests/spec/stubs/responses/get_omi_command_output_response.xml.erb +0 -23
- data/tests/spec/stubs/responses/get_omi_command_output_response_not_done.xml.erb +0 -24
- data/tests/spec/stubs/responses/get_omi_config_response.xml +0 -45
- data/tests/spec/stubs/responses/get_omi_powershell_keepalive_response.xml.erb +0 -33
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +0 -10
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +0 -12
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +0 -9
- data/tests/spec/stubs/responses/open_shell_omi.xml +0 -43
- data/tests/spec/stubs/responses/open_shell_v1.xml +0 -19
- data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
- data/tests/spec/stubs/responses/soap_fault_omi.xml +0 -31
- data/tests/spec/stubs/responses/soap_fault_v1.xml +0 -36
- data/tests/spec/stubs/responses/soap_fault_v2.xml +0 -42
- data/tests/spec/stubs/responses/wmi_error_v2.xml +0 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +0 -20
- data/tests/spec/wsmv/close_shell_spec.rb +0 -15
- data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -35
- data/tests/spec/wsmv/command_output_spec.rb +0 -43
- data/tests/spec/wsmv/command_spec.rb +0 -17
- data/tests/spec/wsmv/configuration_spec.rb +0 -15
- data/tests/spec/wsmv/create_pipeline_spec.rb +0 -30
- data/tests/spec/wsmv/create_shell_spec.rb +0 -39
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -38
- data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
- data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -124
- data/tests/spec/wsmv/send_data_spec.rb +0 -30
- data/tests/spec/wsmv/wql_query_spec.rb +0 -11
- data/tests/spec/wsmv/write_stdin_spec.rb +0 -20
- data/winrm.gemspec +0 -46
data/tests/spec/output_spec.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
describe WinRM::Output do
|
2
|
-
subject { WinRM::Output.new }
|
3
|
-
|
4
|
-
context 'when there is no output' do
|
5
|
-
describe '#stdout' do
|
6
|
-
it 'is empty' do
|
7
|
-
expect(subject.stdout).to be_empty
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#stderr' do
|
12
|
-
it 'is empty' do
|
13
|
-
expect(subject.stderr).to be_empty
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#output' do
|
18
|
-
it 'is empty' do
|
19
|
-
expect(subject.output).to be_empty
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when there is only one line' do
|
25
|
-
describe '#stdout' do
|
26
|
-
it 'is equal to that line' do
|
27
|
-
subject << { stdout: 'foo' }
|
28
|
-
expect(subject.stdout).to eq('foo')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#stderr' do
|
33
|
-
it 'is equal to that line' do
|
34
|
-
subject << { stderr: 'foo' }
|
35
|
-
expect(subject.stderr).to eq('foo')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#output' do
|
40
|
-
it 'is equal to stdout' do
|
41
|
-
subject << { stdout: 'foo' }
|
42
|
-
expect(subject.output).to eq('foo')
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'is equal to stderr' do
|
46
|
-
subject << { stderr: 'foo' }
|
47
|
-
expect(subject.output).to eq('foo')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'when there is one line of each type' do
|
53
|
-
before(:each) do
|
54
|
-
subject << { stdout: 'foo' }
|
55
|
-
subject << { stderr: 'bar' }
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#stdout' do
|
59
|
-
it 'is equal to that line' do
|
60
|
-
expect(subject.stdout).to eq('foo')
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#stderr' do
|
65
|
-
it 'is equal to that line' do
|
66
|
-
expect(subject.stderr).to eq('bar')
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe '#output' do
|
71
|
-
it 'is equal to stdout + stderr' do
|
72
|
-
expect(subject.output).to eq('foobar')
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'when there are multiple lines' do
|
78
|
-
before(:each) do
|
79
|
-
subject << { stdout: 'I can have a newline\nanywhere, ' }
|
80
|
-
subject << { stderr: 'I can also have stderr' }
|
81
|
-
subject << { stdout: 'or stdout', stderr: ' and stderr' }
|
82
|
-
subject << {}
|
83
|
-
subject << { stdout: ' or nothing! (above)' }
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#stdout' do
|
87
|
-
it 'is equal to that line' do
|
88
|
-
expect(subject.stdout).to eq(
|
89
|
-
'I can have a newline\nanywhere, or stdout or nothing! (above)'
|
90
|
-
)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe '#stderr' do
|
95
|
-
it 'is equal to that line' do
|
96
|
-
expect(subject.stderr).to eq('I can also have stderr and stderr')
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe '#output' do
|
101
|
-
it 'is equal to stdout + stderr' do
|
102
|
-
expect(subject.output).to eq(
|
103
|
-
'I can have a newline\nanywhere, I can also have stderror stdout ' \
|
104
|
-
'and stderr or nothing! (above)'
|
105
|
-
)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe '#exitcode' do
|
111
|
-
let(:exitcode) { 0 }
|
112
|
-
|
113
|
-
context 'when a valid exit code is set' do
|
114
|
-
it 'sets the exit code' do
|
115
|
-
subject.exitcode = exitcode
|
116
|
-
expect(subject.exitcode).to eq exitcode
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'when an invalid exit code is set' do
|
121
|
-
let(:exitcode) { 'bad' }
|
122
|
-
|
123
|
-
it 'sets the exit code' do
|
124
|
-
expect { subject.exitcode = exitcode }.to raise_error WinRM::InvalidExitCode
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/fragment'
|
2
|
-
|
3
|
-
describe WinRM::PSRP::Fragment do
|
4
|
-
let(:id) { 1 }
|
5
|
-
let(:message) { 'blah blah blah' }
|
6
|
-
|
7
|
-
context 'called with just id and blob' do
|
8
|
-
subject { described_class.new(id, message.bytes) }
|
9
|
-
|
10
|
-
it 'sets the message id to 1' do
|
11
|
-
expect(subject.bytes[0..7]).to eq([0, 0, 0, 0, 0, 0, 0, id])
|
12
|
-
end
|
13
|
-
it 'sets the fragment id to 0' do
|
14
|
-
expect(subject.bytes[8..15]).to eq([0, 0, 0, 0, 0, 0, 0, 0])
|
15
|
-
end
|
16
|
-
it 'sets the last 2 bits of the end/start fragment' do
|
17
|
-
expect(subject.bytes[16]).to eq(3)
|
18
|
-
end
|
19
|
-
it 'sets message blob length to 3640' do
|
20
|
-
expect(subject.bytes[17..20]).to eq([0, 0, 0, message.bytes.length])
|
21
|
-
end
|
22
|
-
it 'sets message blob' do
|
23
|
-
expect(subject.bytes[21..-1]).to eq(message.bytes)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'specifying a fragment id' do
|
28
|
-
let(:fragment_id) { 1 }
|
29
|
-
|
30
|
-
subject { described_class.new(id, message.bytes, fragment_id) }
|
31
|
-
|
32
|
-
it 'sets the fragment id' do
|
33
|
-
expect(subject.bytes[8..15]).to eq([0, 0, 0, 0, 0, 0, 0, fragment_id])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'middle fragment' do
|
38
|
-
subject { described_class.new(id, message.bytes, 1, false, false) }
|
39
|
-
|
40
|
-
it 'sets the last 2 bits of the end/start fragment to 0' do
|
41
|
-
expect(subject.bytes[16]).to eq(0)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'end fragment' do
|
46
|
-
subject { described_class.new(id, message.bytes, 1, true, false) }
|
47
|
-
|
48
|
-
it 'sets the end fragment bit' do
|
49
|
-
expect(subject.bytes[16]).to eq(1)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'start fragment' do
|
54
|
-
subject { described_class.new(id, message.bytes, 1, false, true) }
|
55
|
-
|
56
|
-
it 'sets the start fragment bit' do
|
57
|
-
expect(subject.bytes[16]).to eq(2)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message_data/base'
|
2
|
-
|
3
|
-
describe WinRM::PSRP::MessageData::Base do
|
4
|
-
let(:raw_data) { 'raw_data' }
|
5
|
-
|
6
|
-
subject { WinRM::PSRP::MessageData::Base.new(raw_data) }
|
7
|
-
|
8
|
-
it 'holds raw message data' do
|
9
|
-
expect(subject.raw).to eq(raw_data)
|
10
|
-
end
|
11
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message_data/base'
|
2
|
-
require 'winrm/psrp/message_data/error_record'
|
3
|
-
|
4
|
-
describe WinRM::PSRP::MessageData::ErrorRecord do
|
5
|
-
let(:test_data_xml_template) do
|
6
|
-
ERB.new(stubbed_clixml('error_record.xml.erb'))
|
7
|
-
end
|
8
|
-
let(:error_message) { 'an error' }
|
9
|
-
let(:script_root) { 'script_root' }
|
10
|
-
let(:category_message) { 'category message' }
|
11
|
-
let(:stack_trace) { 'stack trace' }
|
12
|
-
let(:error_id) { 'Microsoft.PowerShell.Commands.WriteErrorException' }
|
13
|
-
let(:raw_data) { test_data_xml_template.result(binding) }
|
14
|
-
subject { described_class.new(raw_data) }
|
15
|
-
|
16
|
-
it 'returns the exception' do
|
17
|
-
expect(subject.exception[:message]).to eq(error_message)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns the FullyQualifiedErrorId' do
|
21
|
-
expect(subject.fully_qualified_error_id).to eq(error_id)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns the invocation info' do
|
25
|
-
expect(subject.invocation_info[:line]).to eq("write-error '#{error_message}'")
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'converts camel case properties to underscore' do
|
29
|
-
expect(subject.invocation_info[:ps_script_root]).to eq(script_root)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns the error category message' do
|
33
|
-
expect(subject.error_category_message).to eq(category_message)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns the script stack trace' do
|
37
|
-
expect(subject.error_details_script_stack_trace).to eq(stack_trace)
|
38
|
-
end
|
39
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message_data/base'
|
2
|
-
require 'winrm/psrp/message_data/pipeline_host_call'
|
3
|
-
|
4
|
-
describe WinRM::PSRP::MessageData::PipelineHostCall do
|
5
|
-
let(:raw_data) do
|
6
|
-
"\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I64 N=\"ci\">-100</I64><Obj N=\"mi\" RefId=\"1\">"\
|
7
|
-
'<TN RefId="0"><T>System.Management.Automation.Remoting.RemoteHostMethodId</T>'\
|
8
|
-
'<T>System.Enum</T><T>System.ValueType</T><T>System.Object</T></TN>'\
|
9
|
-
'<ToString>WriteLine3</ToString><I32>17</I32></Obj><Obj N="mp" RefId="2">'\
|
10
|
-
'<TN RefId="1"><T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST>'\
|
11
|
-
'<I32>7</I32><I32>0</I32><S>hello</S></LST></Obj></MS></Obj>'
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { described_class.new(raw_data) }
|
15
|
-
|
16
|
-
it 'parses method identifier' do
|
17
|
-
expect(subject.method_identifier).to eq('WriteLine3')
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'parses method parameters' do
|
21
|
-
expect(subject.method_parameters[:s]).to eq('hello')
|
22
|
-
end
|
23
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message_data/base'
|
2
|
-
require 'winrm/psrp/message_data/pipeline_output'
|
3
|
-
|
4
|
-
describe WinRM::PSRP::MessageData::PipelineOutput do
|
5
|
-
subject { described_class.new(raw_data) }
|
6
|
-
|
7
|
-
context 'receiving output with BOM and no new line' do
|
8
|
-
let(:raw_data) { "\xEF\xBB\xBF<obj><S>some data</S></obj>" }
|
9
|
-
|
10
|
-
it 'output removes BOM and adds newline' do
|
11
|
-
expect(subject.output).to eq("some data\r\n")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'receiving output with encoded new line' do
|
16
|
-
let(:raw_data) { '<obj><S>some data_x000D__x000A_</S></obj>' }
|
17
|
-
|
18
|
-
it 'decodes without double newline' do
|
19
|
-
expect(subject.output).to eq("some data\r\n")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'receiving output with new line in middle' do
|
24
|
-
let(:raw_data) { '<obj><S>some_x000D__x000A_data</S></obj>' }
|
25
|
-
|
26
|
-
it 'decodes and replaces newline' do
|
27
|
-
expect(subject.output).to eq("some\r\ndata\r\n")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message_data/base'
|
2
|
-
require 'winrm/psrp/message_data/pipeline_state'
|
3
|
-
|
4
|
-
describe WinRM::PSRP::MessageData::PipelineState do
|
5
|
-
let(:test_data_xml_template) do
|
6
|
-
ERB.new(stubbed_clixml('pipeline_state.xml.erb'))
|
7
|
-
end
|
8
|
-
let(:pipeline_state) { WinRM::PSRP::MessageData::PipelineState::FAILED }
|
9
|
-
let(:error_message) { 'an error occured' }
|
10
|
-
let(:category_message) { 'category message' }
|
11
|
-
let(:error_id) { 'an error occured' }
|
12
|
-
let(:raw_data) { test_data_xml_template.result(binding) }
|
13
|
-
subject { described_class.new(raw_data) }
|
14
|
-
|
15
|
-
it 'returns the state' do
|
16
|
-
expect(subject.pipeline_state).to eq(pipeline_state)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns the exception' do
|
20
|
-
expect(subject.exception_as_error_record.exception[:message]).to eq(error_message)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns the FullyQualifiedErrorId' do
|
24
|
-
expect(subject.exception_as_error_record.fully_qualified_error_id).to eq(error_id)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns the error category message' do
|
28
|
-
expect(subject.exception_as_error_record.error_category_message).to eq(category_message)
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'state is not failed' do
|
32
|
-
let(:pipeline_state) { WinRM::PSRP::MessageData::PipelineState::COMPLETED }
|
33
|
-
|
34
|
-
it 'has a nil exception' do
|
35
|
-
expect(subject.exception_as_error_record).to be(nil)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message_data/base'
|
2
|
-
require 'winrm/psrp/message_data/runspacepool_host_call'
|
3
|
-
|
4
|
-
describe WinRM::PSRP::MessageData::RunspacepoolHostCall do
|
5
|
-
let(:raw_data) do
|
6
|
-
"\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I64 N=\"ci\">-100</I64><Obj N=\"mi\" RefId=\"1\">"\
|
7
|
-
'<TN RefId="0"><T>System.Management.Automation.Remoting.RemoteHostMethodId</T>'\
|
8
|
-
'<T>System.Enum</T><T>System.ValueType</T><T>System.Object</T></TN>'\
|
9
|
-
'<ToString>WriteLine3</ToString><I32>17</I32></Obj><Obj N="mp" RefId="2">'\
|
10
|
-
'<TN RefId="1"><T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST>'\
|
11
|
-
'<I32>7</I32><I32>0</I32><S>hello</S></LST></Obj></MS></Obj>'
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { described_class.new(raw_data) }
|
15
|
-
|
16
|
-
it 'parses method identifier' do
|
17
|
-
expect(subject.method_identifier).to eq('WriteLine3')
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'parses method parameters' do
|
21
|
-
expect(subject.method_parameters[:s]).to eq('hello')
|
22
|
-
end
|
23
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message_data/base'
|
2
|
-
require 'winrm/psrp/message_data/runspacepool_state'
|
3
|
-
|
4
|
-
describe WinRM::PSRP::MessageData::RunspacepoolState do
|
5
|
-
let(:raw_data) do
|
6
|
-
"\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I32 N=\"RunspaceState\">2</I32></MS></Obj>"
|
7
|
-
end
|
8
|
-
|
9
|
-
subject { described_class.new(raw_data) }
|
10
|
-
|
11
|
-
it 'parses runspace state' do
|
12
|
-
expect(subject.runspace_state).to eq(WinRM::PSRP::MessageData::RunspacepoolState::OPENED)
|
13
|
-
end
|
14
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message_data/base'
|
2
|
-
require 'winrm/psrp/message_data/session_capability'
|
3
|
-
|
4
|
-
describe WinRM::PSRP::MessageData::SessionCapability do
|
5
|
-
let(:protocol_version) { '2.2' }
|
6
|
-
let(:ps_version) { '2.0' }
|
7
|
-
let(:serialization_version) { '1.1.0.1' }
|
8
|
-
let(:raw_data) do
|
9
|
-
"\xEF\xBB\xBF<Obj RefId=\"0\"><MS>"\
|
10
|
-
"<Version N=\"protocolversion\">#{protocol_version}</Version>"\
|
11
|
-
"<Version N=\"PSVersion\">#{ps_version}</Version>"\
|
12
|
-
"<Version N=\"SerializationVersion\">#{serialization_version}</Version></MS></Obj>"
|
13
|
-
end
|
14
|
-
|
15
|
-
subject { described_class.new(raw_data) }
|
16
|
-
|
17
|
-
it 'parses protocol version' do
|
18
|
-
expect(subject.protocol_version).to eq(protocol_version)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'parses ps version' do
|
22
|
-
expect(subject.ps_version).to eq(ps_version)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'parses serialization version' do
|
26
|
-
expect(subject.serialization_version).to eq(serialization_version)
|
27
|
-
end
|
28
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message'
|
2
|
-
require 'winrm/psrp/message_data'
|
3
|
-
|
4
|
-
describe WinRM::PSRP::MessageData do
|
5
|
-
describe '#parse' do
|
6
|
-
let(:raw_data) { 'raw_data' }
|
7
|
-
let(:message) do
|
8
|
-
WinRM::PSRP::Message.new(
|
9
|
-
'00000000-0000-0000-0000-000000000000',
|
10
|
-
message_type,
|
11
|
-
raw_data
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
subject { WinRM::PSRP::MessageData.parse(message) }
|
16
|
-
|
17
|
-
context 'defined message type' do
|
18
|
-
let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output] }
|
19
|
-
|
20
|
-
it 'creates correct message data type' do
|
21
|
-
expect(subject).to be_a(WinRM::PSRP::MessageData::PipelineOutput)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'undefined message type' do
|
26
|
-
let(:message_type) { WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_input] }
|
27
|
-
|
28
|
-
it 'returns nill' do
|
29
|
-
expect(subject).to be nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'winrm/psrp/message_defragmenter'
|
2
|
-
|
3
|
-
describe WinRM::PSRP::MessageDefragmenter do
|
4
|
-
context 'a real life fragment' do
|
5
|
-
let(:bytes) do
|
6
|
-
"\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x01\x03\x00\x00\x00I\x01"\
|
7
|
-
"\x00\x00\x00\x04\x10\x04\x00Kk/=Z\xD3-E\x81v\xA0+6\xB1\xD3\x88\n\xED\x90\x9Cj\xE7PG"\
|
8
|
-
"\x9F\xA2\xB2\xC99to9\xEF\xBB\xBF<S>some data_x000D__x000A_</S>".to_byte_string
|
9
|
-
end
|
10
|
-
subject { described_class.new.defragment(Base64.encode64(bytes)) }
|
11
|
-
|
12
|
-
it 'parses the data' do
|
13
|
-
expect(subject.data).to eq("\xEF\xBB\xBF<S>some data_x000D__x000A_</S>".to_byte_string)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'parses the destination' do
|
17
|
-
expect(subject.destination).to eq(1)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'parses the message type' do
|
21
|
-
expect(subject.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output])
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'multiple fragments' do
|
26
|
-
let(:blob) do
|
27
|
-
WinRM::PSRP::Message.new(
|
28
|
-
'bc1bfbba-8215-4a04-b2df-7a3ac0310e16',
|
29
|
-
WinRM::PSRP::Message::MESSAGE_TYPES[:session_capability],
|
30
|
-
'This is a fragmented message'
|
31
|
-
)
|
32
|
-
end
|
33
|
-
let(:fragment1) { WinRM::PSRP::Fragment.new(1, blob.bytes[0..5], 0, true, false) }
|
34
|
-
let(:fragment2) { WinRM::PSRP::Fragment.new(1, blob.bytes[6..10], 1, false, false) }
|
35
|
-
let(:fragment3) { WinRM::PSRP::Fragment.new(1, blob.bytes[11..-1], 2, false, true) }
|
36
|
-
|
37
|
-
it 'pieces the message together' do
|
38
|
-
subject.defragment(Base64.strict_encode64(fragment1.bytes.pack('C*')))
|
39
|
-
subject.defragment(Base64.strict_encode64(fragment2.bytes.pack('C*')))
|
40
|
-
message = subject.defragment(Base64.strict_encode64(fragment3.bytes.pack('C*')))
|
41
|
-
|
42
|
-
expect(message.data[3..-1]).to eq(blob.data)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|