winrm 1.3.0.dev.3 → 1.3.0

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.
@@ -1,8 +1,9 @@
1
+ # encoding: UTF-8
1
2
  # This test may only be meaningful with kerberos auth
2
3
  # Against server 2012, a kerberos connection will require reauth (get a 401)
3
4
  # if there are no requests for >= 15 seconds
4
5
 
5
- describe "Verify kerberos will reauth when necessary", :kerberos => true do
6
+ describe 'Verify kerberos will reauth when necessary', kerberos: true do
6
7
  before(:all) do
7
8
  @winrm = winrm_connection
8
9
  end
data/spec/cmd_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
- describe 'winrm client cmd', :integration => true do
1
+ # encoding: UTF-8
2
+ describe 'winrm client cmd', integration: true do
2
3
  before(:all) do
3
4
  @winrm = winrm_connection
4
5
  end
@@ -13,14 +14,14 @@ describe 'winrm client cmd', :integration => true do
13
14
  describe 'ipconfig' do
14
15
  subject(:output) { @winrm.cmd('ipconfig') }
15
16
  it { should have_exit_code 0 }
16
- it { should have_stdout_match /Windows IP Configuration/ }
17
+ it { should have_stdout_match(/Windows IP Configuration/) }
17
18
  it { should have_no_stderr }
18
19
  end
19
20
 
20
21
  describe 'echo \'hello world\' using apostrophes' do
21
22
  subject(:output) { @winrm.cmd("echo 'hello world'") }
22
23
  it { should have_exit_code 0 }
23
- it { should have_stdout_match /'hello world'/ }
24
+ it { should have_stdout_match(/'hello world'/) }
24
25
  it { should have_no_stderr }
25
26
  end
26
27
 
@@ -32,9 +33,9 @@ describe 'winrm client cmd', :integration => true do
32
33
  # echo , world! 1>&2
33
34
  # eos
34
35
 
35
- script = "echo Hello & echo , world! 1>&2"
36
+ script = 'echo Hello & echo , world! 1>&2'
36
37
 
37
- @captured_stdout, @captured_stderr = "", ""
38
+ @captured_stdout, @captured_stderr = '', ''
38
39
  @winrm.cmd(script) do |stdout, stderr|
39
40
  @captured_stdout << stdout if stdout
40
41
  @captured_stderr << stderr if stderr
@@ -57,9 +58,9 @@ describe 'winrm client cmd', :integration => true do
57
58
  end
58
59
 
59
60
  describe 'ipconfig with /all argument' do
60
- subject(:output) { @winrm.cmd('ipconfig', %w{/all}) }
61
+ subject(:output) { @winrm.cmd('ipconfig', %w(/all)) }
61
62
  it { should have_exit_code 0 }
62
- it { should have_stdout_match /Windows IP Configuration/ }
63
+ it { should have_stdout_match(/Windows IP Configuration/) }
63
64
  it { should have_no_stderr }
64
65
  end
65
66
 
@@ -67,20 +68,20 @@ describe 'winrm client cmd', :integration => true do
67
68
  subject(:output) { @winrm.cmd('dir /z') }
68
69
  it { should have_exit_code 1 }
69
70
  it { should have_no_stdout }
70
- it { should have_stderr_match /Invalid switch/ }
71
+ it { should have_stderr_match(/Invalid switch/) }
71
72
  end
72
73
 
73
74
  describe 'ipconfig && echo error 1>&2' do
74
75
  subject(:output) { @winrm.cmd('ipconfig && echo error 1>&2') }
75
76
  it { should have_exit_code 0 }
76
- it { should have_stdout_match /Windows IP Configuration/ }
77
- it { should have_stderr_match /error/ }
77
+ it { should have_stdout_match(/Windows IP Configuration/) }
78
+ it { should have_stderr_match(/error/) }
78
79
  end
79
80
 
80
81
  describe 'ipconfig with a block' do
81
82
  subject(:stdout) do
82
83
  outvar = ''
83
- @winrm.cmd('ipconfig') do |stdout, stderr|
84
+ @winrm.cmd('ipconfig') do |stdout, _stderr |
84
85
  outvar << stdout
85
86
  end
86
87
  outvar
@@ -1,7 +1,7 @@
1
- describe "Exceptions", :unit => true do
1
+ # encoding: UTF-8
2
+ describe 'Exceptions', unit: true do
2
3
  describe WinRM::WinRMAuthorizationError do
3
-
4
- let (:error) { WinRM::WinRMHTTPTransportError.new("Foo happened", 500) }
4
+ let(:error) { WinRM::WinRMHTTPTransportError.new('Foo happened', 500) }
5
5
 
6
6
  it 'adds the response code to the message' do
7
7
  expect(error.message).to eq('Foo happened (500).')
@@ -17,8 +17,7 @@ describe "Exceptions", :unit => true do
17
17
  end
18
18
 
19
19
  describe WinRM::WinRMWSManFault do
20
-
21
- let (:error) { WinRM::WinRMWSManFault.new("fault text", 42) }
20
+ let(:error) { WinRM::WinRMWSManFault.new('fault text', 42) }
22
21
 
23
22
  it 'exposes the fault text as an attribute' do
24
23
  expect(error.fault_description).to eq('fault text')
@@ -34,15 +33,14 @@ describe "Exceptions", :unit => true do
34
33
  end
35
34
 
36
35
  describe WinRM::WinRMWMIError do
37
-
38
- let (:error) { WinRM::WinRMWMIError.new("message text", 77777) }
36
+ let(:error) { WinRM::WinRMWMIError.new('message text', 77_777) }
39
37
 
40
38
  it 'exposes the error text as an attribute' do
41
39
  expect(error.error).to eq('message text')
42
40
  end
43
41
 
44
42
  it 'exposes the error code as an attribute' do
45
- expect(error.error_code).to eq 77777
43
+ expect(error.error_code).to eq 77_777
46
44
  end
47
45
 
48
46
  it 'is a winrm error' do
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+ describe 'issue 59', integration: true do
3
+ before(:all) do
4
+ @winrm = winrm_connection
5
+ end
6
+
7
+ describe 'long running script without output' do
8
+ it 'should not error' do
9
+ output = @winrm.powershell('sleep 60; Write-Host "Hello"')
10
+ expect(output).to have_exit_code 0
11
+ expect(output).to have_stdout_match(/Hello/)
12
+ expect(output).to have_no_stderr
13
+ end
14
+ end
15
+ end
data/spec/matchers.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # encoding: UTF-8
1
2
  require 'rspec/expectations'
2
3
 
4
+ # rspec matchers
3
5
  module WinRMSpecs
4
6
  def self.stdout(output)
5
7
  output[:data].collect do |i|
@@ -16,7 +18,7 @@ end
16
18
 
17
19
  RSpec::Matchers.define :have_stdout_match do |expected_stdout|
18
20
  match do |actual_output|
19
- expected_stdout.match(WinRMSpecs.stdout(actual_output)) != nil
21
+ !expected_stdout.match(WinRMSpecs.stdout(actual_output)).nil?
20
22
  end
21
23
  failure_message do |actual_output|
22
24
  "expected that '#{WinRMSpecs.stdout(actual_output)}' would match #{expected_stdout}"
@@ -25,7 +27,7 @@ end
25
27
 
26
28
  RSpec::Matchers.define :have_stderr_match do |expected_stderr|
27
29
  match do |actual_output|
28
- expected_stderr.match(WinRMSpecs.stderr(actual_output)) != nil
30
+ !expected_stderr.match(WinRMSpecs.stderr(actual_output)).nil?
29
31
  end
30
32
  failure_message do |actual_output|
31
33
  "expected that '#{WinRMSpecs.stderr(actual_output)}' would match #{expected_stderr}"
@@ -64,7 +66,7 @@ end
64
66
  RSpec::Matchers.define :be_a_uid do
65
67
  match do |actual|
66
68
  # WinRM1.1 returns uuid's prefixed with 'uuid:' where as later versions do not
67
- actual != nil && actual.match(/^(uuid:)*\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/)
69
+ !actual.nil? && actual.match(/^(uuid:)*\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/)
68
70
  end
69
71
  failure_message do |actual|
70
72
  "expected a uid, but got '#{actual}'"
data/spec/output_spec.rb CHANGED
@@ -1,106 +1,110 @@
1
- describe WinRM::Output, :unit => true do
2
- subject { WinRM::Output.new() }
1
+ # encoding: UTF-8
2
+ describe WinRM::Output, unit: true do
3
+ subject { WinRM::Output.new }
3
4
 
4
- context "when there is no output" do
5
- describe "#stdout" do
6
- it "is empty" do
5
+ context 'when there is no output' do
6
+ describe '#stdout' do
7
+ it 'is empty' do
7
8
  expect(subject.stdout).to be_empty
8
9
  end
9
10
  end
10
11
 
11
- describe "#stderr" do
12
- it "is empty" do
12
+ describe '#stderr' do
13
+ it 'is empty' do
13
14
  expect(subject.stderr).to be_empty
14
15
  end
15
16
  end
16
17
 
17
- describe "#output" do
18
- it "is empty" do
18
+ describe '#output' do
19
+ it 'is empty' do
19
20
  expect(subject.output).to be_empty
20
21
  end
21
22
  end
22
23
  end
23
24
 
24
- context "when there is only one line" do
25
- describe "#stdout" do
26
- it "is equal to that line" do
27
- subject[:data] << { :stdout => "foo" }
28
- expect(subject.stdout).to eq("foo")
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')
29
30
  end
30
31
  end
31
32
 
32
- describe "#stderr" do
33
- it "is equal to that line" do
34
- subject[:data] << { :stderr => "foo" }
35
- expect(subject.stderr).to eq("foo")
33
+ describe '#stderr' do
34
+ it 'is equal to that line' do
35
+ subject[:data] << { stderr: 'foo' }
36
+ expect(subject.stderr).to eq('foo')
36
37
  end
37
38
  end
38
39
 
39
- describe "#output" do
40
- it "is equal to stdout" do
41
- subject[:data] << { :stdout => "foo" }
42
- expect(subject.output).to eq("foo")
40
+ describe '#output' do
41
+ it 'is equal to stdout' do
42
+ subject[:data] << { stdout: 'foo' }
43
+ expect(subject.output).to eq('foo')
43
44
  end
44
45
 
45
- it "is equal to stderr" do
46
- subject[:data] << { :stderr => "foo" }
47
- expect(subject.output).to eq("foo")
46
+ it 'is equal to stderr' do
47
+ subject[:data] << { stderr: 'foo' }
48
+ expect(subject.output).to eq('foo')
48
49
  end
49
50
  end
50
51
  end
51
52
 
52
- context "when there is one line of each type" do
53
+ context 'when there is one line of each type' do
53
54
  before(:each) do
54
- subject[:data] << { :stdout => "foo" }
55
- subject[:data] << { :stderr => "bar" }
55
+ subject[:data] << { stdout: 'foo' }
56
+ subject[:data] << { stderr: 'bar' }
56
57
  end
57
58
 
58
- describe "#stdout" do
59
- it "is equal to that line" do
60
- expect(subject.stdout).to eq("foo")
59
+ describe '#stdout' do
60
+ it 'is equal to that line' do
61
+ expect(subject.stdout).to eq('foo')
61
62
  end
62
63
  end
63
64
 
64
- describe "#stderr" do
65
- it "is equal to that line" do
66
- expect(subject.stderr).to eq("bar")
65
+ describe '#stderr' do
66
+ it 'is equal to that line' do
67
+ expect(subject.stderr).to eq('bar')
67
68
  end
68
69
  end
69
70
 
70
- describe "#output" do
71
- it "is equal to stdout + stderr" do
72
- expect(subject.output).to eq("foobar")
71
+ describe '#output' do
72
+ it 'is equal to stdout + stderr' do
73
+ expect(subject.output).to eq('foobar')
73
74
  end
74
75
  end
75
76
  end
76
77
 
77
- context "when there are multiple lines" do
78
+ context 'when there are multiple lines' do
78
79
  before(:each) do
79
- subject[:data] << { :stdout => "I can have a newline\nanywhere, " }
80
- subject[:data] << { :stderr => "I can also have stderr" }
81
- subject[:data] << { :stdout => "or stdout", :stderr => " and stderr" }
82
- subject[:data] << { }
83
- subject[:data] << { :stdout => " or nothing! (above)" }
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)' }
84
85
  end
85
86
 
86
- describe "#stdout" do
87
- it "is equal to that line" do
88
- expect(subject.stdout).to eq("I can have a newline\nanywhere, or stdout or nothing! (above)")
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)')
89
91
  end
90
92
  end
91
93
 
92
- describe "#stderr" do
93
- it "is equal to that line" do
94
- expect(subject.stderr).to eq("I can also have stderr and stderr")
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')
95
97
  end
96
98
  end
97
99
 
98
- describe "#output" do
99
- it "is equal to stdout + stderr" do
100
- expect(subject.output).to eq("I can have a newline\nanywhere, I can also have stderror stdout and stderr or nothing! (above)")
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)')
101
105
  end
102
106
  end
103
107
  end
104
108
 
105
- pending "parse CLIXML errors and convert to Strings and/or Exceptions"
109
+ pending 'parse CLIXML errors and convert to Strings and/or Exceptions'
106
110
  end
@@ -1,25 +1,26 @@
1
- describe 'winrm client powershell', :integration => true do
1
+ # encoding: UTF-8
2
+ describe 'winrm client powershell', integration: true do
2
3
  before(:all) do
3
4
  @winrm = winrm_connection
4
5
  end
5
6
 
6
7
  describe 'empty string' do
7
8
  subject(:output) { @winrm.powershell('') }
8
- it { should have_exit_code 4294770688 }
9
- it { should have_stderr_match /Cannot process the command because of a missing parameter/ }
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/) }
10
11
  end
11
12
 
12
13
  describe 'ipconfig' do
13
14
  subject(:output) { @winrm.powershell('ipconfig') }
14
15
  it { should have_exit_code 0 }
15
- it { should have_stdout_match /Windows IP Configuration/ }
16
+ it { should have_stdout_match(/Windows IP Configuration/) }
16
17
  it { should have_no_stderr }
17
18
  end
18
19
 
19
20
  describe 'echo \'hello world\' using apostrophes' do
20
21
  subject(:output) { @winrm.powershell("echo 'hello world'") }
21
22
  it { should have_exit_code 0 }
22
- it { should have_stdout_match /hello world/ }
23
+ it { should have_stdout_match(/hello world/) }
23
24
  it { should have_no_stderr }
24
25
  end
25
26
 
@@ -27,8 +28,6 @@ describe 'winrm client powershell', :integration => true do
27
28
  subject(:output) { @winrm.powershell('dir /z') }
28
29
  it { should have_exit_code 1 }
29
30
  it { should have_no_stdout }
30
- #TODO Better
31
- #it { should have_stderr_match /Invalid switch/ }
32
31
  end
33
32
 
34
33
  describe 'Math area calculation' do
@@ -41,14 +40,14 @@ describe 'winrm client powershell', :integration => true do
41
40
  )
42
41
  end
43
42
  it { should have_exit_code 0 }
44
- it { should have_stdout_match /49.9648722805149/ }
43
+ it { should have_stdout_match(/49.9648722805149/) }
45
44
  it { should have_no_stderr }
46
45
  end
47
46
 
48
47
  describe 'ipconfig with a block' do
49
48
  subject(:stdout) do
50
49
  outvar = ''
51
- @winrm.powershell('ipconfig') do |stdout, stderr|
50
+ @winrm.powershell('ipconfig') do |stdout, _stderr|
52
51
  outvar << stdout
53
52
  end
54
53
  outvar
@@ -63,7 +62,7 @@ describe 'winrm client powershell', :integration => true do
63
62
  $host.ui.WriteErrorLine(', world!')
64
63
  eos
65
64
 
66
- @captured_stdout, @captured_stderr = "", ""
65
+ @captured_stdout, @captured_stderr = '', ''
67
66
  @winrm.powershell(script) do |stdout, stderr|
68
67
  @captured_stdout << stdout if stdout
69
68
  @captured_stderr << stderr if stderr
@@ -79,16 +78,19 @@ describe 'winrm client powershell', :integration => true do
79
78
  # TODO: Option to parse CLIXML
80
79
  # expect(output.output).to eq("Hello\n, world!")
81
80
  # expect(output.stderr).to eq(", world!")
82
- expect(output.stderr).to eq("#< CLIXML\r\n<Objs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\"><S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
81
+ expect(output.stderr).to eq(
82
+ "#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
83
+ "xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
84
+ "<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
83
85
  expect(output.stderr).to eq(@captured_stderr)
84
86
  end
85
87
 
86
88
  it 'should have output' do
87
89
  # TODO: Option to parse CLIXML
88
90
  # expect(output.output).to eq("Hello\n, world!")
89
- expect(output.output).to eq("Hello\n#< CLIXML\r\n<Objs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\"><S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
91
+ expect(output.output).to eq("Hello\n#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
92
+ "xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
93
+ "<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
90
94
  end
91
95
  end
92
96
  end
93
-
94
-
@@ -1,15 +1,15 @@
1
+ # encoding: UTF-8
1
2
  require 'winrm/http/response_handler'
2
3
 
3
- describe 'response handler', :unit => true do
4
-
5
- ['v1', 'v2'].each do |winrm_version|
4
+ describe 'response handler', unit: true do
5
+ %w(v1, v2).each do |winrm_version|
6
6
  let(:soap_fault) { File.read("spec/stubs/responses/soap_fault_#{winrm_version}.xml") }
7
7
  let(:open_shell) { File.read("spec/stubs/responses/open_shell_#{winrm_version}.xml") }
8
8
 
9
9
  describe "successful 200 #{winrm_version} response" do
10
10
  it 'returns an xml doc' do
11
11
  handler = WinRM::ResponseHandler.new(open_shell, 200)
12
- xml_doc = handler.parse_to_xml()
12
+ xml_doc = handler.parse_to_xml
13
13
  expect(xml_doc).to be_instance_of(REXML::Document)
14
14
  expect(xml_doc.to_s).to eq(REXML::Document.new(open_shell).to_s)
15
15
  end
@@ -18,14 +18,14 @@ describe 'response handler', :unit => true do
18
18
  describe "failed 500 #{winrm_version} response" do
19
19
  it 'raises a WinRMHTTPTransportError' do
20
20
  handler = WinRM::ResponseHandler.new('', 500)
21
- expect { handler.parse_to_xml()}.to raise_error(WinRM::WinRMHTTPTransportError)
21
+ expect { handler.parse_to_xml }.to raise_error(WinRM::WinRMHTTPTransportError)
22
22
  end
23
23
  end
24
24
 
25
25
  describe "failed 401 #{winrm_version} response" do
26
26
  it 'raises a WinRMAuthorizationError' do
27
27
  handler = WinRM::ResponseHandler.new('', 401)
28
- expect { handler.parse_to_xml()}.to raise_error(WinRM::WinRMAuthorizationError)
28
+ expect { handler.parse_to_xml }.to raise_error(WinRM::WinRMAuthorizationError)
29
29
  end
30
30
  end
31
31
 
@@ -33,22 +33,23 @@ describe 'response handler', :unit => true do
33
33
  it 'raises a WinRMWSManFault' do
34
34
  handler = WinRM::ResponseHandler.new(soap_fault, 400)
35
35
  begin
36
- handler.parse_to_xml()
36
+ handler.parse_to_xml
37
37
  rescue WinRM::WinRMWSManFault => e
38
38
  expect(e.fault_code).to eq('2150858778')
39
- expect(e.fault_description).to include('The specified class does not exist in the given namespace')
39
+ expect(e.fault_description).to include(
40
+ 'The specified class does not exist in the given namespace')
40
41
  end
41
42
  end
42
43
  end
43
44
  end
44
45
 
45
- describe "failed 500 WMI error response" do
46
- let(:wmi_error) { File.read("spec/stubs/responses/wmi_error_v2.xml") }
46
+ describe 'failed 500 WMI error response' do
47
+ let(:wmi_error) { File.read('spec/stubs/responses/wmi_error_v2.xml') }
47
48
 
48
49
  it 'raises a WinRMWMIError' do
49
50
  handler = WinRM::ResponseHandler.new(wmi_error, 500)
50
51
  begin
51
- handler.parse_to_xml()
52
+ handler.parse_to_xml
52
53
  rescue WinRM::WinRMWMIError => e
53
54
  expect(e.error_code).to eq('2150859173')
54
55
  expect(e.error).to include('The WS-Management service cannot process the request.')