winrm 1.3.5 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/.rspec +3 -3
- data/.rubocop.yml +9 -9
- data/.travis.yml +4 -4
- data/Gemfile +9 -9
- data/LICENSE +202 -202
- data/README.md +148 -148
- data/Rakefile +28 -28
- data/VERSION +1 -1
- data/Vagrantfile +9 -9
- data/bin/rwinrm +97 -97
- data/changelog.md +49 -46
- data/lib/winrm.rb +41 -41
- data/lib/winrm/exceptions/exceptions.rb +57 -57
- data/lib/winrm/helpers/iso8601_duration.rb +58 -58
- data/lib/winrm/helpers/powershell_script.rb +37 -37
- data/lib/winrm/http/response_handler.rb +82 -82
- data/lib/winrm/http/transport.rb +294 -294
- data/lib/winrm/output.rb +43 -43
- data/lib/winrm/soap_provider.rb +40 -40
- data/lib/winrm/winrm_service.rb +490 -488
- data/preamble +17 -17
- data/spec/auth_timeout_spec.rb +16 -16
- data/spec/cmd_spec.rb +102 -102
- data/spec/config-example.yml +19 -19
- data/spec/exception_spec.rb +50 -50
- data/spec/issue_59_spec.rb +15 -15
- data/spec/matchers.rb +74 -74
- data/spec/output_spec.rb +110 -110
- data/spec/powershell_spec.rb +103 -103
- data/spec/response_handler_spec.rb +59 -59
- data/spec/spec_helper.rb +48 -48
- data/spec/stubs/responses/open_shell_v1.xml +19 -19
- data/spec/stubs/responses/open_shell_v2.xml +20 -20
- data/spec/stubs/responses/soap_fault_v1.xml +36 -36
- data/spec/stubs/responses/soap_fault_v2.xml +42 -42
- data/spec/stubs/responses/wmi_error_v2.xml +41 -41
- data/spec/winrm_options_spec.rb +76 -76
- data/spec/winrm_primitives_spec.rb +51 -51
- data/spec/wql_spec.rb +14 -14
- data/winrm.gemspec +41 -41
- metadata +2 -2
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
|
data/spec/powershell_spec.rb
CHANGED
@@ -1,103 +1,103 @@
|
|
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 'empty string' do
|
8
|
-
subject(:output) { @winrm.powershell('') }
|
9
|
-
it { should have_exit_code 4_294_770_688 }
|
10
|
-
it { should have_stderr_match(/Cannot process the command because of a missing parameter/) }
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'ipconfig' do
|
14
|
-
subject(:output) { @winrm.powershell('ipconfig') }
|
15
|
-
it { should have_exit_code 0 }
|
16
|
-
it { should have_stdout_match(/Windows IP Configuration/) }
|
17
|
-
it { should have_no_stderr }
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'echo \'hello world\' using apostrophes' do
|
21
|
-
subject(:output) { @winrm.powershell("echo 'hello world'") }
|
22
|
-
it { should have_exit_code 0 }
|
23
|
-
it { should have_stdout_match(/hello world/) }
|
24
|
-
it { should have_no_stderr }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'dir with incorrect argument /z' do
|
28
|
-
subject(:output) { @winrm.powershell('dir /z') }
|
29
|
-
it { should have_exit_code 1 }
|
30
|
-
it { should have_no_stdout }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe 'Math area calculation' do
|
34
|
-
subject(:output) do
|
35
|
-
@winrm.powershell(<<-EOH
|
36
|
-
$diameter = 4.5
|
37
|
-
$area = [Math]::pow([Math]::PI * ($diameter/2), 2)
|
38
|
-
Write-Host $area
|
39
|
-
EOH
|
40
|
-
)
|
41
|
-
end
|
42
|
-
it { should have_exit_code 0 }
|
43
|
-
it { should have_stdout_match(/49.9648722805149/) }
|
44
|
-
it { should have_no_stderr }
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'ipconfig with a block' do
|
48
|
-
subject(:stdout) do
|
49
|
-
outvar = ''
|
50
|
-
@winrm.powershell('ipconfig') do |stdout, _stderr|
|
51
|
-
outvar << stdout
|
52
|
-
end
|
53
|
-
outvar
|
54
|
-
end
|
55
|
-
it { should match(/Windows IP Configuration/) }
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'capturing output from Write-Host and Write-Error' do
|
59
|
-
subject(:output) do
|
60
|
-
script = <<-eos
|
61
|
-
Write-Host 'Hello'
|
62
|
-
$host.ui.WriteErrorLine(', world!')
|
63
|
-
eos
|
64
|
-
|
65
|
-
@captured_stdout = ''
|
66
|
-
@captured_stderr = ''
|
67
|
-
@winrm.powershell(script) do |stdout, stderr|
|
68
|
-
@captured_stdout << stdout if stdout
|
69
|
-
@captured_stderr << stderr if stderr
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should have stdout' do
|
74
|
-
expect(output.stdout).to eq("Hello\n")
|
75
|
-
expect(output.stdout).to eq(@captured_stdout)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should have stderr' do
|
79
|
-
# TODO: Option to parse CLIXML
|
80
|
-
# expect(output.output).to eq("Hello\n, world!")
|
81
|
-
# expect(output.stderr).to eq(", world!")
|
82
|
-
expect(output.stderr).to eq(
|
83
|
-
"#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
|
84
|
-
"xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
|
85
|
-
"<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
|
86
|
-
expect(output.stderr).to eq(@captured_stderr)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should have output' do
|
90
|
-
# TODO: Option to parse CLIXML
|
91
|
-
# expect(output.output).to eq("Hello\n, world!")
|
92
|
-
expect(output.output).to eq("Hello\n#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
|
93
|
-
"xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
|
94
|
-
"<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe 'it should handle utf-8 characters' do
|
99
|
-
subject(:output) { @winrm.powershell('echo "✓1234-äöü"') }
|
100
|
-
it { should have_exit_code 0 }
|
101
|
-
it { should have_stdout_match(/✓1234-äöü/) }
|
102
|
-
end
|
103
|
-
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 'empty string' do
|
8
|
+
subject(:output) { @winrm.powershell('') }
|
9
|
+
it { should have_exit_code 4_294_770_688 }
|
10
|
+
it { should have_stderr_match(/Cannot process the command because of a missing parameter/) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'ipconfig' do
|
14
|
+
subject(:output) { @winrm.powershell('ipconfig') }
|
15
|
+
it { should have_exit_code 0 }
|
16
|
+
it { should have_stdout_match(/Windows IP Configuration/) }
|
17
|
+
it { should have_no_stderr }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'echo \'hello world\' using apostrophes' do
|
21
|
+
subject(:output) { @winrm.powershell("echo 'hello world'") }
|
22
|
+
it { should have_exit_code 0 }
|
23
|
+
it { should have_stdout_match(/hello world/) }
|
24
|
+
it { should have_no_stderr }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'dir with incorrect argument /z' do
|
28
|
+
subject(:output) { @winrm.powershell('dir /z') }
|
29
|
+
it { should have_exit_code 1 }
|
30
|
+
it { should have_no_stdout }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'Math area calculation' do
|
34
|
+
subject(:output) do
|
35
|
+
@winrm.powershell(<<-EOH
|
36
|
+
$diameter = 4.5
|
37
|
+
$area = [Math]::pow([Math]::PI * ($diameter/2), 2)
|
38
|
+
Write-Host $area
|
39
|
+
EOH
|
40
|
+
)
|
41
|
+
end
|
42
|
+
it { should have_exit_code 0 }
|
43
|
+
it { should have_stdout_match(/49.9648722805149/) }
|
44
|
+
it { should have_no_stderr }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'ipconfig with a block' do
|
48
|
+
subject(:stdout) do
|
49
|
+
outvar = ''
|
50
|
+
@winrm.powershell('ipconfig') do |stdout, _stderr|
|
51
|
+
outvar << stdout
|
52
|
+
end
|
53
|
+
outvar
|
54
|
+
end
|
55
|
+
it { should match(/Windows IP Configuration/) }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'capturing output from Write-Host and Write-Error' do
|
59
|
+
subject(:output) do
|
60
|
+
script = <<-eos
|
61
|
+
Write-Host 'Hello'
|
62
|
+
$host.ui.WriteErrorLine(', world!')
|
63
|
+
eos
|
64
|
+
|
65
|
+
@captured_stdout = ''
|
66
|
+
@captured_stderr = ''
|
67
|
+
@winrm.powershell(script) do |stdout, stderr|
|
68
|
+
@captured_stdout << stdout if stdout
|
69
|
+
@captured_stderr << stderr if stderr
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should have stdout' do
|
74
|
+
expect(output.stdout).to eq("Hello\n")
|
75
|
+
expect(output.stdout).to eq(@captured_stdout)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should have stderr' do
|
79
|
+
# TODO: Option to parse CLIXML
|
80
|
+
# expect(output.output).to eq("Hello\n, world!")
|
81
|
+
# expect(output.stderr).to eq(", world!")
|
82
|
+
expect(output.stderr).to eq(
|
83
|
+
"#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
|
84
|
+
"xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
|
85
|
+
"<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
|
86
|
+
expect(output.stderr).to eq(@captured_stderr)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should have output' do
|
90
|
+
# TODO: Option to parse CLIXML
|
91
|
+
# expect(output.output).to eq("Hello\n, world!")
|
92
|
+
expect(output.output).to eq("Hello\n#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
|
93
|
+
"xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
|
94
|
+
"<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'it should handle utf-8 characters' do
|
99
|
+
subject(:output) { @winrm.powershell('echo "✓1234-äöü"') }
|
100
|
+
it { should have_exit_code 0 }
|
101
|
+
it { should have_stdout_match(/✓1234-äöü/) }
|
102
|
+
end
|
103
|
+
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
|