winrm 1.8.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -11
  3. data/.rubocop.yml +26 -22
  4. data/.travis.yml +11 -12
  5. data/Gemfile +3 -9
  6. data/LICENSE +202 -202
  7. data/README.md +232 -215
  8. data/Rakefile +34 -36
  9. data/Vagrantfile +6 -9
  10. data/WinrmAppveyor.psm1 +31 -31
  11. data/appveyor.yml +51 -51
  12. data/bin/rwinrm +97 -97
  13. data/changelog.md +86 -86
  14. data/lib/winrm.rb +39 -42
  15. data/lib/winrm/connection.rb +82 -0
  16. data/lib/winrm/connection_opts.rb +87 -0
  17. data/lib/winrm/{exceptions/exceptions.rb → exceptions.rb} +76 -57
  18. data/lib/winrm/http/response_handler.rb +96 -82
  19. data/lib/winrm/http/transport.rb +424 -435
  20. data/lib/winrm/http/transport_factory.rb +68 -0
  21. data/lib/winrm/output.rb +59 -43
  22. data/lib/winrm/psrp/create_pipeline.xml.erb +167 -0
  23. data/lib/winrm/psrp/fragment.rb +70 -0
  24. data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -0
  25. data/lib/winrm/psrp/message.rb +130 -0
  26. data/lib/winrm/psrp/message_data.rb +41 -0
  27. data/lib/winrm/psrp/message_data/base.rb +49 -0
  28. data/lib/winrm/psrp/message_data/error_record.rb +68 -0
  29. data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -0
  30. data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -0
  31. data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -0
  32. data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -0
  33. data/lib/winrm/psrp/message_data/session_capability.rb +36 -0
  34. data/lib/winrm/psrp/message_defragmenter.rb +62 -0
  35. data/lib/winrm/psrp/message_factory.rb +75 -0
  36. data/lib/winrm/psrp/message_fragmenter.rb +60 -0
  37. data/lib/winrm/psrp/powershell_output_decoder.rb +120 -0
  38. data/lib/winrm/psrp/receive_response_reader.rb +93 -0
  39. data/lib/winrm/psrp/session_capability.xml.erb +7 -0
  40. data/lib/winrm/psrp/uuid.rb +40 -0
  41. data/lib/winrm/shells/base.rb +175 -0
  42. data/lib/winrm/shells/cmd.rb +65 -0
  43. data/lib/winrm/shells/power_shell.rb +201 -0
  44. data/lib/winrm/shells/retryable.rb +45 -0
  45. data/lib/winrm/shells/shell_factory.rb +50 -0
  46. data/lib/winrm/version.rb +7 -7
  47. data/lib/winrm/wsmv/base.rb +59 -0
  48. data/lib/winrm/wsmv/cleanup_command.rb +61 -0
  49. data/lib/winrm/wsmv/close_shell.rb +50 -0
  50. data/lib/winrm/wsmv/command.rb +101 -0
  51. data/lib/winrm/wsmv/command_output.rb +76 -0
  52. data/lib/winrm/wsmv/command_output_decoder.rb +55 -0
  53. data/lib/winrm/wsmv/configuration.rb +46 -0
  54. data/lib/winrm/wsmv/create_pipeline.rb +66 -0
  55. data/lib/winrm/wsmv/create_shell.rb +119 -0
  56. data/lib/winrm/wsmv/header.rb +203 -0
  57. data/lib/winrm/wsmv/init_runspace_pool.rb +95 -0
  58. data/lib/winrm/wsmv/iso8601_duration.rb +60 -0
  59. data/lib/winrm/wsmv/keep_alive.rb +68 -0
  60. data/lib/winrm/wsmv/receive_response_reader.rb +128 -0
  61. data/lib/winrm/wsmv/send_data.rb +68 -0
  62. data/lib/winrm/wsmv/soap.rb +51 -0
  63. data/lib/winrm/wsmv/wql_query.rb +79 -0
  64. data/lib/winrm/wsmv/write_stdin.rb +88 -0
  65. data/preamble +17 -17
  66. data/{spec → tests/integration}/auth_timeout_spec.rb +18 -16
  67. data/{spec → tests/integration}/cmd_spec.rb +104 -102
  68. data/{spec → tests/integration}/config-example.yml +16 -19
  69. data/{spec → tests/integration}/issue_59_spec.rb +26 -23
  70. data/tests/integration/powershell_spec.rb +154 -0
  71. data/{spec → tests/integration}/spec_helper.rb +65 -73
  72. data/{spec → tests/integration}/transport_spec.rb +99 -139
  73. data/{spec → tests/integration}/wql_spec.rb +16 -14
  74. data/{spec → tests}/matchers.rb +60 -74
  75. data/tests/spec/configuration_spec.rb +93 -0
  76. data/tests/spec/connection_spec.rb +39 -0
  77. data/{spec → tests/spec}/exception_spec.rb +50 -50
  78. data/tests/spec/http/transport_factory_spec.rb +68 -0
  79. data/tests/spec/http/transport_spec.rb +44 -0
  80. data/{spec → tests/spec}/output_spec.rb +127 -110
  81. data/tests/spec/psrp/fragment_spec.rb +62 -0
  82. data/tests/spec/psrp/message_data/base_spec.rb +13 -0
  83. data/tests/spec/psrp/message_data/error_record_spec.rb +41 -0
  84. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -0
  85. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -0
  86. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -0
  87. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -0
  88. data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -0
  89. data/tests/spec/psrp/message_data_spec.rb +35 -0
  90. data/tests/spec/psrp/message_defragmenter_spec.rb +47 -0
  91. data/tests/spec/psrp/message_fragmenter_spec.rb +105 -0
  92. data/tests/spec/psrp/powershell_output_decoder_spec.rb +84 -0
  93. data/tests/spec/psrp/psrp_message_spec.rb +70 -0
  94. data/tests/spec/psrp/recieve_response_reader_spec.rb +154 -0
  95. data/tests/spec/psrp/uuid_spec.rb +28 -0
  96. data/{spec → tests/spec}/response_handler_spec.rb +61 -61
  97. data/tests/spec/shells/base_spec.rb +202 -0
  98. data/tests/spec/shells/cmd_spec.rb +75 -0
  99. data/tests/spec/shells/powershell_spec.rb +175 -0
  100. data/tests/spec/spec_helper.rb +47 -0
  101. data/tests/spec/stubs/clixml/error_record.xml.erb +84 -0
  102. data/{spec → 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 -0
  104. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -0
  105. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -0
  106. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -0
  107. data/{spec → tests/spec}/stubs/responses/open_shell_v1.xml +19 -19
  108. data/{spec → tests/spec}/stubs/responses/open_shell_v2.xml +20 -20
  109. data/{spec → tests/spec}/stubs/responses/soap_fault_v1.xml +36 -36
  110. data/{spec → tests/spec}/stubs/responses/soap_fault_v2.xml +42 -42
  111. data/{spec → tests/spec}/stubs/responses/wmi_error_v2.xml +41 -41
  112. data/tests/spec/wsmv/cleanup_command_spec.rb +22 -0
  113. data/tests/spec/wsmv/close_shell_spec.rb +17 -0
  114. data/{spec → tests/spec/wsmv}/command_output_decoder_spec.rb +37 -37
  115. data/tests/spec/wsmv/command_output_spec.rb +45 -0
  116. data/tests/spec/wsmv/command_spec.rb +19 -0
  117. data/tests/spec/wsmv/configuration_spec.rb +17 -0
  118. data/tests/spec/wsmv/create_pipeline_spec.rb +31 -0
  119. data/tests/spec/wsmv/create_shell_spec.rb +38 -0
  120. data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -0
  121. data/tests/spec/wsmv/keep_alive_spec.rb +21 -0
  122. data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -0
  123. data/tests/spec/wsmv/send_data_spec.rb +30 -0
  124. data/tests/spec/wsmv/wql_query_spec.rb +13 -0
  125. data/tests/spec/wsmv/write_stdin_spec.rb +22 -0
  126. data/winrm.gemspec +42 -40
  127. metadata +140 -38
  128. data/.rspec +0 -3
  129. data/lib/winrm/command_executor.rb +0 -243
  130. data/lib/winrm/command_output_decoder.rb +0 -53
  131. data/lib/winrm/helpers/iso8601_duration.rb +0 -58
  132. data/lib/winrm/helpers/powershell_script.rb +0 -42
  133. data/lib/winrm/soap_provider.rb +0 -39
  134. data/lib/winrm/winrm_service.rb +0 -550
  135. data/spec/command_executor_spec.rb +0 -475
  136. data/spec/issue_184_spec.rb +0 -67
  137. data/spec/powershell_spec.rb +0 -97
  138. data/spec/winrm_options_spec.rb +0 -76
  139. data/spec/winrm_primitives_spec.rb +0 -51
@@ -1,14 +1,16 @@
1
- # encoding: UTF-8
2
- describe 'winrm client wql', integration: true do
3
- before(:all) do
4
- @winrm = winrm_connection
5
- end
6
-
7
- it 'should query Win32_OperatingSystem' do
8
- output = @winrm.run_wql('select * from Win32_OperatingSystem')
9
- expect(output).to_not be_empty
10
- output_caption = output[:win32_operating_system][0][:caption]
11
- expect(output_caption).to include('Microsoft')
12
- expect(output_caption).to include('Windows')
13
- end
14
- end
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
@@ -1,74 +1,60 @@
1
- # encoding: UTF-8
2
- require 'rspec/expectations'
3
-
4
- # rspec matchers
5
- module WinRMSpecs
6
- def self.stdout(output)
7
- output[:data].collect do |i|
8
- i[:stdout]
9
- end.join('\r\n').gsub(/(\\r\\n)+$/, '')
10
- end
11
-
12
- def self.stderr(output)
13
- output[:data].collect do |i|
14
- i[:stderr]
15
- end.join('\r\n').gsub(/(\\r\\n)+$/, '')
16
- end
17
- end
18
-
19
- RSpec::Matchers.define :have_stdout_match do |expected_stdout|
20
- match do |actual_output|
21
- !expected_stdout.match(WinRMSpecs.stdout(actual_output)).nil?
22
- end
23
- failure_message do |actual_output|
24
- "expected that '#{WinRMSpecs.stdout(actual_output)}' would match #{expected_stdout}"
25
- end
26
- end
27
-
28
- RSpec::Matchers.define :have_stderr_match do |expected_stderr|
29
- match do |actual_output|
30
- !expected_stderr.match(WinRMSpecs.stderr(actual_output)).nil?
31
- end
32
- failure_message do |actual_output|
33
- "expected that '#{WinRMSpecs.stderr(actual_output)}' would match #{expected_stderr}"
34
- end
35
- end
36
-
37
- RSpec::Matchers.define :have_no_stdout do
38
- match do |actual_output|
39
- stdout = WinRMSpecs.stdout(actual_output)
40
- stdout == '\r\n' || stdout == ''
41
- end
42
- failure_message do |actual_output|
43
- "expected that '#{WinRMSpecs.stdout(actual_output)}' would have no stdout"
44
- end
45
- end
46
-
47
- RSpec::Matchers.define :have_no_stderr do
48
- match do |actual_output|
49
- stderr = WinRMSpecs.stderr(actual_output)
50
- stderr == '\r\n' || stderr == ''
51
- end
52
- failure_message do |actual_output|
53
- "expected that '#{WinRMSpecs.stderr(actual_output)}' would have no stderr"
54
- end
55
- end
56
-
57
- RSpec::Matchers.define :have_exit_code do |expected_exit_code|
58
- match do |actual_output|
59
- expected_exit_code == actual_output[:exitcode]
60
- end
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', unit: true 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
+ # 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