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
data/spec/output_spec.rb CHANGED
@@ -1,110 +1,110 @@
1
- # encoding: UTF-8
2
- describe WinRM::Output, unit: true do
3
- subject { WinRM::Output.new }
4
-
5
- context 'when there is no output' do
6
- describe '#stdout' do
7
- it 'is empty' do
8
- expect(subject.stdout).to be_empty
9
- end
10
- end
11
-
12
- describe '#stderr' do
13
- it 'is empty' do
14
- expect(subject.stderr).to be_empty
15
- end
16
- end
17
-
18
- describe '#output' do
19
- it 'is empty' do
20
- expect(subject.output).to be_empty
21
- end
22
- end
23
- end
24
-
25
- context 'when there is only one line' do
26
- describe '#stdout' do
27
- it 'is equal to that line' do
28
- subject[:data] << { stdout: 'foo' }
29
- expect(subject.stdout).to eq('foo')
30
- end
31
- end
32
-
33
- describe '#stderr' do
34
- it 'is equal to that line' do
35
- subject[:data] << { stderr: 'foo' }
36
- expect(subject.stderr).to eq('foo')
37
- end
38
- end
39
-
40
- describe '#output' do
41
- it 'is equal to stdout' do
42
- subject[:data] << { stdout: 'foo' }
43
- expect(subject.output).to eq('foo')
44
- end
45
-
46
- it 'is equal to stderr' do
47
- subject[:data] << { stderr: 'foo' }
48
- expect(subject.output).to eq('foo')
49
- end
50
- end
51
- end
52
-
53
- context 'when there is one line of each type' do
54
- before(:each) do
55
- subject[:data] << { stdout: 'foo' }
56
- subject[:data] << { stderr: 'bar' }
57
- end
58
-
59
- describe '#stdout' do
60
- it 'is equal to that line' do
61
- expect(subject.stdout).to eq('foo')
62
- end
63
- end
64
-
65
- describe '#stderr' do
66
- it 'is equal to that line' do
67
- expect(subject.stderr).to eq('bar')
68
- end
69
- end
70
-
71
- describe '#output' do
72
- it 'is equal to stdout + stderr' do
73
- expect(subject.output).to eq('foobar')
74
- end
75
- end
76
- end
77
-
78
- context 'when there are multiple lines' do
79
- before(:each) do
80
- subject[:data] << { stdout: 'I can have a newline\nanywhere, ' }
81
- subject[:data] << { stderr: 'I can also have stderr' }
82
- subject[:data] << { stdout: 'or stdout', stderr: ' and stderr' }
83
- subject[:data] << {}
84
- subject[:data] << { stdout: ' or nothing! (above)' }
85
- end
86
-
87
- describe '#stdout' do
88
- it 'is equal to that line' do
89
- expect(subject.stdout).to eq(
90
- 'I can have a newline\nanywhere, or stdout or nothing! (above)')
91
- end
92
- end
93
-
94
- describe '#stderr' do
95
- it 'is equal to that line' do
96
- expect(subject.stderr).to eq('I can also have stderr and stderr')
97
- end
98
- end
99
-
100
- describe '#output' do
101
- it 'is equal to stdout + stderr' do
102
- expect(subject.output).to eq(
103
- 'I can have a newline\nanywhere, I can also have stderror stdout ' \
104
- 'and stderr or nothing! (above)')
105
- end
106
- end
107
- end
108
-
109
- pending 'parse CLIXML errors and convert to Strings and/or Exceptions'
110
- end
1
+ # encoding: UTF-8
2
+ describe WinRM::Output, unit: true do
3
+ subject { WinRM::Output.new }
4
+
5
+ context 'when there is no output' do
6
+ describe '#stdout' do
7
+ it 'is empty' do
8
+ expect(subject.stdout).to be_empty
9
+ end
10
+ end
11
+
12
+ describe '#stderr' do
13
+ it 'is empty' do
14
+ expect(subject.stderr).to be_empty
15
+ end
16
+ end
17
+
18
+ describe '#output' do
19
+ it 'is empty' do
20
+ expect(subject.output).to be_empty
21
+ end
22
+ end
23
+ end
24
+
25
+ context 'when there is only one line' do
26
+ describe '#stdout' do
27
+ it 'is equal to that line' do
28
+ subject[:data] << { stdout: 'foo' }
29
+ expect(subject.stdout).to eq('foo')
30
+ end
31
+ end
32
+
33
+ describe '#stderr' do
34
+ it 'is equal to that line' do
35
+ subject[:data] << { stderr: 'foo' }
36
+ expect(subject.stderr).to eq('foo')
37
+ end
38
+ end
39
+
40
+ describe '#output' do
41
+ it 'is equal to stdout' do
42
+ subject[:data] << { stdout: 'foo' }
43
+ expect(subject.output).to eq('foo')
44
+ end
45
+
46
+ it 'is equal to stderr' do
47
+ subject[:data] << { stderr: 'foo' }
48
+ expect(subject.output).to eq('foo')
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'when there is one line of each type' do
54
+ before(:each) do
55
+ subject[:data] << { stdout: 'foo' }
56
+ subject[:data] << { stderr: 'bar' }
57
+ end
58
+
59
+ describe '#stdout' do
60
+ it 'is equal to that line' do
61
+ expect(subject.stdout).to eq('foo')
62
+ end
63
+ end
64
+
65
+ describe '#stderr' do
66
+ it 'is equal to that line' do
67
+ expect(subject.stderr).to eq('bar')
68
+ end
69
+ end
70
+
71
+ describe '#output' do
72
+ it 'is equal to stdout + stderr' do
73
+ expect(subject.output).to eq('foobar')
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'when there are multiple lines' do
79
+ before(:each) do
80
+ subject[:data] << { stdout: 'I can have a newline\nanywhere, ' }
81
+ subject[:data] << { stderr: 'I can also have stderr' }
82
+ subject[:data] << { stdout: 'or stdout', stderr: ' and stderr' }
83
+ subject[:data] << {}
84
+ subject[:data] << { stdout: ' or nothing! (above)' }
85
+ end
86
+
87
+ describe '#stdout' do
88
+ it 'is equal to that line' do
89
+ expect(subject.stdout).to eq(
90
+ 'I can have a newline\nanywhere, or stdout or nothing! (above)')
91
+ end
92
+ end
93
+
94
+ describe '#stderr' do
95
+ it 'is equal to that line' do
96
+ expect(subject.stderr).to eq('I can also have stderr and stderr')
97
+ end
98
+ end
99
+
100
+ describe '#output' do
101
+ it 'is equal to stdout + stderr' do
102
+ expect(subject.output).to eq(
103
+ 'I can have a newline\nanywhere, I can also have stderror stdout ' \
104
+ 'and stderr or nothing! (above)')
105
+ end
106
+ end
107
+ end
108
+
109
+ pending 'parse CLIXML errors and convert to Strings and/or Exceptions'
110
+ end
@@ -1,97 +1,97 @@
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
+ # 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,59 +1,59 @@
1
- # encoding: UTF-8
2
- require 'winrm/http/response_handler'
3
-
4
- describe 'response handler', unit: true do
5
- %w(v1, v2).each do |winrm_version|
6
- let(:soap_fault) { File.read("spec/stubs/responses/soap_fault_#{winrm_version}.xml") }
7
- let(:open_shell) { File.read("spec/stubs/responses/open_shell_#{winrm_version}.xml") }
8
-
9
- describe "successful 200 #{winrm_version} response" do
10
- it 'returns an xml doc' do
11
- handler = WinRM::ResponseHandler.new(open_shell, 200)
12
- xml_doc = handler.parse_to_xml
13
- expect(xml_doc).to be_instance_of(REXML::Document)
14
- expect(xml_doc.to_s).to eq(REXML::Document.new(open_shell).to_s)
15
- end
16
- end
17
-
18
- describe "failed 500 #{winrm_version} response" do
19
- it 'raises a WinRMHTTPTransportError' do
20
- handler = WinRM::ResponseHandler.new('', 500)
21
- expect { handler.parse_to_xml }.to raise_error(WinRM::WinRMHTTPTransportError)
22
- end
23
- end
24
-
25
- describe "failed 401 #{winrm_version} response" do
26
- it 'raises a WinRMAuthorizationError' do
27
- handler = WinRM::ResponseHandler.new('', 401)
28
- expect { handler.parse_to_xml }.to raise_error(WinRM::WinRMAuthorizationError)
29
- end
30
- end
31
-
32
- describe "failed 400 #{winrm_version} response" do
33
- it 'raises a WinRMWSManFault' do
34
- handler = WinRM::ResponseHandler.new(soap_fault, 400)
35
- begin
36
- handler.parse_to_xml
37
- rescue WinRM::WinRMWSManFault => e
38
- expect(e.fault_code).to eq('2150858778')
39
- expect(e.fault_description).to include(
40
- 'The specified class does not exist in the given namespace')
41
- end
42
- end
43
- end
44
- end
45
-
46
- describe 'failed 500 WMI error response' do
47
- let(:wmi_error) { File.read('spec/stubs/responses/wmi_error_v2.xml') }
48
-
49
- it 'raises a WinRMWMIError' do
50
- handler = WinRM::ResponseHandler.new(wmi_error, 500)
51
- begin
52
- handler.parse_to_xml
53
- rescue WinRM::WinRMWMIError => e
54
- expect(e.error_code).to eq('2150859173')
55
- expect(e.error).to include('The WS-Management service cannot process the request.')
56
- end
57
- end
58
- end
59
- end
1
+ # encoding: UTF-8
2
+ require 'winrm/http/response_handler'
3
+
4
+ describe 'response handler', unit: true do
5
+ %w(v1, v2).each do |winrm_version|
6
+ let(:soap_fault) { File.read("spec/stubs/responses/soap_fault_#{winrm_version}.xml") }
7
+ let(:open_shell) { File.read("spec/stubs/responses/open_shell_#{winrm_version}.xml") }
8
+
9
+ describe "successful 200 #{winrm_version} response" do
10
+ it 'returns an xml doc' do
11
+ handler = WinRM::ResponseHandler.new(open_shell, 200)
12
+ xml_doc = handler.parse_to_xml
13
+ expect(xml_doc).to be_instance_of(REXML::Document)
14
+ expect(xml_doc.to_s).to eq(REXML::Document.new(open_shell).to_s)
15
+ end
16
+ end
17
+
18
+ describe "failed 500 #{winrm_version} response" do
19
+ it 'raises a WinRMHTTPTransportError' do
20
+ handler = WinRM::ResponseHandler.new('', 500)
21
+ expect { handler.parse_to_xml }.to raise_error(WinRM::WinRMHTTPTransportError)
22
+ end
23
+ end
24
+
25
+ describe "failed 401 #{winrm_version} response" do
26
+ it 'raises a WinRMAuthorizationError' do
27
+ handler = WinRM::ResponseHandler.new('', 401)
28
+ expect { handler.parse_to_xml }.to raise_error(WinRM::WinRMAuthorizationError)
29
+ end
30
+ end
31
+
32
+ describe "failed 400 #{winrm_version} response" do
33
+ it 'raises a WinRMWSManFault' do
34
+ handler = WinRM::ResponseHandler.new(soap_fault, 400)
35
+ begin
36
+ handler.parse_to_xml
37
+ rescue WinRM::WinRMWSManFault => e
38
+ expect(e.fault_code).to eq('2150858778')
39
+ expect(e.fault_description).to include(
40
+ 'The specified class does not exist in the given namespace')
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ describe 'failed 500 WMI error response' do
47
+ let(:wmi_error) { File.read('spec/stubs/responses/wmi_error_v2.xml') }
48
+
49
+ it 'raises a WinRMWMIError' do
50
+ handler = WinRM::ResponseHandler.new(wmi_error, 500)
51
+ begin
52
+ handler.parse_to_xml
53
+ rescue WinRM::WinRMWMIError => e
54
+ expect(e.error_code).to eq('2150859173')
55
+ expect(e.error).to include('The WS-Management service cannot process the request.')
56
+ end
57
+ end
58
+ end
59
+ end