winrm 2.2.3 → 2.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -1
  3. data/bin/rwinrm +90 -97
  4. data/lib/winrm/connection.rb +84 -86
  5. data/lib/winrm/connection_opts.rb +90 -91
  6. data/lib/winrm/exceptions.rb +14 -2
  7. data/lib/winrm/http/response_handler.rb +127 -96
  8. data/lib/winrm/http/transport.rb +462 -427
  9. data/lib/winrm/http/transport_factory.rb +1 -5
  10. data/lib/winrm/output.rb +1 -2
  11. data/lib/winrm/psrp/fragment.rb +0 -2
  12. data/lib/winrm/psrp/message.rb +128 -130
  13. data/lib/winrm/psrp/message_data/base.rb +0 -2
  14. data/lib/winrm/psrp/message_data/error_record.rb +2 -2
  15. data/lib/winrm/psrp/message_data/pipeline_host_call.rb +0 -2
  16. data/lib/winrm/psrp/message_data/pipeline_output.rb +48 -54
  17. data/lib/winrm/psrp/message_data/pipeline_state.rb +0 -2
  18. data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +0 -2
  19. data/lib/winrm/psrp/message_data/runspacepool_state.rb +0 -2
  20. data/lib/winrm/psrp/message_data/session_capability.rb +0 -2
  21. data/lib/winrm/psrp/message_data.rb +0 -2
  22. data/lib/winrm/psrp/message_defragmenter.rb +2 -2
  23. data/lib/winrm/psrp/message_factory.rb +16 -5
  24. data/lib/winrm/psrp/message_fragmenter.rb +1 -3
  25. data/lib/winrm/psrp/powershell_output_decoder.rb +142 -144
  26. data/lib/winrm/psrp/receive_response_reader.rb +3 -5
  27. data/lib/winrm/psrp/uuid.rb +1 -2
  28. data/lib/winrm/shells/base.rb +7 -4
  29. data/lib/winrm/shells/cmd.rb +63 -65
  30. data/lib/winrm/shells/power_shell.rb +207 -202
  31. data/lib/winrm/shells/retryable.rb +44 -45
  32. data/lib/winrm/shells/shell_factory.rb +0 -2
  33. data/lib/winrm/version.rb +1 -3
  34. data/lib/winrm/wsmv/base.rb +0 -2
  35. data/lib/winrm/wsmv/cleanup_command.rb +1 -2
  36. data/lib/winrm/wsmv/close_shell.rb +1 -2
  37. data/lib/winrm/wsmv/command.rb +2 -3
  38. data/lib/winrm/wsmv/command_output.rb +2 -3
  39. data/lib/winrm/wsmv/command_output_decoder.rb +1 -2
  40. data/lib/winrm/wsmv/configuration.rb +0 -2
  41. data/lib/winrm/wsmv/create_pipeline.rb +0 -2
  42. data/lib/winrm/wsmv/create_shell.rb +2 -6
  43. data/lib/winrm/wsmv/header.rb +213 -215
  44. data/lib/winrm/wsmv/init_runspace_pool.rb +96 -95
  45. data/lib/winrm/wsmv/iso8601_duration.rb +0 -2
  46. data/lib/winrm/wsmv/keep_alive.rb +0 -2
  47. data/lib/winrm/wsmv/receive_response_reader.rb +128 -126
  48. data/lib/winrm/wsmv/send_data.rb +0 -2
  49. data/lib/winrm/wsmv/soap.rb +0 -2
  50. data/lib/winrm/wsmv/wql_pull.rb +54 -56
  51. data/lib/winrm/wsmv/wql_query.rb +98 -99
  52. data/lib/winrm/wsmv/write_stdin.rb +0 -2
  53. data/lib/winrm.rb +3 -5
  54. metadata +81 -135
  55. data/.gitignore +0 -10
  56. data/.rubocop.yml +0 -26
  57. data/.travis.yml +0 -11
  58. data/Gemfile +0 -3
  59. data/Rakefile +0 -34
  60. data/Vagrantfile +0 -6
  61. data/WinrmAppveyor.psm1 +0 -32
  62. data/appveyor.yml +0 -51
  63. data/changelog.md +0 -128
  64. data/preamble +0 -17
  65. data/tests/integration/auth_timeout_spec.rb +0 -18
  66. data/tests/integration/cmd_spec.rb +0 -131
  67. data/tests/integration/config-example.yml +0 -16
  68. data/tests/integration/issue_59_spec.rb +0 -26
  69. data/tests/integration/powershell_spec.rb +0 -165
  70. data/tests/integration/spec_helper.rb +0 -65
  71. data/tests/integration/transport_spec.rb +0 -99
  72. data/tests/integration/wql_spec.rb +0 -34
  73. data/tests/matchers.rb +0 -60
  74. data/tests/spec/configuration_spec.rb +0 -184
  75. data/tests/spec/connection_spec.rb +0 -39
  76. data/tests/spec/exception_spec.rb +0 -50
  77. data/tests/spec/http/transport_factory_spec.rb +0 -68
  78. data/tests/spec/http/transport_spec.rb +0 -44
  79. data/tests/spec/output_spec.rb +0 -127
  80. data/tests/spec/psrp/fragment_spec.rb +0 -62
  81. data/tests/spec/psrp/message_data/base_spec.rb +0 -13
  82. data/tests/spec/psrp/message_data/error_record_spec.rb +0 -41
  83. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -25
  84. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -32
  85. data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -40
  86. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -25
  87. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -16
  88. data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -30
  89. data/tests/spec/psrp/message_data_spec.rb +0 -35
  90. data/tests/spec/psrp/message_defragmenter_spec.rb +0 -47
  91. data/tests/spec/psrp/message_fragmenter_spec.rb +0 -105
  92. data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -100
  93. data/tests/spec/psrp/psrp_message_spec.rb +0 -70
  94. data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -172
  95. data/tests/spec/psrp/uuid_spec.rb +0 -28
  96. data/tests/spec/response_handler_spec.rb +0 -61
  97. data/tests/spec/shells/base_spec.rb +0 -225
  98. data/tests/spec/shells/cmd_spec.rb +0 -75
  99. data/tests/spec/shells/powershell_spec.rb +0 -175
  100. data/tests/spec/spec_helper.rb +0 -47
  101. data/tests/spec/stubs/clixml/error_record.xml.erb +0 -84
  102. data/tests/spec/stubs/clixml/pipeline_state.xml.erb +0 -88
  103. data/tests/spec/stubs/responses/get_command_output_response.xml.erb +0 -13
  104. data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +0 -10
  105. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +0 -10
  106. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +0 -12
  107. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +0 -9
  108. data/tests/spec/stubs/responses/open_shell_v1.xml +0 -19
  109. data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
  110. data/tests/spec/stubs/responses/soap_fault_v1.xml +0 -36
  111. data/tests/spec/stubs/responses/soap_fault_v2.xml +0 -42
  112. data/tests/spec/stubs/responses/wmi_error_v2.xml +0 -41
  113. data/tests/spec/wsmv/cleanup_command_spec.rb +0 -22
  114. data/tests/spec/wsmv/close_shell_spec.rb +0 -17
  115. data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -37
  116. data/tests/spec/wsmv/command_output_spec.rb +0 -45
  117. data/tests/spec/wsmv/command_spec.rb +0 -19
  118. data/tests/spec/wsmv/configuration_spec.rb +0 -17
  119. data/tests/spec/wsmv/create_pipeline_spec.rb +0 -31
  120. data/tests/spec/wsmv/create_shell_spec.rb +0 -38
  121. data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -36
  122. data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
  123. data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -123
  124. data/tests/spec/wsmv/send_data_spec.rb +0 -30
  125. data/tests/spec/wsmv/wql_query_spec.rb +0 -13
  126. data/tests/spec/wsmv/write_stdin_spec.rb +0 -22
  127. data/winrm.gemspec +0 -47
@@ -1,96 +1,127 @@
1
- # encoding: UTF-8
2
- #
3
- # Copyright 2014 Shawn Neal <sneal@sneal.net>
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require 'rexml/document'
18
- require_relative '../wsmv/soap'
19
-
20
- module WinRM
21
- # Handles the raw WinRM HTTP response. Returns the body as an XML doc
22
- # or raises the appropriate WinRM error if the response is an error.
23
- class ResponseHandler
24
- # @param [String] The raw unparsed response body, if any
25
- # @param [Integer] The HTTP response status code
26
- def initialize(response_body, status_code)
27
- @response_body = response_body
28
- @status_code = status_code
29
- end
30
-
31
- # Processes the response from the WinRM service and either returns an XML
32
- # doc or raises an appropriate error.
33
- #
34
- # @returns [REXML::Document] The parsed response body
35
- def parse_to_xml
36
- raise_if_error
37
- response_xml
38
- end
39
-
40
- private
41
-
42
- def response_xml
43
- @response_xml ||= REXML::Document.new(@response_body)
44
- rescue REXML::ParseException => e
45
- raise WinRMHTTPTransportError.new(
46
- "Unable to parse WinRM response: #{e.message}", @status_code)
47
- end
48
-
49
- def raise_if_error
50
- return if @status_code == 200
51
- raise_if_auth_error
52
- raise_if_wsman_fault
53
- raise_if_wmi_error
54
- raise_transport_error
55
- end
56
-
57
- def raise_if_auth_error
58
- raise WinRMAuthorizationError if @status_code == 401
59
- end
60
-
61
- def raise_if_wsman_fault
62
- soap_errors = REXML::XPath.match(
63
- response_xml,
64
- "//#{WinRM::WSMV::SOAP::NS_SOAP_ENV}:Body/#{WinRM::WSMV::SOAP::NS_SOAP_ENV}:Fault/*")
65
- return if soap_errors.empty?
66
- fault = REXML::XPath.first(
67
- soap_errors,
68
- "//#{WinRM::WSMV::SOAP::NS_WSMAN_FAULT}:WSManFault")
69
- raise WinRMWSManFault.new(fault.to_s, fault.attributes['Code']) unless fault.nil?
70
- end
71
-
72
- def raise_if_wmi_error
73
- soap_errors = REXML::XPath.match(
74
- response_xml,
75
- "//#{WinRM::WSMV::SOAP::NS_SOAP_ENV}:Body/#{WinRM::WSMV::SOAP::NS_SOAP_ENV}:Fault/*")
76
- return if soap_errors.empty?
77
-
78
- error = REXML::XPath.first(
79
- soap_errors,
80
- "//#{WinRM::WSMV::SOAP::NS_WSMAN_MSFT}:MSFT_WmiError")
81
- return if error.nil?
82
-
83
- error_code = REXML::XPath.first(
84
- error,
85
- "//#{WinRM::WSMV::SOAP::NS_WSMAN_MSFT}:error_Code").text
86
- raise WinRMWMIError.new(error.to_s, error_code)
87
- end
88
-
89
- def raise_transport_error
90
- raise WinRMHTTPTransportError.new(
91
- "Bad HTTP response returned from server. Body(if present):#{@response_body}",
92
- @status_code
93
- )
94
- end
95
- end
96
- end
1
+ # Copyright 2014 Shawn Neal <sneal@sneal.net>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'rexml/document' unless defined?(REXML::Document)
16
+ require_relative '../wsmv/soap'
17
+
18
+ module WinRM
19
+ # Handles the raw WinRM HTTP response. Returns the body as an XML doc
20
+ # or raises the appropriate WinRM error if the response is an error.
21
+ class ResponseHandler
22
+ # @param [String] The raw unparsed response body, if any
23
+ # @param [Integer] The HTTP response status code
24
+ def initialize(response_body, status_code)
25
+ @response_body = response_body
26
+ @status_code = status_code
27
+ end
28
+
29
+ # Processes the response from the WinRM service and either returns an XML
30
+ # doc or raises an appropriate error.
31
+ #
32
+ # @returns [REXML::Document] The parsed response body
33
+ def parse_to_xml
34
+ raise_if_error
35
+ response_xml
36
+ end
37
+
38
+ private
39
+
40
+ def response_xml
41
+ @response_xml ||= REXML::Document.new(@response_body)
42
+ rescue REXML::ParseException => e
43
+ raise WinRMHTTPTransportError.new(
44
+ "Unable to parse WinRM response: #{e.message}", @status_code
45
+ )
46
+ end
47
+
48
+ def raise_if_error
49
+ return if @status_code == 200
50
+
51
+ raise_if_auth_error
52
+ raise_if_wsman_fault
53
+ raise_if_wmi_error
54
+ raise_if_soap_fault
55
+ raise_transport_error
56
+ end
57
+
58
+ def raise_if_auth_error
59
+ raise WinRMAuthorizationError if @status_code == 401
60
+ end
61
+
62
+ def raise_if_wsman_fault
63
+ soap_errors = REXML::XPath.match(
64
+ response_xml,
65
+ "//*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[local-name() = 'Fault']/*"
66
+ )
67
+ return if soap_errors.empty?
68
+
69
+ fault = REXML::XPath.first(
70
+ soap_errors,
71
+ "//*[local-name() = 'WSManFault']"
72
+ )
73
+ raise WinRMWSManFault.new(fault.to_s, fault.attributes['Code']) unless fault.nil?
74
+ end
75
+
76
+ def raise_if_wmi_error
77
+ soap_errors = REXML::XPath.match(
78
+ response_xml,
79
+ "//*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[local-name() = 'Fault']/*"
80
+ )
81
+ return if soap_errors.empty?
82
+
83
+ error = REXML::XPath.first(
84
+ soap_errors,
85
+ "//*[local-name() = 'MSFT_WmiError']"
86
+ )
87
+ return if error.nil?
88
+
89
+ error_code = REXML::XPath.first(
90
+ error,
91
+ "//*[local-name() = 'error_Code']"
92
+ ).text
93
+ raise WinRMWMIError.new(error.to_s, error_code)
94
+ end
95
+
96
+ def raise_if_soap_fault
97
+ soap_errors = REXML::XPath.match(
98
+ response_xml,
99
+ "//*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[local-name() = 'Fault']/*"
100
+ )
101
+ return if soap_errors.empty?
102
+
103
+ code = REXML::XPath.first(
104
+ soap_errors,
105
+ "//*[local-name() = 'Code']/*[local-name() = 'Value']/text()"
106
+ )
107
+ subcode = REXML::XPath.first(
108
+ soap_errors,
109
+ "//*[local-name() = 'Subcode']/*[local-name() = 'Value']/text()"
110
+ )
111
+ reason = REXML::XPath.first(
112
+ soap_errors,
113
+ "//*[local-name() = 'Reason']/*[local-name() = 'Text']/text()"
114
+ )
115
+
116
+ raise WinRMSoapFault.new(code, subcode, reason) unless
117
+ code.nil? && subcode.nil? && reason.nil?
118
+ end
119
+
120
+ def raise_transport_error
121
+ raise WinRMHTTPTransportError.new(
122
+ "Bad HTTP response returned from server. Body(if present):#{@response_body}",
123
+ @status_code
124
+ )
125
+ end
126
+ end
127
+ end