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,67 +0,0 @@
1
- # encoding: UTF-8
2
- require 'winrm/winrm_service'
3
- require 'rexml/document'
4
- require 'erb'
5
- require 'base64'
6
-
7
- describe 'issue 184', unit: true do
8
- let(:shell_id) { 'shell-123' }
9
- let(:command_id) { 123 }
10
- let(:test_data_xml_template) do
11
- ERB.new(File.read('spec/stubs/responses/get_command_output_response.xml.erb'))
12
- end
13
- let(:service) do
14
- WinRM::WinRMWebService.new(
15
- 'http://dummy/wsman',
16
- :plaintext,
17
- user: 'dummy',
18
- pass: 'dummy')
19
- end
20
-
21
- describe 'response doc stdout with invalid UTF-8 characters' do
22
- let(:test_data_stdout) { 'ffff' } # Base64-decodes to '}\xF7\xDF', an invalid sequence
23
- let(:test_data_stderr) { '' }
24
- let(:test_data_xml) { test_data_xml_template.result(binding) }
25
-
26
- before do
27
- allow(service).to receive(:send_get_output_message).and_return(
28
- REXML::Document.new(test_data_xml)
29
- )
30
- end
31
-
32
- it 'does not raise an ArgumentError: invalid byte sequence in UTF-8' do
33
- begin
34
- expect(
35
- service.get_command_output(shell_id, command_id)
36
- ).not_to raise_error
37
- rescue RSpec::Expectations::ExpectationNotMetError => e
38
- expect(e.message).not_to include 'ArgumentError'
39
- end
40
- end
41
-
42
- it 'does not have an empty stdout' do
43
- expect(
44
- service.get_command_output(shell_id, command_id)[:data][0][:stdout]
45
- ).not_to be_empty
46
- end
47
- end
48
-
49
- describe 'response doc stdout with valid UTF-8' do
50
- let(:test_data_raw) { '✓1234-äöü' }
51
- let(:test_data_stdout) { Base64.encode64(test_data_raw) }
52
- let(:test_data_stderr) { '' }
53
- let(:test_data_xml) { test_data_xml_template.result(binding) }
54
-
55
- before do
56
- allow(service).to receive(:send_get_output_message).and_return(
57
- REXML::Document.new(test_data_xml)
58
- )
59
- end
60
-
61
- it 'decodes to match input data' do
62
- expect(
63
- service.get_command_output(shell_id, command_id)[:data][0][:stdout]
64
- ).to eq(test_data_raw)
65
- end
66
- end
67
- end
@@ -1,97 +0,0 @@
1
- # encoding: UTF-8
2
- describe 'winrm client powershell', integration: true do
3
- before(:all) do
4
- @winrm = winrm_connection
5
- end
6
-
7
- describe 'ipconfig' do
8
- subject(:output) { @winrm.powershell('ipconfig') }
9
- it { should have_exit_code 0 }
10
- it { should have_stdout_match(/Windows IP Configuration/) }
11
- it { should have_no_stderr }
12
- end
13
-
14
- describe 'echo \'hello world\' using apostrophes' do
15
- subject(:output) { @winrm.powershell("echo 'hello world'") }
16
- it { should have_exit_code 0 }
17
- it { should have_stdout_match(/hello world/) }
18
- it { should have_no_stderr }
19
- end
20
-
21
- describe 'dir with incorrect argument /z' do
22
- subject(:output) { @winrm.powershell('dir /z') }
23
- it { should have_exit_code 1 }
24
- it { should have_no_stdout }
25
- end
26
-
27
- describe 'Math area calculation' do
28
- subject(:output) do
29
- @winrm.powershell(<<-EOH
30
- $diameter = 4.5
31
- $area = [Math]::pow([Math]::PI * ($diameter/2), 2)
32
- Write-Host $area
33
- EOH
34
- )
35
- end
36
- it { should have_exit_code 0 }
37
- it { should have_stdout_match(/49.9648722805149/) }
38
- it { should have_no_stderr }
39
- end
40
-
41
- describe 'ipconfig with a block' do
42
- subject(:stdout) do
43
- outvar = ''
44
- @winrm.powershell('ipconfig') do |stdout, _stderr|
45
- outvar << stdout
46
- end
47
- outvar
48
- end
49
- it { should match(/Windows IP Configuration/) }
50
- end
51
-
52
- describe 'capturing output from Write-Host and Write-Error' do
53
- subject(:output) do
54
- script = <<-eos
55
- Write-Host 'Hello'
56
- $host.ui.WriteErrorLine(', world!')
57
- eos
58
-
59
- @captured_stdout = ''
60
- @captured_stderr = ''
61
- @winrm.powershell(script) do |stdout, stderr|
62
- @captured_stdout << stdout if stdout
63
- @captured_stderr << stderr if stderr
64
- end
65
- end
66
-
67
- it 'should have stdout' do
68
- expect(output.stdout).to eq("Hello\n")
69
- expect(output.stdout).to eq(@captured_stdout)
70
- end
71
-
72
- it 'should have stderr' do
73
- # TODO: Option to parse CLIXML
74
- # expect(output.output).to eq("Hello\n, world!")
75
- # expect(output.stderr).to eq(", world!")
76
- expect(output.stderr).to eq(
77
- "#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
78
- "xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
79
- "<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
80
- expect(output.stderr).to eq(@captured_stderr)
81
- end
82
-
83
- it 'should have output' do
84
- # TODO: Option to parse CLIXML
85
- # expect(output.output).to eq("Hello\n, world!")
86
- expect(output.output).to eq("Hello\n#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
87
- "xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
88
- "<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
89
- end
90
- end
91
-
92
- describe 'it should handle utf-8 characters' do
93
- subject(:output) { @winrm.powershell('echo "✓1234-äöü"') }
94
- it { should have_exit_code 0 }
95
- it { should have_stdout_match(/✓1234-äöü/) }
96
- end
97
- end
@@ -1,76 +0,0 @@
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 70s' do
56
- transportclass = subject.instance_variable_get(:@xfer)
57
- expect(transportclass.receive_timeout).to eql(70)
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 +0,0 @@
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