winrm 1.7.1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -10
  3. data/.rspec +3 -3
  4. data/.rubocop.yml +12 -12
  5. data/.travis.yml +12 -12
  6. data/Gemfile +9 -9
  7. data/LICENSE +202 -202
  8. data/README.md +194 -194
  9. data/Rakefile +36 -36
  10. data/Vagrantfile +9 -9
  11. data/appveyor.yml +42 -42
  12. data/bin/rwinrm +97 -97
  13. data/changelog.md +77 -74
  14. data/lib/winrm.rb +42 -42
  15. data/lib/winrm/command_executor.rb +224 -224
  16. data/lib/winrm/command_output_decoder.rb +53 -0
  17. data/lib/winrm/exceptions/exceptions.rb +57 -57
  18. data/lib/winrm/helpers/iso8601_duration.rb +58 -58
  19. data/lib/winrm/helpers/powershell_script.rb +42 -42
  20. data/lib/winrm/http/response_handler.rb +82 -82
  21. data/lib/winrm/http/transport.rb +421 -421
  22. data/lib/winrm/output.rb +43 -43
  23. data/lib/winrm/soap_provider.rb +39 -39
  24. data/lib/winrm/version.rb +7 -7
  25. data/lib/winrm/winrm_service.rb +547 -556
  26. data/preamble +17 -17
  27. data/spec/auth_timeout_spec.rb +16 -16
  28. data/spec/cmd_spec.rb +102 -102
  29. data/spec/command_executor_spec.rb +429 -429
  30. data/spec/command_output_decoder_spec.rb +37 -0
  31. data/spec/config-example.yml +19 -19
  32. data/spec/exception_spec.rb +50 -50
  33. data/spec/issue_184_spec.rb +67 -67
  34. data/spec/issue_59_spec.rb +23 -23
  35. data/spec/matchers.rb +74 -74
  36. data/spec/output_spec.rb +110 -110
  37. data/spec/powershell_spec.rb +97 -97
  38. data/spec/response_handler_spec.rb +59 -59
  39. data/spec/spec_helper.rb +73 -73
  40. data/spec/stubs/responses/get_command_output_response.xml.erb +13 -13
  41. data/spec/stubs/responses/open_shell_v1.xml +19 -19
  42. data/spec/stubs/responses/open_shell_v2.xml +20 -20
  43. data/spec/stubs/responses/soap_fault_v1.xml +36 -36
  44. data/spec/stubs/responses/soap_fault_v2.xml +42 -42
  45. data/spec/stubs/responses/wmi_error_v2.xml +41 -41
  46. data/spec/transport_spec.rb +124 -124
  47. data/spec/winrm_options_spec.rb +76 -76
  48. data/spec/winrm_primitives_spec.rb +51 -51
  49. data/spec/wql_spec.rb +14 -14
  50. data/winrm.gemspec +40 -40
  51. metadata +5 -3
@@ -1,124 +1,124 @@
1
- # encoding: UTF-8
2
- require 'rubyntlm'
3
- require 'winrm/http/transport'
4
-
5
- describe WinRM::HTTP::HttpNegotiate, unit: true 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
45
-
46
- describe 'WinRM connection', integration: true do
47
- let(:winrm_connection) do
48
- endpoint = config[:endpoint].dup
49
- if auth_type == :ssl
50
- endpoint.sub!('5985', '5986')
51
- endpoint.sub!('http', 'https')
52
- end
53
- winrm = WinRM::WinRMWebService.new(
54
- endpoint, auth_type, options)
55
- winrm.logger.level = :error
56
- winrm
57
- end
58
- let(:options) do
59
- opts = {}
60
- opts[:user] = config[:options][:user]
61
- opts[:pass] = config[:options][:pass]
62
- opts[:basic_auth_only] = basic_auth_only
63
- opts[:no_ssl_peer_verification] = no_ssl_peer_verification
64
- opts[:ssl_peer_fingerprint] = ssl_peer_fingerprint
65
- opts
66
- end
67
- let(:basic_auth_only) { false }
68
- let(:no_ssl_peer_verification) { false }
69
- let(:ssl_peer_fingerprint) { nil }
70
-
71
- subject(:output) do
72
- executor = winrm_connection.create_executor
73
- executor.run_cmd('ipconfig')
74
- end
75
-
76
- shared_examples 'a valid_connection' do
77
- it 'has a 0 exit code' do
78
- expect(subject).to have_exit_code 0
79
- end
80
-
81
- it 'includes command output' do
82
- expect(subject).to have_stdout_match(/Windows IP Configuration/)
83
- end
84
-
85
- it 'has no errors' do
86
- expect(subject).to have_no_stderr
87
- end
88
- end
89
-
90
- context 'HttpPlaintext' do
91
- let(:basic_auth_only) { true }
92
- let(:auth_type) { :plaintext }
93
-
94
- it_behaves_like 'a valid_connection'
95
- end
96
-
97
- context 'HttpNegotiate' do
98
- let(:auth_type) { :negotiate }
99
-
100
- it_behaves_like 'a valid_connection'
101
- end
102
-
103
- context 'BasicAuthSSL', skip: ENV['winrm_cert'].nil? do
104
- let(:basic_auth_only) { true }
105
- let(:auth_type) { :ssl }
106
- let(:no_ssl_peer_verification) { true }
107
-
108
- it_behaves_like 'a valid_connection'
109
- end
110
-
111
- context 'Negotiate over SSL', skip: ENV['winrm_cert'].nil? do
112
- let(:auth_type) { :ssl }
113
- let(:no_ssl_peer_verification) { true }
114
-
115
- it_behaves_like 'a valid_connection'
116
- end
117
-
118
- context 'SSL fingerprint', skip: ENV['winrm_cert'].nil? do
119
- let(:auth_type) { :ssl }
120
- let(:ssl_peer_fingerprint) { ENV['winrm_cert'] }
121
-
122
- it_behaves_like 'a valid_connection'
123
- end
124
- end
1
+ # encoding: UTF-8
2
+ require 'rubyntlm'
3
+ require 'winrm/http/transport'
4
+
5
+ describe WinRM::HTTP::HttpNegotiate, unit: true 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
45
+
46
+ describe 'WinRM connection', integration: true do
47
+ let(:winrm_connection) do
48
+ endpoint = config[:endpoint].dup
49
+ if auth_type == :ssl
50
+ endpoint.sub!('5985', '5986')
51
+ endpoint.sub!('http', 'https')
52
+ end
53
+ winrm = WinRM::WinRMWebService.new(
54
+ endpoint, auth_type, options)
55
+ winrm.logger.level = :error
56
+ winrm
57
+ end
58
+ let(:options) do
59
+ opts = {}
60
+ opts[:user] = config[:options][:user]
61
+ opts[:pass] = config[:options][:pass]
62
+ opts[:basic_auth_only] = basic_auth_only
63
+ opts[:no_ssl_peer_verification] = no_ssl_peer_verification
64
+ opts[:ssl_peer_fingerprint] = ssl_peer_fingerprint
65
+ opts
66
+ end
67
+ let(:basic_auth_only) { false }
68
+ let(:no_ssl_peer_verification) { false }
69
+ let(:ssl_peer_fingerprint) { nil }
70
+
71
+ subject(:output) do
72
+ executor = winrm_connection.create_executor
73
+ executor.run_cmd('ipconfig')
74
+ end
75
+
76
+ shared_examples 'a valid_connection' do
77
+ it 'has a 0 exit code' do
78
+ expect(subject).to have_exit_code 0
79
+ end
80
+
81
+ it 'includes command output' do
82
+ expect(subject).to have_stdout_match(/Windows IP Configuration/)
83
+ end
84
+
85
+ it 'has no errors' do
86
+ expect(subject).to have_no_stderr
87
+ end
88
+ end
89
+
90
+ context 'HttpPlaintext' do
91
+ let(:basic_auth_only) { true }
92
+ let(:auth_type) { :plaintext }
93
+
94
+ it_behaves_like 'a valid_connection'
95
+ end
96
+
97
+ context 'HttpNegotiate' do
98
+ let(:auth_type) { :negotiate }
99
+
100
+ it_behaves_like 'a valid_connection'
101
+ end
102
+
103
+ context 'BasicAuthSSL', skip: ENV['winrm_cert'].nil? do
104
+ let(:basic_auth_only) { true }
105
+ let(:auth_type) { :ssl }
106
+ let(:no_ssl_peer_verification) { true }
107
+
108
+ it_behaves_like 'a valid_connection'
109
+ end
110
+
111
+ context 'Negotiate over SSL', skip: ENV['winrm_cert'].nil? do
112
+ let(:auth_type) { :ssl }
113
+ let(:no_ssl_peer_verification) { true }
114
+
115
+ it_behaves_like 'a valid_connection'
116
+ end
117
+
118
+ context 'SSL fingerprint', skip: ENV['winrm_cert'].nil? do
119
+ let(:auth_type) { :ssl }
120
+ let(:ssl_peer_fingerprint) { ENV['winrm_cert'] }
121
+
122
+ it_behaves_like 'a valid_connection'
123
+ end
124
+ end
@@ -1,76 +1,76 @@
1
- # encoding: UTF-8
2
- describe 'WinRM options', unit: true do
3
- let(:subject) { WinRM::WinRMWebService.new('http://localhost:55985/wsman', :plaintext) }
4
-
5
- context 'when operations timeout is set to 60' do
6
- before(:each) { subject.set_timeout(60) }
7
- describe '#receive_timeout' do
8
- it 'is set to 70s' do
9
- transportclass = subject.instance_variable_get(:@xfer)
10
- expect(transportclass.receive_timeout).to eql(70)
11
- end
12
- end
13
- describe '#op_timeout' do
14
- it 'is set to 60s' do
15
- expect(subject.timeout).to eql('PT60S')
16
- end
17
- end
18
- end
19
-
20
- context 'when operations timeout is set to 30 and receive timeout is set to 120' do
21
- before(:each) { subject.set_timeout(30, 120) }
22
- describe '#receive_timeout' do
23
- it 'is set to 120s' do
24
- transportclass = subject.instance_variable_get(:@xfer)
25
- expect(transportclass.receive_timeout).to eql(120)
26
- end
27
- end
28
- describe '#op_timeout' do
29
- it 'is set to 30s' do
30
- expect(subject.timeout).to eql('PT30S')
31
- end
32
- end
33
- end
34
-
35
- context 'when max_env_size is set to 614400' do
36
- before(:each) { subject.max_env_size(614_400) }
37
- describe '@max_env_sz' do
38
- it 'is set to 614400' do
39
- expect(subject.instance_variable_get('@max_env_sz')).to eq(614_400)
40
- end
41
- end
42
- end
43
-
44
- context 'when locale is set to en-CA' do
45
- before(:each) { subject.locale('en-CA') }
46
- describe '@locale' do
47
- it 'is set to en-CA' do
48
- expect(subject.instance_variable_get('@locale')).to eq('en-CA')
49
- end
50
- end
51
- end
52
-
53
- context 'default' do
54
- describe '#receive_timeout' do
55
- it 'should be 3600ms' do
56
- transportclass = subject.instance_variable_get(:@xfer)
57
- expect(transportclass.receive_timeout).to eql(3600)
58
- end
59
- end
60
- describe '#timeout' do
61
- it 'should be 60s' do
62
- expect(subject.timeout).to eql('PT60S')
63
- end
64
- end
65
- describe '@locale' do
66
- it 'should be en-US' do
67
- expect(subject.instance_variable_get('@locale')).to eq('en-US')
68
- end
69
- end
70
- describe '@max_env_sz' do
71
- it 'should be 153600' do
72
- expect(subject.instance_variable_get('@max_env_sz')).to eq(153_600)
73
- end
74
- end
75
- end
76
- end
1
+ # encoding: UTF-8
2
+ describe 'WinRM options', unit: true do
3
+ let(:subject) { WinRM::WinRMWebService.new('http://localhost:55985/wsman', :plaintext) }
4
+
5
+ context 'when operations timeout is set to 60' do
6
+ before(:each) { subject.set_timeout(60) }
7
+ describe '#receive_timeout' do
8
+ it 'is set to 70s' do
9
+ transportclass = subject.instance_variable_get(:@xfer)
10
+ expect(transportclass.receive_timeout).to eql(70)
11
+ end
12
+ end
13
+ describe '#op_timeout' do
14
+ it 'is set to 60s' do
15
+ expect(subject.timeout).to eql('PT60S')
16
+ end
17
+ end
18
+ end
19
+
20
+ context 'when operations timeout is set to 30 and receive timeout is set to 120' do
21
+ before(:each) { subject.set_timeout(30, 120) }
22
+ describe '#receive_timeout' do
23
+ it 'is set to 120s' do
24
+ transportclass = subject.instance_variable_get(:@xfer)
25
+ expect(transportclass.receive_timeout).to eql(120)
26
+ end
27
+ end
28
+ describe '#op_timeout' do
29
+ it 'is set to 30s' do
30
+ expect(subject.timeout).to eql('PT30S')
31
+ end
32
+ end
33
+ end
34
+
35
+ context 'when max_env_size is set to 614400' do
36
+ before(:each) { subject.max_env_size(614_400) }
37
+ describe '@max_env_sz' do
38
+ it 'is set to 614400' do
39
+ expect(subject.instance_variable_get('@max_env_sz')).to eq(614_400)
40
+ end
41
+ end
42
+ end
43
+
44
+ context 'when locale is set to en-CA' do
45
+ before(:each) { subject.locale('en-CA') }
46
+ describe '@locale' do
47
+ it 'is set to en-CA' do
48
+ expect(subject.instance_variable_get('@locale')).to eq('en-CA')
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'default' do
54
+ describe '#receive_timeout' do
55
+ it 'should be 3600ms' do
56
+ transportclass = subject.instance_variable_get(:@xfer)
57
+ expect(transportclass.receive_timeout).to eql(3600)
58
+ end
59
+ end
60
+ describe '#timeout' do
61
+ it 'should be 60s' do
62
+ expect(subject.timeout).to eql('PT60S')
63
+ end
64
+ end
65
+ describe '@locale' do
66
+ it 'should be en-US' do
67
+ expect(subject.instance_variable_get('@locale')).to eq('en-US')
68
+ end
69
+ end
70
+ describe '@max_env_sz' do
71
+ it 'should be 153600' do
72
+ expect(subject.instance_variable_get('@max_env_sz')).to eq(153_600)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,51 +1,51 @@
1
- # encoding: UTF-8
2
- describe 'winrm client primitives' do
3
- before(:all) do
4
- @winrm = winrm_connection
5
- end
6
-
7
- describe 'open and close shell', integration: true do
8
- it 'should #open_shell and #close_shell' do
9
- sid = @winrm.open_shell
10
- expect(sid).to be_a_uid
11
- expect(@winrm.close_shell(sid)).to be true
12
- end
13
-
14
- it 'should #run_command and #cleanup_command' do
15
- sid = @winrm.open_shell
16
-
17
- cmd_id = @winrm.run_command(sid, 'ipconfig', %w(/all))
18
- expect(sid).to be_a_uid
19
-
20
- expect(@winrm.cleanup_command(sid, cmd_id)).to be true
21
- @winrm.close_shell(sid)
22
- end
23
-
24
- it 'should #get_command_output' do
25
- sid = @winrm.open_shell
26
- cmd_id = @winrm.run_command(sid, 'ipconfig', %w(/all))
27
-
28
- output = @winrm.get_command_output(sid, cmd_id)
29
- expect(output).to have_exit_code 0
30
- expect(output).to have_stdout_match(/.+/)
31
- expect(output).to have_no_stderr
32
-
33
- @winrm.cleanup_command(sid, cmd_id)
34
- @winrm.close_shell(sid)
35
- end
36
-
37
- it 'should #get_command_output with a block' do
38
- sid = @winrm.open_shell
39
- cmd_id = @winrm.run_command(sid, 'ipconfig', %w(/all))
40
-
41
- outvar = ''
42
- @winrm.get_command_output(sid, cmd_id) do |stdout, _stderr|
43
- outvar << stdout
44
- end
45
- expect(outvar).to match(/Windows IP Configuration/)
46
-
47
- @winrm.cleanup_command(sid, cmd_id)
48
- @winrm.close_shell(sid)
49
- end
50
- end
51
- end
1
+ # encoding: UTF-8
2
+ describe 'winrm client primitives' do
3
+ before(:all) do
4
+ @winrm = winrm_connection
5
+ end
6
+
7
+ describe 'open and close shell', integration: true do
8
+ it 'should #open_shell and #close_shell' do
9
+ sid = @winrm.open_shell
10
+ expect(sid).to be_a_uid
11
+ expect(@winrm.close_shell(sid)).to be true
12
+ end
13
+
14
+ it 'should #run_command and #cleanup_command' do
15
+ sid = @winrm.open_shell
16
+
17
+ cmd_id = @winrm.run_command(sid, 'ipconfig', %w(/all))
18
+ expect(sid).to be_a_uid
19
+
20
+ expect(@winrm.cleanup_command(sid, cmd_id)).to be true
21
+ @winrm.close_shell(sid)
22
+ end
23
+
24
+ it 'should #get_command_output' do
25
+ sid = @winrm.open_shell
26
+ cmd_id = @winrm.run_command(sid, 'ipconfig', %w(/all))
27
+
28
+ output = @winrm.get_command_output(sid, cmd_id)
29
+ expect(output).to have_exit_code 0
30
+ expect(output).to have_stdout_match(/.+/)
31
+ expect(output).to have_no_stderr
32
+
33
+ @winrm.cleanup_command(sid, cmd_id)
34
+ @winrm.close_shell(sid)
35
+ end
36
+
37
+ it 'should #get_command_output with a block' do
38
+ sid = @winrm.open_shell
39
+ cmd_id = @winrm.run_command(sid, 'ipconfig', %w(/all))
40
+
41
+ outvar = ''
42
+ @winrm.get_command_output(sid, cmd_id) do |stdout, _stderr|
43
+ outvar << stdout
44
+ end
45
+ expect(outvar).to match(/Windows IP Configuration/)
46
+
47
+ @winrm.cleanup_command(sid, cmd_id)
48
+ @winrm.close_shell(sid)
49
+ end
50
+ end
51
+ end