winrm 1.8.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +10 -11
- data/.rubocop.yml +26 -22
- data/.travis.yml +11 -12
- data/Gemfile +3 -9
- data/LICENSE +202 -202
- data/README.md +232 -215
- data/Rakefile +34 -36
- data/Vagrantfile +6 -9
- data/WinrmAppveyor.psm1 +31 -31
- data/appveyor.yml +51 -51
- data/bin/rwinrm +97 -97
- data/changelog.md +86 -86
- data/lib/winrm.rb +39 -42
- data/lib/winrm/connection.rb +82 -0
- data/lib/winrm/connection_opts.rb +87 -0
- data/lib/winrm/{exceptions/exceptions.rb → exceptions.rb} +76 -57
- data/lib/winrm/http/response_handler.rb +96 -82
- data/lib/winrm/http/transport.rb +424 -435
- data/lib/winrm/http/transport_factory.rb +68 -0
- data/lib/winrm/output.rb +59 -43
- data/lib/winrm/psrp/create_pipeline.xml.erb +167 -0
- data/lib/winrm/psrp/fragment.rb +70 -0
- data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -0
- data/lib/winrm/psrp/message.rb +130 -0
- data/lib/winrm/psrp/message_data.rb +41 -0
- data/lib/winrm/psrp/message_data/base.rb +49 -0
- data/lib/winrm/psrp/message_data/error_record.rb +68 -0
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -0
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -0
- data/lib/winrm/psrp/message_data/session_capability.rb +36 -0
- data/lib/winrm/psrp/message_defragmenter.rb +62 -0
- data/lib/winrm/psrp/message_factory.rb +75 -0
- data/lib/winrm/psrp/message_fragmenter.rb +60 -0
- data/lib/winrm/psrp/powershell_output_decoder.rb +120 -0
- data/lib/winrm/psrp/receive_response_reader.rb +93 -0
- data/lib/winrm/psrp/session_capability.xml.erb +7 -0
- data/lib/winrm/psrp/uuid.rb +40 -0
- data/lib/winrm/shells/base.rb +175 -0
- data/lib/winrm/shells/cmd.rb +65 -0
- data/lib/winrm/shells/power_shell.rb +201 -0
- data/lib/winrm/shells/retryable.rb +45 -0
- data/lib/winrm/shells/shell_factory.rb +50 -0
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/wsmv/base.rb +59 -0
- data/lib/winrm/wsmv/cleanup_command.rb +61 -0
- data/lib/winrm/wsmv/close_shell.rb +50 -0
- data/lib/winrm/wsmv/command.rb +101 -0
- data/lib/winrm/wsmv/command_output.rb +76 -0
- data/lib/winrm/wsmv/command_output_decoder.rb +55 -0
- data/lib/winrm/wsmv/configuration.rb +46 -0
- data/lib/winrm/wsmv/create_pipeline.rb +66 -0
- data/lib/winrm/wsmv/create_shell.rb +119 -0
- data/lib/winrm/wsmv/header.rb +203 -0
- data/lib/winrm/wsmv/init_runspace_pool.rb +95 -0
- data/lib/winrm/wsmv/iso8601_duration.rb +60 -0
- data/lib/winrm/wsmv/keep_alive.rb +68 -0
- data/lib/winrm/wsmv/receive_response_reader.rb +128 -0
- data/lib/winrm/wsmv/send_data.rb +68 -0
- data/lib/winrm/wsmv/soap.rb +51 -0
- data/lib/winrm/wsmv/wql_query.rb +79 -0
- data/lib/winrm/wsmv/write_stdin.rb +88 -0
- data/preamble +17 -17
- data/{spec → tests/integration}/auth_timeout_spec.rb +18 -16
- data/{spec → tests/integration}/cmd_spec.rb +104 -102
- data/{spec → tests/integration}/config-example.yml +16 -19
- data/{spec → tests/integration}/issue_59_spec.rb +26 -23
- data/tests/integration/powershell_spec.rb +154 -0
- data/{spec → tests/integration}/spec_helper.rb +65 -73
- data/{spec → tests/integration}/transport_spec.rb +99 -139
- data/{spec → tests/integration}/wql_spec.rb +16 -14
- data/{spec → tests}/matchers.rb +60 -74
- data/tests/spec/configuration_spec.rb +93 -0
- data/tests/spec/connection_spec.rb +39 -0
- data/{spec → tests/spec}/exception_spec.rb +50 -50
- data/tests/spec/http/transport_factory_spec.rb +68 -0
- data/tests/spec/http/transport_spec.rb +44 -0
- data/{spec → tests/spec}/output_spec.rb +127 -110
- data/tests/spec/psrp/fragment_spec.rb +62 -0
- data/tests/spec/psrp/message_data/base_spec.rb +13 -0
- data/tests/spec/psrp/message_data/error_record_spec.rb +41 -0
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -0
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -0
- data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -0
- data/tests/spec/psrp/message_data_spec.rb +35 -0
- data/tests/spec/psrp/message_defragmenter_spec.rb +47 -0
- data/tests/spec/psrp/message_fragmenter_spec.rb +105 -0
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +84 -0
- data/tests/spec/psrp/psrp_message_spec.rb +70 -0
- data/tests/spec/psrp/recieve_response_reader_spec.rb +154 -0
- data/tests/spec/psrp/uuid_spec.rb +28 -0
- data/{spec → tests/spec}/response_handler_spec.rb +61 -61
- data/tests/spec/shells/base_spec.rb +202 -0
- data/tests/spec/shells/cmd_spec.rb +75 -0
- data/tests/spec/shells/powershell_spec.rb +175 -0
- data/tests/spec/spec_helper.rb +47 -0
- data/tests/spec/stubs/clixml/error_record.xml.erb +84 -0
- data/{spec → tests/spec}/stubs/responses/get_command_output_response.xml.erb +13 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -0
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -0
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -0
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -0
- data/{spec → tests/spec}/stubs/responses/open_shell_v1.xml +19 -19
- data/{spec → tests/spec}/stubs/responses/open_shell_v2.xml +20 -20
- data/{spec → tests/spec}/stubs/responses/soap_fault_v1.xml +36 -36
- data/{spec → tests/spec}/stubs/responses/soap_fault_v2.xml +42 -42
- data/{spec → tests/spec}/stubs/responses/wmi_error_v2.xml +41 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +22 -0
- data/tests/spec/wsmv/close_shell_spec.rb +17 -0
- data/{spec → tests/spec/wsmv}/command_output_decoder_spec.rb +37 -37
- data/tests/spec/wsmv/command_output_spec.rb +45 -0
- data/tests/spec/wsmv/command_spec.rb +19 -0
- data/tests/spec/wsmv/configuration_spec.rb +17 -0
- data/tests/spec/wsmv/create_pipeline_spec.rb +31 -0
- data/tests/spec/wsmv/create_shell_spec.rb +38 -0
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -0
- data/tests/spec/wsmv/keep_alive_spec.rb +21 -0
- data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -0
- data/tests/spec/wsmv/send_data_spec.rb +30 -0
- data/tests/spec/wsmv/wql_query_spec.rb +13 -0
- data/tests/spec/wsmv/write_stdin_spec.rb +22 -0
- data/winrm.gemspec +42 -40
- metadata +140 -38
- data/.rspec +0 -3
- data/lib/winrm/command_executor.rb +0 -243
- data/lib/winrm/command_output_decoder.rb +0 -53
- data/lib/winrm/helpers/iso8601_duration.rb +0 -58
- data/lib/winrm/helpers/powershell_script.rb +0 -42
- data/lib/winrm/soap_provider.rb +0 -39
- data/lib/winrm/winrm_service.rb +0 -550
- data/spec/command_executor_spec.rb +0 -475
- data/spec/issue_184_spec.rb +0 -67
- data/spec/powershell_spec.rb +0 -97
- data/spec/winrm_options_spec.rb +0 -76
- data/spec/winrm_primitives_spec.rb +0 -51
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
expect(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require_relative 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe 'winrm client wql' do
|
|
5
|
+
before(:all) do
|
|
6
|
+
@winrm = winrm_connection
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'should query Win32_OperatingSystem' do
|
|
10
|
+
output = @winrm.run_wql('select * from Win32_OperatingSystem')
|
|
11
|
+
expect(output).to_not be_empty
|
|
12
|
+
output_caption = output[:win32_operating_system][0][:caption]
|
|
13
|
+
expect(output_caption).to include('Microsoft')
|
|
14
|
+
expect(output_caption).to include('Windows')
|
|
15
|
+
end
|
|
16
|
+
end
|
data/{spec → tests}/matchers.rb
RENAMED
|
@@ -1,74 +1,60 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require 'rspec/expectations'
|
|
3
|
-
|
|
4
|
-
# rspec matchers
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
failure_message do |actual_output|
|
|
62
|
-
"expected exit code #{expected_exit_code}, but got #{actual_output[:exitcode]}"
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
RSpec::Matchers.define :be_a_uid do
|
|
67
|
-
match do |actual|
|
|
68
|
-
# WinRM1.1 returns uuid's prefixed with 'uuid:' where as later versions do not
|
|
69
|
-
actual && actual.to_s.match(/^(uuid:)*\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/)
|
|
70
|
-
end
|
|
71
|
-
failure_message do |actual|
|
|
72
|
-
"expected a uid, but got '#{actual}'"
|
|
73
|
-
end
|
|
74
|
-
end
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'rspec/expectations'
|
|
3
|
+
|
|
4
|
+
# rspec matchers
|
|
5
|
+
RSpec::Matchers.define :have_stdout_match do |expected_stdout|
|
|
6
|
+
match do |actual_output|
|
|
7
|
+
!expected_stdout.match(actual_output.stdout).nil?
|
|
8
|
+
end
|
|
9
|
+
failure_message do |actual_output|
|
|
10
|
+
"expected that '#{actual_output.stdout}' would match #{expected_stdout}"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
RSpec::Matchers.define :have_stderr_match do |expected_stderr|
|
|
15
|
+
match do |actual_output|
|
|
16
|
+
!expected_stderr.match(actual_output.stderr).nil?
|
|
17
|
+
end
|
|
18
|
+
failure_message do |actual_output|
|
|
19
|
+
"expected that '#{actual_output.stderr}' would match #{expected_stderr}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
RSpec::Matchers.define :have_no_stdout do
|
|
24
|
+
match do |actual_output|
|
|
25
|
+
stdout = actual_output.stdout
|
|
26
|
+
stdout == '\r\n' || stdout == ''
|
|
27
|
+
end
|
|
28
|
+
failure_message do |actual_output|
|
|
29
|
+
"expected that '#{actual_output.stdout}' would have no stdout"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
RSpec::Matchers.define :have_no_stderr do
|
|
34
|
+
match do |actual_output|
|
|
35
|
+
stderr = actual_output.stderr
|
|
36
|
+
stderr == '\r\n' || stderr == ''
|
|
37
|
+
end
|
|
38
|
+
failure_message do |actual_output|
|
|
39
|
+
"expected that '#{actual_output.stderr}' would have no stderr"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
RSpec::Matchers.define :have_exit_code do |expected_exit_code|
|
|
44
|
+
match do |actual_output|
|
|
45
|
+
expected_exit_code == actual_output.exitcode
|
|
46
|
+
end
|
|
47
|
+
failure_message do |actual_output|
|
|
48
|
+
"expected exit code #{expected_exit_code}, but got #{actual_output.exitcode}"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
RSpec::Matchers.define :be_a_uid do
|
|
53
|
+
match do |actual|
|
|
54
|
+
# WinRM1.1 returns uuid's prefixed with 'uuid:' where as later versions do not
|
|
55
|
+
actual && actual.to_s.match(/^(uuid:)*\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/)
|
|
56
|
+
end
|
|
57
|
+
failure_message do |actual|
|
|
58
|
+
"expected a uid, but got '#{actual}'"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'winrm/connection_opts'
|
|
3
|
+
|
|
4
|
+
describe WinRM::ConnectionOpts do
|
|
5
|
+
context 'when there are no overrides' do
|
|
6
|
+
describe '#create_with_defaults' do
|
|
7
|
+
it 'throws a validation error' do
|
|
8
|
+
expect { WinRM::ConnectionOpts.create_with_defaults({}) }.to raise_error
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
context 'when username, password, and endpoint are given' do
|
|
13
|
+
let(:overrides) do
|
|
14
|
+
{
|
|
15
|
+
user: 'Administrator',
|
|
16
|
+
password: 'password',
|
|
17
|
+
endpoint: 'http://localhost:5985/wsman'
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
describe '#create_with_defaults' do
|
|
21
|
+
it 'creates a ConnectionOpts object' do
|
|
22
|
+
config = WinRM::ConnectionOpts.create_with_defaults(overrides)
|
|
23
|
+
expect(config[:user]).to eq(overrides[:user])
|
|
24
|
+
expect(config[:password]).to eq(overrides[:password])
|
|
25
|
+
expect(config[:endpoint]).to eq(overrides[:endpoint])
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
context 'when overrides are provided' do
|
|
30
|
+
let(:overrides) do
|
|
31
|
+
{
|
|
32
|
+
user: 'Administrator',
|
|
33
|
+
password: 'password',
|
|
34
|
+
endpoint: 'http://localhost:5985/wsman',
|
|
35
|
+
transport: :ssl
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
describe '#create_with_defaults' do
|
|
39
|
+
it 'creates a ConnectionOpts object with overrides' do
|
|
40
|
+
config = WinRM::ConnectionOpts.create_with_defaults(overrides)
|
|
41
|
+
expect(config[:transport]).to eq(overrides[:transport])
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
context 'when receive_timeout is specified' do
|
|
46
|
+
let(:overrides) do
|
|
47
|
+
{
|
|
48
|
+
user: 'Administrator',
|
|
49
|
+
password: 'password',
|
|
50
|
+
endpoint: 'http://localhost:5985/wsman',
|
|
51
|
+
receive_timeout: 120
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
describe '#create_with_defaults' do
|
|
55
|
+
it 'creates a ConnectionOpts object with the correct receive_timeout' do
|
|
56
|
+
config = WinRM::ConnectionOpts.create_with_defaults(overrides)
|
|
57
|
+
expect(config[:receive_timeout]).to eq(overrides[:receive_timeout])
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
context 'when operation_timeout is specified' do
|
|
62
|
+
let(:overrides) do
|
|
63
|
+
{
|
|
64
|
+
user: 'Administrator',
|
|
65
|
+
password: 'password',
|
|
66
|
+
endpoint: 'http://localhost:5985/wsman',
|
|
67
|
+
operation_timeout: 120
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
describe '#create_with_defaults' do
|
|
71
|
+
it 'creates a ConnectionOpts object with the correct timeouts' do
|
|
72
|
+
config = WinRM::ConnectionOpts.create_with_defaults(overrides)
|
|
73
|
+
expect(config[:operation_timeout]).to eq(overrides[:operation_timeout])
|
|
74
|
+
expect(config[:receive_timeout]).to eq(overrides[:operation_timeout] + 10)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
context 'when invalid data types are given' do
|
|
79
|
+
let(:overrides) do
|
|
80
|
+
{
|
|
81
|
+
user: 'Administrator',
|
|
82
|
+
password: 'password',
|
|
83
|
+
endpoint: 'http://localhost:5985/wsman',
|
|
84
|
+
operation_timeout: 'PT60S'
|
|
85
|
+
}
|
|
86
|
+
end
|
|
87
|
+
describe '#create_with_defaults' do
|
|
88
|
+
it 'raises an error' do
|
|
89
|
+
expect { WinRM::ConnectionOpts.create_with_defaults(overrides) }.to raise_error
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
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 +1,50 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
describe 'Exceptions'
|
|
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
|
+
# 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
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|