winrm 2.3.0 → 2.3.1

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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/lib/winrm/http/transport.rb +1 -1
  3. data/lib/winrm/psrp/message.rb +128 -128
  4. data/lib/winrm/shells/power_shell.rb +0 -1
  5. data/lib/winrm/version.rb +1 -1
  6. metadata +12 -85
  7. data/.gitignore +0 -10
  8. data/.rubocop.yml +0 -38
  9. data/.travis.yml +0 -10
  10. data/Gemfile +0 -2
  11. data/Rakefile +0 -33
  12. data/Vagrantfile +0 -6
  13. data/WinrmAppveyor.psm1 +0 -32
  14. data/appveyor.yml +0 -50
  15. data/changelog.md +0 -133
  16. data/preamble +0 -17
  17. data/tests/integration/auth_timeout_spec.rb +0 -17
  18. data/tests/integration/cmd_spec.rb +0 -130
  19. data/tests/integration/config-example.yml +0 -16
  20. data/tests/integration/issue_59_spec.rb +0 -25
  21. data/tests/integration/powershell_spec.rb +0 -164
  22. data/tests/integration/spec_helper.rb +0 -62
  23. data/tests/integration/transport_spec.rb +0 -98
  24. data/tests/integration/wql_spec.rb +0 -33
  25. data/tests/matchers.rb +0 -59
  26. data/tests/spec/configuration_spec.rb +0 -183
  27. data/tests/spec/connection_spec.rb +0 -37
  28. data/tests/spec/exception_spec.rb +0 -49
  29. data/tests/spec/http/transport_factory_spec.rb +0 -66
  30. data/tests/spec/http/transport_spec.rb +0 -43
  31. data/tests/spec/output_spec.rb +0 -128
  32. data/tests/spec/psrp/fragment_spec.rb +0 -60
  33. data/tests/spec/psrp/message_data/base_spec.rb +0 -11
  34. data/tests/spec/psrp/message_data/error_record_spec.rb +0 -39
  35. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -23
  36. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -30
  37. data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -38
  38. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -23
  39. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -14
  40. data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -28
  41. data/tests/spec/psrp/message_data_spec.rb +0 -33
  42. data/tests/spec/psrp/message_defragmenter_spec.rb +0 -45
  43. data/tests/spec/psrp/message_fragmenter_spec.rb +0 -103
  44. data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -98
  45. data/tests/spec/psrp/psrp_message_spec.rb +0 -73
  46. data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -170
  47. data/tests/spec/psrp/uuid_spec.rb +0 -28
  48. data/tests/spec/response_handler_spec.rb +0 -69
  49. data/tests/spec/shells/base_spec.rb +0 -227
  50. data/tests/spec/shells/cmd_spec.rb +0 -75
  51. data/tests/spec/shells/powershell_spec.rb +0 -221
  52. data/tests/spec/spec_helper.rb +0 -46
  53. data/tests/spec/stubs/clixml/error_record.xml.erb +0 -84
  54. data/tests/spec/stubs/clixml/pipeline_state.xml.erb +0 -88
  55. data/tests/spec/stubs/responses/get_command_output_response.xml.erb +0 -13
  56. data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +0 -10
  57. data/tests/spec/stubs/responses/get_omi_command_output_response.xml.erb +0 -23
  58. data/tests/spec/stubs/responses/get_omi_command_output_response_not_done.xml.erb +0 -24
  59. data/tests/spec/stubs/responses/get_omi_config_response.xml +0 -45
  60. data/tests/spec/stubs/responses/get_omi_powershell_keepalive_response.xml.erb +0 -33
  61. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +0 -10
  62. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +0 -12
  63. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +0 -9
  64. data/tests/spec/stubs/responses/open_shell_omi.xml +0 -43
  65. data/tests/spec/stubs/responses/open_shell_v1.xml +0 -19
  66. data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
  67. data/tests/spec/stubs/responses/soap_fault_omi.xml +0 -31
  68. data/tests/spec/stubs/responses/soap_fault_v1.xml +0 -36
  69. data/tests/spec/stubs/responses/soap_fault_v2.xml +0 -42
  70. data/tests/spec/stubs/responses/wmi_error_v2.xml +0 -41
  71. data/tests/spec/wsmv/cleanup_command_spec.rb +0 -20
  72. data/tests/spec/wsmv/close_shell_spec.rb +0 -15
  73. data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -35
  74. data/tests/spec/wsmv/command_output_spec.rb +0 -43
  75. data/tests/spec/wsmv/command_spec.rb +0 -17
  76. data/tests/spec/wsmv/configuration_spec.rb +0 -15
  77. data/tests/spec/wsmv/create_pipeline_spec.rb +0 -30
  78. data/tests/spec/wsmv/create_shell_spec.rb +0 -39
  79. data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -38
  80. data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
  81. data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -124
  82. data/tests/spec/wsmv/send_data_spec.rb +0 -30
  83. data/tests/spec/wsmv/wql_query_spec.rb +0 -11
  84. data/tests/spec/wsmv/write_stdin_spec.rb +0 -20
  85. data/winrm.gemspec +0 -46
@@ -1,16 +0,0 @@
1
- # Copy this file to config.yml and edit the settings below.
2
- # This should work out of the box for vagrant provisioned boxes.
3
-
4
- ## Kerberos
5
- # auth_type: kerberos
6
- # realm: "your.realm"
7
- # endpoint: "http://<yourserver>:5985/wsman"
8
-
9
- # If you are running this in a vagrant provisioned box using NAT,
10
- # this will be the forwarded WinRM HTTP port to your VM.
11
- # If you are running this on the VM, the default HTTP port is 5985.
12
- # See README.md#Troubleshooting.
13
-
14
- endpoint: "http://localhost:55985/wsman"
15
- user: vagrant
16
- password: vagrant
@@ -1,25 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe 'issue 59' do
4
- describe 'long running script without output' do
5
- let(:logged_output) { StringIO.new }
6
- let(:logger) { Logging.logger(logged_output) }
7
-
8
- before do
9
- opts = connection_opts.dup
10
- opts[:operation_timeout] = 1
11
- conn = WinRM::Connection.new(opts)
12
- conn.logger = logger
13
- @powershell = conn.shell(:powershell)
14
- end
15
-
16
- it 'should not error' do
17
- out = @powershell.run('$ProgressPreference="SilentlyContinue";sleep 3; Write-Host "Hello"')
18
-
19
- expect(out).to have_exit_code 0
20
- expect(out).to have_stdout_match(/Hello/)
21
- expect(out).to have_no_stderr
22
- expect(logged_output.string).to match(/retrying receive request/)
23
- end
24
- end
25
- end
@@ -1,164 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe 'winrm client powershell' do
4
- before(:all) do
5
- @powershell = winrm_connection.shell(:powershell)
6
- end
7
-
8
- describe 'ipconfig' do
9
- subject(:output) { @powershell.run('ipconfig') }
10
- it { should have_exit_code 0 }
11
- it { should have_stdout_match(/Windows IP Configuration/) }
12
- it { should have_no_stderr }
13
- end
14
-
15
- describe 'ipconfig with invalid args' do
16
- subject(:output) { @powershell.run('ipconfig blah') }
17
- it { should have_exit_code 1 }
18
- end
19
-
20
- describe 'throw' do
21
- subject(:output) { @powershell.run("throw 'an error occured'") }
22
- it { should have_exit_code 0 }
23
- it { should have_stderr_match(/an error occured/) }
24
- end
25
-
26
- describe 'exit' do
27
- subject(:output) { @powershell.run('exit 5') }
28
- it { should have_exit_code 5 }
29
- end
30
-
31
- describe 'echo \'hello world\' using apostrophes' do
32
- subject(:output) { @powershell.run("echo 'hello world'") }
33
- it { should have_exit_code 0 }
34
- it { should have_stdout_match(/hello world/) }
35
- it { should have_no_stderr }
36
- end
37
-
38
- describe 'handling special XML characters' do
39
- subject(:output) { @powershell.run("echo 'hello & <world>'") }
40
- it { should have_exit_code 0 }
41
- it { should have_stdout_match(/hello & <world>/) }
42
- it { should have_no_stderr }
43
- end
44
-
45
- describe 'dir with incorrect argument /z' do
46
- subject(:output) { @powershell.run('dir /z') }
47
- it { should have_stderr_match(/Cannot find path/) }
48
- it { should have_no_stdout }
49
- end
50
-
51
- describe 'Math area calculation' do
52
- subject(:output) do
53
- @powershell.run <<-EOH
54
- $diameter = 4.5
55
- $area = [Math]::pow([Math]::PI * ($diameter/2), 2)
56
- Write-Host $area
57
- EOH
58
- end
59
- it { should have_exit_code 0 }
60
- it { should have_stdout_match(/49.9648722805149/) }
61
- it { should have_no_stderr }
62
- end
63
-
64
- describe 'ipconfig with a block' do
65
- subject(:stdout) do
66
- outvar = ''
67
- @powershell.run('ipconfig') do |stdout, _stderr|
68
- outvar << stdout
69
- end
70
- outvar
71
- end
72
- it { should match(/Windows IP Configuration/) }
73
- end
74
-
75
- describe 'capturing output from Write-Host and Write-Error' do
76
- subject(:output) do
77
- script = <<-EOS
78
- Write-Host 'Hello'
79
- $host.ui.WriteErrorLine(', world!')
80
- EOS
81
-
82
- @captured_stdout = ''
83
- @captured_stderr = ''
84
- @powershell.run(script) do |stdout, stderr|
85
- @captured_stdout << stdout if stdout
86
- @captured_stderr << stderr if stderr
87
- end
88
- end
89
-
90
- it 'should have stdout' do
91
- expect(output.stdout).to eq("Hello\r\n")
92
- expect(output.stdout).to eq(@captured_stdout)
93
- end
94
-
95
- it 'should have stderr' do
96
- expect(output.stderr).to eq(", world!\r\n")
97
- expect(output.stderr).to eq(@captured_stderr)
98
- end
99
-
100
- it 'should have output' do
101
- expect(output.output).to eq("Hello\r\n, world!\r\n")
102
- end
103
- end
104
-
105
- describe 'capturing output from pipeline followed by Host' do
106
- subject(:output) do
107
- script = <<-EOS
108
- Write-Output 'output'
109
- $host.UI.Writeline('host')
110
- EOS
111
-
112
- @captured_stdout = ''
113
- @captured_stderr = ''
114
- @powershell.run(script) do |stdout, stderr|
115
- @captured_stdout << stdout if stdout
116
- @captured_stderr << stderr if stderr
117
- end
118
- end
119
-
120
- it 'should print from the pipeline first' do
121
- expect(output.stdout).to start_with("output\r\n")
122
- end
123
-
124
- it 'should write to host last' do
125
- expect(output.stdout).to end_with("host\r\n")
126
- end
127
- end
128
-
129
- describe 'it should handle utf-8 characters' do
130
- subject(:output) { @powershell.run('echo "✓1234-äöü"') }
131
- it { should have_exit_code 0 }
132
- it { should have_stdout_match(/✓1234-äöü/) }
133
- end
134
-
135
- describe 'output exceeds a single fragment' do
136
- subject(:output) { @powershell.run('Write-Output $("a"*600000)') }
137
- it { should have_exit_code 0 }
138
- it 'has assebled the output' do
139
- expect(output.stdout).to eq('a' * 600000 + "\r\n")
140
- end
141
- end
142
-
143
- describe 'command exceeds a single fragment' do
144
- subject(:output) { @powershell.run("$var='#{'a' * 600000}';Write-Output 'long var'") }
145
- it { should have_exit_code 0 }
146
- it 'has sent the output' do
147
- expect(output.stdout).to eq("long var\r\n")
148
- end
149
- end
150
-
151
- describe 'reading pipeline messages' do
152
- subject(:messages) { @powershell.send_pipeline_command('ipconfig') }
153
-
154
- it 'returns multiple messages' do
155
- expect(messages.length).to be > 1
156
- end
157
- it 'first message is pipeline output' do
158
- expect(messages.first.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output])
159
- end
160
- it 'last message is pipeline state' do
161
- expect(messages.last.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state])
162
- end
163
- end
164
- end
@@ -1,62 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'winrm'
4
- require 'json'
5
- require_relative '../matchers'
6
-
7
- # Creates a WinRM connection for integration tests
8
- module ConnectionHelper
9
- def winrm_connection
10
- WinRM::Connection.new(connection_opts)
11
- end
12
-
13
- def connection_opts
14
- @connection_opts ||= begin
15
- cfg = symbolize_keys(YAML.safe_load(File.read(winrm_config_path)))
16
- merge_environment(cfg)
17
- end
18
- end
19
-
20
- def merge_environment(config)
21
- merge_config_option_from_environment(config, 'user')
22
- merge_config_option_from_environment(config, 'password')
23
- merge_config_option_from_environment(config, 'no_ssl_peer_verification')
24
- config[:ssl_peer_fingerprint] = ENV['winrm_cert'] if ENV['use_ssl_peer_fingerprint']
25
- config[:endpoint] = ENV['winrm_endpoint'] if ENV['winrm_endpoint']
26
- config
27
- end
28
-
29
- def merge_config_option_from_environment(config, key)
30
- env_key = 'winrm_' + key
31
- config[key.to_sym] = ENV[env_key] if ENV[env_key]
32
- end
33
-
34
- def winrm_config_path
35
- # Copy config-example.yml to config.yml and edit for your local ConnectionOpts
36
- path = File.expand_path("#{File.dirname(__FILE__)}/config.yml")
37
- unless File.exist?(path)
38
- # user hasn't done this, so use sane defaults for unit tests
39
- path = File.expand_path("#{File.dirname(__FILE__)}/config-example.yml")
40
- end
41
- path
42
- end
43
-
44
- def symbolize_keys(hash)
45
- hash.each_with_object({}) do |(key, value), result|
46
- new_key = case key
47
- when String then key.to_sym
48
- else key
49
- end
50
- new_value = case value
51
- when Hash then symbolize_keys(value)
52
- else value
53
- end
54
- result[new_key] = new_value
55
- result
56
- end
57
- end
58
- end
59
-
60
- RSpec.configure do |config|
61
- config.include(ConnectionHelper)
62
- end
@@ -1,98 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe 'WinRM connection' do
4
- let(:connection) do
5
- endpoint = connection_opts[:endpoint].dup
6
- if auth_type == :ssl
7
- endpoint.sub!('5985', '5986')
8
- endpoint.sub!('http', 'https')
9
- end
10
- conn_options = {
11
- transport: auth_type,
12
- endpoint: endpoint
13
- }.merge(options)
14
- WinRM::Connection.new(conn_options).shell(:cmd)
15
- end
16
- let(:options) do
17
- opts = {}
18
- opts[:user] = connection_opts[:user]
19
- opts[:password] = connection_opts[:password]
20
- opts[:basic_auth_only] = basic_auth_only
21
- opts[:no_ssl_peer_verification] = no_ssl_peer_verification
22
- opts[:ssl_peer_fingerprint] = ssl_peer_fingerprint
23
- opts[:client_cert] = user_cert
24
- opts[:client_key] = user_key
25
- opts
26
- end
27
- let(:basic_auth_only) { false }
28
- let(:no_ssl_peer_verification) { false }
29
- let(:ssl_peer_fingerprint) { nil }
30
- let(:user_cert) { nil }
31
- let(:user_key) { nil }
32
-
33
- subject(:output) { connection.run('ipconfig') }
34
-
35
- after(:each) do
36
- connection.close
37
- end
38
-
39
- shared_examples 'a valid_connection' do
40
- it 'has a 0 exit code' do
41
- expect(subject).to have_exit_code 0
42
- end
43
-
44
- it 'includes command output' do
45
- expect(subject).to have_stdout_match(/Windows IP Configuration/)
46
- end
47
-
48
- it 'has no errors' do
49
- expect(subject).to have_no_stderr
50
- end
51
- end
52
-
53
- context 'HttpPlaintext' do
54
- let(:basic_auth_only) { true }
55
- let(:auth_type) { :plaintext }
56
-
57
- it_behaves_like 'a valid_connection'
58
- end
59
-
60
- context 'HttpNegotiate' do
61
- let(:auth_type) { :negotiate }
62
-
63
- it_behaves_like 'a valid_connection'
64
- end
65
-
66
- context 'BasicAuthSSL', skip: ENV['winrm_cert'].nil? do
67
- let(:basic_auth_only) { true }
68
- let(:auth_type) { :ssl }
69
- let(:no_ssl_peer_verification) { true }
70
-
71
- it_behaves_like 'a valid_connection'
72
- end
73
-
74
- context 'ClientCertAuthSSL', skip: ENV['user_cert'].nil? do
75
- let(:auth_type) { :ssl }
76
- let(:no_ssl_peer_verification) { true }
77
- let(:user_cert) { ENV['user_cert'] }
78
- let(:user_key) { ENV['user_key'] }
79
-
80
- before { options[:pass] = nil }
81
-
82
- it_behaves_like 'a valid_connection'
83
- end
84
-
85
- context 'Negotiate over SSL', skip: ENV['winrm_cert'].nil? do
86
- let(:auth_type) { :ssl }
87
- let(:no_ssl_peer_verification) { true }
88
-
89
- it_behaves_like 'a valid_connection'
90
- end
91
-
92
- context 'SSL fingerprint', skip: ENV['winrm_cert'].nil? do
93
- let(:auth_type) { :ssl }
94
- let(:ssl_peer_fingerprint) { ENV['winrm_cert'] }
95
-
96
- it_behaves_like 'a valid_connection'
97
- end
98
- end
@@ -1,33 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe 'winrm client wql' do
4
- before(:all) do
5
- @winrm = winrm_connection
6
- end
7
-
8
- it 'should query Win32_OperatingSystem' do
9
- output = @winrm.run_wql('select * from Win32_OperatingSystem')
10
- expect(output).to_not be_empty
11
- output_caption = output[:win32_operating_system][0][:caption]
12
- expect(output_caption).to include('Microsoft')
13
- expect(output_caption).to include('Windows')
14
- end
15
-
16
- it 'should query Win32_Process' do
17
- output = @winrm.run_wql('select * from Win32_Process')
18
- expect(output).to_not be_empty
19
- process_count = output[:win32_process].count
20
- expect(process_count).to be > 1
21
- expect(output[:win32_process]).to all(include(:command_line))
22
- end
23
-
24
- it 'should query Win32_Process with block' do
25
- count = 0
26
- @winrm.run_wql('select * from Win32_Process') do |type, item|
27
- expect(type).to eq(:win32_process)
28
- expect(item).to include(:command_line)
29
- count += 1
30
- end
31
- expect(count).to be > 1
32
- end
33
- end
@@ -1,59 +0,0 @@
1
- require 'rspec/expectations'
2
-
3
- # rspec matchers
4
- RSpec::Matchers.define :have_stdout_match do |expected_stdout|
5
- match do |actual_output|
6
- !expected_stdout.match(actual_output.stdout).nil?
7
- end
8
- failure_message do |actual_output|
9
- "expected that '#{actual_output.stdout}' would match #{expected_stdout}"
10
- end
11
- end
12
-
13
- RSpec::Matchers.define :have_stderr_match do |expected_stderr|
14
- match do |actual_output|
15
- !expected_stderr.match(actual_output.stderr).nil?
16
- end
17
- failure_message do |actual_output|
18
- "expected that '#{actual_output.stderr}' would match #{expected_stderr}"
19
- end
20
- end
21
-
22
- RSpec::Matchers.define :have_no_stdout do
23
- match do |actual_output|
24
- stdout = actual_output.stdout
25
- ['\r\n', ''].include?(stdout)
26
- end
27
- failure_message do |actual_output|
28
- "expected that '#{actual_output.stdout}' would have no stdout"
29
- end
30
- end
31
-
32
- RSpec::Matchers.define :have_no_stderr do
33
- match do |actual_output|
34
- stderr = actual_output.stderr
35
- ['\r\n', ''].include?(stderr)
36
- end
37
- failure_message do |actual_output|
38
- "expected that '#{actual_output.stderr}' would have no stderr"
39
- end
40
- end
41
-
42
- RSpec::Matchers.define :have_exit_code do |expected_exit_code|
43
- match do |actual_output|
44
- expected_exit_code == actual_output.exitcode
45
- end
46
- failure_message do |actual_output|
47
- "expected exit code #{expected_exit_code}, but got #{actual_output.exitcode}"
48
- end
49
- end
50
-
51
- RSpec::Matchers.define :be_a_uid do
52
- match do |actual|
53
- # WinRM1.1 returns uuid's prefixed with 'uuid:' where as later versions do not
54
- actual && actual.to_s.match(/^(uuid:)*\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/)
55
- end
56
- failure_message do |actual|
57
- "expected a uid, but got '#{actual}'"
58
- end
59
- end