winrm 2.2.3 → 2.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/bin/rwinrm +90 -97
- data/lib/winrm/connection.rb +84 -86
- data/lib/winrm/connection_opts.rb +90 -91
- data/lib/winrm/exceptions.rb +14 -2
- data/lib/winrm/http/response_handler.rb +127 -96
- data/lib/winrm/http/transport.rb +462 -427
- data/lib/winrm/http/transport_factory.rb +1 -5
- data/lib/winrm/output.rb +1 -2
- data/lib/winrm/psrp/fragment.rb +0 -2
- data/lib/winrm/psrp/message.rb +128 -130
- data/lib/winrm/psrp/message_data/base.rb +0 -2
- data/lib/winrm/psrp/message_data/error_record.rb +2 -2
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +0 -2
- data/lib/winrm/psrp/message_data/pipeline_output.rb +48 -54
- data/lib/winrm/psrp/message_data/pipeline_state.rb +0 -2
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +0 -2
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +0 -2
- data/lib/winrm/psrp/message_data/session_capability.rb +0 -2
- data/lib/winrm/psrp/message_data.rb +0 -2
- data/lib/winrm/psrp/message_defragmenter.rb +2 -2
- data/lib/winrm/psrp/message_factory.rb +16 -5
- data/lib/winrm/psrp/message_fragmenter.rb +1 -3
- data/lib/winrm/psrp/powershell_output_decoder.rb +142 -144
- data/lib/winrm/psrp/receive_response_reader.rb +3 -5
- data/lib/winrm/psrp/uuid.rb +1 -2
- data/lib/winrm/shells/base.rb +7 -4
- data/lib/winrm/shells/cmd.rb +63 -65
- data/lib/winrm/shells/power_shell.rb +207 -202
- data/lib/winrm/shells/retryable.rb +44 -45
- data/lib/winrm/shells/shell_factory.rb +0 -2
- data/lib/winrm/version.rb +1 -3
- data/lib/winrm/wsmv/base.rb +0 -2
- data/lib/winrm/wsmv/cleanup_command.rb +1 -2
- data/lib/winrm/wsmv/close_shell.rb +1 -2
- data/lib/winrm/wsmv/command.rb +2 -3
- data/lib/winrm/wsmv/command_output.rb +2 -3
- data/lib/winrm/wsmv/command_output_decoder.rb +1 -2
- data/lib/winrm/wsmv/configuration.rb +0 -2
- data/lib/winrm/wsmv/create_pipeline.rb +0 -2
- data/lib/winrm/wsmv/create_shell.rb +2 -6
- data/lib/winrm/wsmv/header.rb +213 -215
- data/lib/winrm/wsmv/init_runspace_pool.rb +96 -95
- data/lib/winrm/wsmv/iso8601_duration.rb +0 -2
- data/lib/winrm/wsmv/keep_alive.rb +0 -2
- data/lib/winrm/wsmv/receive_response_reader.rb +128 -126
- data/lib/winrm/wsmv/send_data.rb +0 -2
- data/lib/winrm/wsmv/soap.rb +0 -2
- data/lib/winrm/wsmv/wql_pull.rb +54 -56
- data/lib/winrm/wsmv/wql_query.rb +98 -99
- data/lib/winrm/wsmv/write_stdin.rb +0 -2
- data/lib/winrm.rb +3 -5
- metadata +81 -135
- data/.gitignore +0 -10
- data/.rubocop.yml +0 -26
- data/.travis.yml +0 -11
- data/Gemfile +0 -3
- data/Rakefile +0 -34
- data/Vagrantfile +0 -6
- data/WinrmAppveyor.psm1 +0 -32
- data/appveyor.yml +0 -51
- data/changelog.md +0 -128
- data/preamble +0 -17
- data/tests/integration/auth_timeout_spec.rb +0 -18
- data/tests/integration/cmd_spec.rb +0 -131
- data/tests/integration/config-example.yml +0 -16
- data/tests/integration/issue_59_spec.rb +0 -26
- data/tests/integration/powershell_spec.rb +0 -165
- data/tests/integration/spec_helper.rb +0 -65
- data/tests/integration/transport_spec.rb +0 -99
- data/tests/integration/wql_spec.rb +0 -34
- data/tests/matchers.rb +0 -60
- data/tests/spec/configuration_spec.rb +0 -184
- data/tests/spec/connection_spec.rb +0 -39
- data/tests/spec/exception_spec.rb +0 -50
- data/tests/spec/http/transport_factory_spec.rb +0 -68
- data/tests/spec/http/transport_spec.rb +0 -44
- data/tests/spec/output_spec.rb +0 -127
- data/tests/spec/psrp/fragment_spec.rb +0 -62
- data/tests/spec/psrp/message_data/base_spec.rb +0 -13
- data/tests/spec/psrp/message_data/error_record_spec.rb +0 -41
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -25
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -32
- data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -40
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -25
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -16
- data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -30
- data/tests/spec/psrp/message_data_spec.rb +0 -35
- data/tests/spec/psrp/message_defragmenter_spec.rb +0 -47
- data/tests/spec/psrp/message_fragmenter_spec.rb +0 -105
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -100
- data/tests/spec/psrp/psrp_message_spec.rb +0 -70
- data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -172
- data/tests/spec/psrp/uuid_spec.rb +0 -28
- data/tests/spec/response_handler_spec.rb +0 -61
- data/tests/spec/shells/base_spec.rb +0 -225
- data/tests/spec/shells/cmd_spec.rb +0 -75
- data/tests/spec/shells/powershell_spec.rb +0 -175
- data/tests/spec/spec_helper.rb +0 -47
- 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_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_v1.xml +0 -19
- data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
- 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 -22
- data/tests/spec/wsmv/close_shell_spec.rb +0 -17
- data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -37
- data/tests/spec/wsmv/command_output_spec.rb +0 -45
- data/tests/spec/wsmv/command_spec.rb +0 -19
- data/tests/spec/wsmv/configuration_spec.rb +0 -17
- data/tests/spec/wsmv/create_pipeline_spec.rb +0 -31
- data/tests/spec/wsmv/create_shell_spec.rb +0 -38
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -36
- data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
- data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -123
- data/tests/spec/wsmv/send_data_spec.rb +0 -30
- data/tests/spec/wsmv/wql_query_spec.rb +0 -13
- data/tests/spec/wsmv/write_stdin_spec.rb +0 -22
- data/winrm.gemspec +0 -47
@@ -1,184 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'winrm/connection_opts'
|
3
|
-
|
4
|
-
describe WinRM::ConnectionOpts do
|
5
|
-
shared_examples 'invalid options' do
|
6
|
-
it 'throws a validation error' do
|
7
|
-
expect { WinRM::ConnectionOpts.create_with_defaults(overrides) }.to raise_error
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'when there are no overrides' do
|
12
|
-
it_behaves_like 'invalid options'
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when there are only username and password' do
|
16
|
-
let(:overrides) do
|
17
|
-
{
|
18
|
-
user: 'Administrator',
|
19
|
-
password: 'password'
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
it_behaves_like 'invalid options'
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when there are only username and endpoint' do
|
27
|
-
let(:overrides) do
|
28
|
-
{
|
29
|
-
user: 'Administrator',
|
30
|
-
endpoint: 'http://localhost:5985/wsman'
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
it_behaves_like 'invalid options'
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when there are only password and endpoint' do
|
38
|
-
let(:overrides) do
|
39
|
-
{
|
40
|
-
password: 'password',
|
41
|
-
endpoint: 'http://localhost:5985/wsman'
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
it_behaves_like 'invalid options'
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when there are only certificate and key' do
|
49
|
-
let(:overrides) do
|
50
|
-
{
|
51
|
-
client_cert: 'path/to/cert',
|
52
|
-
client_key: 'path/to/key'
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
it_behaves_like 'invalid options'
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'when there are only certificate and endpoint' do
|
60
|
-
let(:overrides) do
|
61
|
-
{
|
62
|
-
client_cert: 'path/to/cert',
|
63
|
-
endpoint: 'http://localhost:5985/wsman'
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
it_behaves_like 'invalid options'
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when there are only key and endpoint' do
|
71
|
-
let(:overrides) do
|
72
|
-
{
|
73
|
-
client_key: 'path/to/key',
|
74
|
-
endpoint: 'http://localhost:5985/wsman'
|
75
|
-
}
|
76
|
-
end
|
77
|
-
|
78
|
-
it_behaves_like 'invalid options'
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'when username, password, and endpoint are given' do
|
82
|
-
let(:overrides) do
|
83
|
-
{
|
84
|
-
user: 'Administrator',
|
85
|
-
password: 'password',
|
86
|
-
endpoint: 'http://localhost:5985/wsman'
|
87
|
-
}
|
88
|
-
end
|
89
|
-
describe '#create_with_defaults' do
|
90
|
-
it 'creates a ConnectionOpts object' do
|
91
|
-
config = WinRM::ConnectionOpts.create_with_defaults(overrides)
|
92
|
-
expect(config[:user]).to eq(overrides[:user])
|
93
|
-
expect(config[:password]).to eq(overrides[:password])
|
94
|
-
expect(config[:endpoint]).to eq(overrides[:endpoint])
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'when certificate, key and endpoint are given' do
|
100
|
-
let(:overrides) do
|
101
|
-
{
|
102
|
-
client_cert: 'path/to/cert',
|
103
|
-
client_key: 'path/to/key',
|
104
|
-
endpoint: 'http://localhost:5985/wsman'
|
105
|
-
}
|
106
|
-
end
|
107
|
-
describe '#create_with_defaults' do
|
108
|
-
it 'creates a ConnectionOpts object' do
|
109
|
-
config = WinRM::ConnectionOpts.create_with_defaults(overrides)
|
110
|
-
expect(config[:client_cert]).to eq(overrides[:client_cert])
|
111
|
-
expect(config[:client_key]).to eq(overrides[:client_key])
|
112
|
-
expect(config[:endpoint]).to eq(overrides[:endpoint])
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'when overrides are provided' do
|
118
|
-
let(:overrides) do
|
119
|
-
{
|
120
|
-
user: 'Administrator',
|
121
|
-
password: 'password',
|
122
|
-
endpoint: 'http://localhost:5985/wsman',
|
123
|
-
transport: :ssl
|
124
|
-
}
|
125
|
-
end
|
126
|
-
describe '#create_with_defaults' do
|
127
|
-
it 'creates a ConnectionOpts object with overrides' do
|
128
|
-
config = WinRM::ConnectionOpts.create_with_defaults(overrides)
|
129
|
-
expect(config[:transport]).to eq(overrides[:transport])
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'when receive_timeout is specified' do
|
135
|
-
let(:overrides) do
|
136
|
-
{
|
137
|
-
user: 'Administrator',
|
138
|
-
password: 'password',
|
139
|
-
endpoint: 'http://localhost:5985/wsman',
|
140
|
-
receive_timeout: 120
|
141
|
-
}
|
142
|
-
end
|
143
|
-
describe '#create_with_defaults' do
|
144
|
-
it 'creates a ConnectionOpts object with the correct receive_timeout' do
|
145
|
-
config = WinRM::ConnectionOpts.create_with_defaults(overrides)
|
146
|
-
expect(config[:receive_timeout]).to eq(overrides[:receive_timeout])
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
context 'when operation_timeout is specified' do
|
152
|
-
let(:overrides) do
|
153
|
-
{
|
154
|
-
user: 'Administrator',
|
155
|
-
password: 'password',
|
156
|
-
endpoint: 'http://localhost:5985/wsman',
|
157
|
-
operation_timeout: 120
|
158
|
-
}
|
159
|
-
end
|
160
|
-
describe '#create_with_defaults' do
|
161
|
-
it 'creates a ConnectionOpts object with the correct timeouts' do
|
162
|
-
config = WinRM::ConnectionOpts.create_with_defaults(overrides)
|
163
|
-
expect(config[:operation_timeout]).to eq(overrides[:operation_timeout])
|
164
|
-
expect(config[:receive_timeout]).to eq(overrides[:operation_timeout] + 10)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'when invalid data types are given' do
|
170
|
-
let(:overrides) do
|
171
|
-
{
|
172
|
-
user: 'Administrator',
|
173
|
-
password: 'password',
|
174
|
-
endpoint: 'http://localhost:5985/wsman',
|
175
|
-
operation_timeout: 'PT60S'
|
176
|
-
}
|
177
|
-
end
|
178
|
-
describe '#create_with_defaults' do
|
179
|
-
it 'raises an error' do
|
180
|
-
expect { WinRM::ConnectionOpts.create_with_defaults(overrides) }.to raise_error
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'winrm'
|
4
|
-
require 'winrm/shells/cmd'
|
5
|
-
require 'winrm/shells/power_shell'
|
6
|
-
|
7
|
-
describe WinRM::Connection do
|
8
|
-
context 'new' do
|
9
|
-
it 'creates a new winrm session' do
|
10
|
-
connection = WinRM::Connection.new(default_connection_opts)
|
11
|
-
expect(connection).not_to be_nil
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'shell(:cmd)' do
|
16
|
-
it 'creates a new cmd session' do
|
17
|
-
connection = WinRM::Connection.new(default_connection_opts)
|
18
|
-
cmd_shell = connection.shell(:cmd)
|
19
|
-
expect(cmd_shell).not_to be_nil
|
20
|
-
expect(cmd_shell).to be_an_instance_of(WinRM::Shells::Cmd)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'shell(:powershell)' do
|
25
|
-
it 'creates a new powershell session' do
|
26
|
-
connection = WinRM::Connection.new(default_connection_opts)
|
27
|
-
cmd_shell = connection.shell(:powershell)
|
28
|
-
expect(cmd_shell).not_to be_nil
|
29
|
-
expect(cmd_shell).to be_an_instance_of(WinRM::Shells::Powershell)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'shell(:not_a_real_shell_type)' do
|
34
|
-
it 'raises a descriptive error' do
|
35
|
-
connection = WinRM::Connection.new(default_connection_opts)
|
36
|
-
expect { connection.shell(:not_a_real_shell_type) }.to raise_error(WinRM::InvalidShellError)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
describe 'Exceptions' do
|
3
|
-
describe WinRM::WinRMAuthorizationError do
|
4
|
-
let(:error) { WinRM::WinRMHTTPTransportError.new('Foo happened', 500) }
|
5
|
-
|
6
|
-
it 'adds the response code to the message' do
|
7
|
-
expect(error.message).to eq('Foo happened (500).')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'exposes the response code as an attribute' do
|
11
|
-
expect(error.status_code).to eq 500
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'is a winrm error' do
|
15
|
-
expect(error).to be_kind_of(WinRM::WinRMError)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe WinRM::WinRMWSManFault do
|
20
|
-
let(:error) { WinRM::WinRMWSManFault.new('fault text', 42) }
|
21
|
-
|
22
|
-
it 'exposes the fault text as an attribute' do
|
23
|
-
expect(error.fault_description).to eq('fault text')
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'exposes the fault code as an attribute' do
|
27
|
-
expect(error.fault_code).to eq 42
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'is a winrm error' do
|
31
|
-
expect(error).to be_kind_of(WinRM::WinRMError)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe WinRM::WinRMWMIError do
|
36
|
-
let(:error) { WinRM::WinRMWMIError.new('message text', 77_777) }
|
37
|
-
|
38
|
-
it 'exposes the error text as an attribute' do
|
39
|
-
expect(error.error).to eq('message text')
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'exposes the error code as an attribute' do
|
43
|
-
expect(error.error_code).to eq 77_777
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'is a winrm error' do
|
47
|
-
expect(error).to be_kind_of(WinRM::WinRMError)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'winrm/exceptions'
|
3
|
-
require 'winrm/http/transport_factory'
|
4
|
-
|
5
|
-
module WinRM
|
6
|
-
module HTTP
|
7
|
-
# Remove the gssapi stuff in kerberos init for tests
|
8
|
-
class HttpGSSAPI < HttpTransport
|
9
|
-
def initialize(endpoint, realm, opts, service = nil)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe WinRM::HTTP::TransportFactory do
|
16
|
-
describe '#create_transport' do
|
17
|
-
let(:transport) { :negotiate }
|
18
|
-
let(:options) do
|
19
|
-
{
|
20
|
-
transport: transport,
|
21
|
-
endpoint: 'endpoint',
|
22
|
-
user: 'user'
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'creates a negotiate transport' do
|
27
|
-
options[:transport] = :negotiate
|
28
|
-
expect(subject.create_transport(options)).to be_a(WinRM::HTTP::HttpNegotiate)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'creates a plaintext transport' do
|
32
|
-
options[:transport] = :plaintext
|
33
|
-
expect(subject.create_transport(options)).to be_a(WinRM::HTTP::HttpPlaintext)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'creates a basic auth ssl transport' do
|
37
|
-
options[:transport] = :ssl
|
38
|
-
options[:basic_auth_only] = true
|
39
|
-
expect(subject.create_transport(options)).to be_a(WinRM::HTTP::BasicAuthSSL)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'creates a client cert ssl transport' do
|
43
|
-
options[:transport] = :ssl
|
44
|
-
options[:client_cert] = 'cert'
|
45
|
-
expect(subject.create_transport(options)).to be_a(WinRM::HTTP::ClientCertAuthSSL)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'creates a negotiate over ssl transport' do
|
49
|
-
options[:transport] = :ssl
|
50
|
-
expect(subject.create_transport(options)).to be_a(WinRM::HTTP::HttpNegotiate)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'creates a kerberos transport' do
|
54
|
-
options[:transport] = :kerberos
|
55
|
-
expect(subject.create_transport(options)).to be_a(WinRM::HTTP::HttpGSSAPI)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'creates a transport from a stringified transport' do
|
59
|
-
options[:transport] = 'negotiate'
|
60
|
-
expect(subject.create_transport(options)).to be_a(WinRM::HTTP::HttpNegotiate)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'raises when transport type does not exist' do
|
64
|
-
options[:transport] = :fancy
|
65
|
-
expect { subject.create_transport(options) }.to raise_error(WinRM::InvalidTransportError)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'rubyntlm'
|
3
|
-
require 'winrm/http/transport'
|
4
|
-
|
5
|
-
describe WinRM::HTTP::HttpNegotiate do
|
6
|
-
describe '#init' do
|
7
|
-
let(:endpoint) { 'some_endpoint' }
|
8
|
-
let(:domain) { 'some_domain' }
|
9
|
-
let(:user) { 'some_user' }
|
10
|
-
let(:password) { 'some_password' }
|
11
|
-
let(:options) { {} }
|
12
|
-
|
13
|
-
context 'user is not domain prefixed' do
|
14
|
-
it 'does not pass a domain to the NTLM client' do
|
15
|
-
expect(Net::NTLM::Client).to receive(:new).with(user, password, options)
|
16
|
-
WinRM::HTTP::HttpNegotiate.new(endpoint, user, password, options)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'user is domain prefixed' do
|
21
|
-
it 'passes prefixed domain to the NTLM client' do
|
22
|
-
expect(Net::NTLM::Client).to receive(:new) do |passed_user, passed_password, passed_options|
|
23
|
-
expect(passed_user).to eq user
|
24
|
-
expect(passed_password).to eq password
|
25
|
-
expect(passed_options[:domain]).to eq domain
|
26
|
-
end
|
27
|
-
WinRM::HTTP::HttpNegotiate.new(endpoint, "#{domain}\\#{user}", password, options)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'option is passed with a domain' do
|
32
|
-
let(:options) { { domain: domain } }
|
33
|
-
|
34
|
-
it 'passes domain option to the NTLM client' do
|
35
|
-
expect(Net::NTLM::Client).to receive(:new) do |passed_user, passed_password, passed_options|
|
36
|
-
expect(passed_user).to eq user
|
37
|
-
expect(passed_password).to eq password
|
38
|
-
expect(passed_options[:domain]).to eq domain
|
39
|
-
end
|
40
|
-
WinRM::HTTP::HttpNegotiate.new(endpoint, user, password, options)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/tests/spec/output_spec.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
describe WinRM::Output do
|
3
|
-
subject { WinRM::Output.new }
|
4
|
-
|
5
|
-
context 'when there is no output' do
|
6
|
-
describe '#stdout' do
|
7
|
-
it 'is empty' do
|
8
|
-
expect(subject.stdout).to be_empty
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#stderr' do
|
13
|
-
it 'is empty' do
|
14
|
-
expect(subject.stderr).to be_empty
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#output' do
|
19
|
-
it 'is empty' do
|
20
|
-
expect(subject.output).to be_empty
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when there is only one line' do
|
26
|
-
describe '#stdout' do
|
27
|
-
it 'is equal to that line' do
|
28
|
-
subject << { stdout: 'foo' }
|
29
|
-
expect(subject.stdout).to eq('foo')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#stderr' do
|
34
|
-
it 'is equal to that line' do
|
35
|
-
subject << { stderr: 'foo' }
|
36
|
-
expect(subject.stderr).to eq('foo')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#output' do
|
41
|
-
it 'is equal to stdout' do
|
42
|
-
subject << { stdout: 'foo' }
|
43
|
-
expect(subject.output).to eq('foo')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'is equal to stderr' do
|
47
|
-
subject << { stderr: 'foo' }
|
48
|
-
expect(subject.output).to eq('foo')
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when there is one line of each type' do
|
54
|
-
before(:each) do
|
55
|
-
subject << { stdout: 'foo' }
|
56
|
-
subject << { stderr: 'bar' }
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#stdout' do
|
60
|
-
it 'is equal to that line' do
|
61
|
-
expect(subject.stdout).to eq('foo')
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#stderr' do
|
66
|
-
it 'is equal to that line' do
|
67
|
-
expect(subject.stderr).to eq('bar')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#output' do
|
72
|
-
it 'is equal to stdout + stderr' do
|
73
|
-
expect(subject.output).to eq('foobar')
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'when there are multiple lines' do
|
79
|
-
before(:each) do
|
80
|
-
subject << { stdout: 'I can have a newline\nanywhere, ' }
|
81
|
-
subject << { stderr: 'I can also have stderr' }
|
82
|
-
subject << { stdout: 'or stdout', stderr: ' and stderr' }
|
83
|
-
subject << {}
|
84
|
-
subject << { stdout: ' or nothing! (above)' }
|
85
|
-
end
|
86
|
-
|
87
|
-
describe '#stdout' do
|
88
|
-
it 'is equal to that line' do
|
89
|
-
expect(subject.stdout).to eq(
|
90
|
-
'I can have a newline\nanywhere, or stdout or nothing! (above)')
|
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
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe '#exitcode' do
|
110
|
-
let(:exitcode) { 0 }
|
111
|
-
|
112
|
-
context 'when a valid exit code is set' do
|
113
|
-
it 'sets the exit code' do
|
114
|
-
subject.exitcode = exitcode
|
115
|
-
expect(subject.exitcode).to eq exitcode
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'when an invalid exit code is set' do
|
120
|
-
let(:exitcode) { 'bad' }
|
121
|
-
|
122
|
-
it 'sets the exit code' do
|
123
|
-
expect { subject.exitcode = exitcode }.to raise_error WinRM::InvalidExitCode
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'winrm/psrp/fragment'
|
4
|
-
|
5
|
-
describe WinRM::PSRP::Fragment do
|
6
|
-
let(:id) { 1 }
|
7
|
-
let(:message) { 'blah blah blah' }
|
8
|
-
|
9
|
-
context 'called with just id and blob' do
|
10
|
-
subject { described_class.new(id, message.bytes) }
|
11
|
-
|
12
|
-
it 'sets the message id to 1' do
|
13
|
-
expect(subject.bytes[0..7]).to eq([0, 0, 0, 0, 0, 0, 0, id])
|
14
|
-
end
|
15
|
-
it 'sets the fragment id to 0' do
|
16
|
-
expect(subject.bytes[8..15]).to eq([0, 0, 0, 0, 0, 0, 0, 0])
|
17
|
-
end
|
18
|
-
it 'sets the last 2 bits of the end/start fragment' do
|
19
|
-
expect(subject.bytes[16]).to eq(3)
|
20
|
-
end
|
21
|
-
it 'sets message blob length to 3640' do
|
22
|
-
expect(subject.bytes[17..20]).to eq([0, 0, 0, message.bytes.length])
|
23
|
-
end
|
24
|
-
it 'sets message blob' do
|
25
|
-
expect(subject.bytes[21..-1]).to eq(message.bytes)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'specifying a fragment id' do
|
30
|
-
let(:fragment_id) { 1 }
|
31
|
-
|
32
|
-
subject { described_class.new(id, message.bytes, fragment_id) }
|
33
|
-
|
34
|
-
it 'sets the fragment id' do
|
35
|
-
expect(subject.bytes[8..15]).to eq([0, 0, 0, 0, 0, 0, 0, fragment_id])
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'middle fragment' do
|
40
|
-
subject { described_class.new(id, message.bytes, 1, false, false) }
|
41
|
-
|
42
|
-
it 'sets the last 2 bits of the end/start fragment to 0' do
|
43
|
-
expect(subject.bytes[16]).to eq(0)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'end fragment' do
|
48
|
-
subject { described_class.new(id, message.bytes, 1, true, false) }
|
49
|
-
|
50
|
-
it 'sets the end fragment bit' do
|
51
|
-
expect(subject.bytes[16]).to eq(1)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'start fragment' do
|
56
|
-
subject { described_class.new(id, message.bytes, 1, false, true) }
|
57
|
-
|
58
|
-
it 'sets the start fragment bit' do
|
59
|
-
expect(subject.bytes[16]).to eq(2)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'winrm/psrp/message_data/base'
|
4
|
-
|
5
|
-
describe WinRM::PSRP::MessageData::Base do
|
6
|
-
let(:raw_data) { 'raw_data' }
|
7
|
-
|
8
|
-
subject { WinRM::PSRP::MessageData::Base.new(raw_data) }
|
9
|
-
|
10
|
-
it 'holds raw message data' do
|
11
|
-
expect(subject.raw).to eq(raw_data)
|
12
|
-
end
|
13
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'winrm/psrp/message_data/base'
|
4
|
-
require 'winrm/psrp/message_data/error_record'
|
5
|
-
|
6
|
-
describe WinRM::PSRP::MessageData::ErrorRecord do
|
7
|
-
let(:test_data_xml_template) do
|
8
|
-
ERB.new(stubbed_clixml('error_record.xml.erb'))
|
9
|
-
end
|
10
|
-
let(:error_message) { 'an error' }
|
11
|
-
let(:script_root) { 'script_root' }
|
12
|
-
let(:category_message) { 'category message' }
|
13
|
-
let(:stack_trace) { 'stack trace' }
|
14
|
-
let(:error_id) { 'Microsoft.PowerShell.Commands.WriteErrorException' }
|
15
|
-
let(:raw_data) { test_data_xml_template.result(binding) }
|
16
|
-
subject { described_class.new(raw_data) }
|
17
|
-
|
18
|
-
it 'returns the exception' do
|
19
|
-
expect(subject.exception[:message]).to eq(error_message)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns the FullyQualifiedErrorId' do
|
23
|
-
expect(subject.fully_qualified_error_id).to eq(error_id)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'returns the invocation info' do
|
27
|
-
expect(subject.invocation_info[:line]).to eq("write-error '#{error_message}'")
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'converts camel case properties to underscore' do
|
31
|
-
expect(subject.invocation_info[:ps_script_root]).to eq(script_root)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'returns the error category message' do
|
35
|
-
expect(subject.error_category_message).to eq(category_message)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'returns the script stack trace' do
|
39
|
-
expect(subject.error_details_script_stack_trace).to eq(stack_trace)
|
40
|
-
end
|
41
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'winrm/psrp/message_data/base'
|
4
|
-
require 'winrm/psrp/message_data/pipeline_host_call'
|
5
|
-
|
6
|
-
describe WinRM::PSRP::MessageData::PipelineHostCall do
|
7
|
-
let(:raw_data) do
|
8
|
-
"\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I64 N=\"ci\">-100</I64><Obj N=\"mi\" RefId=\"1\">"\
|
9
|
-
'<TN RefId="0"><T>System.Management.Automation.Remoting.RemoteHostMethodId</T>'\
|
10
|
-
'<T>System.Enum</T><T>System.ValueType</T><T>System.Object</T></TN>'\
|
11
|
-
'<ToString>WriteLine3</ToString><I32>17</I32></Obj><Obj N="mp" RefId="2">'\
|
12
|
-
'<TN RefId="1"><T>System.Collections.ArrayList</T><T>System.Object</T></TN><LST>'\
|
13
|
-
'<I32>7</I32><I32>0</I32><S>hello</S></LST></Obj></MS></Obj>'
|
14
|
-
end
|
15
|
-
|
16
|
-
subject { described_class.new(raw_data) }
|
17
|
-
|
18
|
-
it 'parses method identifier' do
|
19
|
-
expect(subject.method_identifier).to eq('WriteLine3')
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'parses method parameters' do
|
23
|
-
expect(subject.method_parameters[:s]).to eq('hello')
|
24
|
-
end
|
25
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'winrm/psrp/message_data/base'
|
4
|
-
require 'winrm/psrp/message_data/pipeline_output'
|
5
|
-
|
6
|
-
describe WinRM::PSRP::MessageData::PipelineOutput do
|
7
|
-
subject { described_class.new(raw_data) }
|
8
|
-
|
9
|
-
context 'receiving output with BOM and no new line' do
|
10
|
-
let(:raw_data) { "\xEF\xBB\xBF<obj><S>some data</S></obj>" }
|
11
|
-
|
12
|
-
it 'output removes BOM and adds newline' do
|
13
|
-
expect(subject.output).to eq("some data\r\n")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'receiving output with encoded new line' do
|
18
|
-
let(:raw_data) { '<obj><S>some data_x000D__x000A_</S></obj>' }
|
19
|
-
|
20
|
-
it 'decodes without double newline' do
|
21
|
-
expect(subject.output).to eq("some data\r\n")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'receiving output with new line in middle' do
|
26
|
-
let(:raw_data) { '<obj><S>some_x000D__x000A_data</S></obj>' }
|
27
|
-
|
28
|
-
it 'decodes and replaces newline' do
|
29
|
-
expect(subject.output).to eq("some\r\ndata\r\n")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|