knife-windows 1.4.0 → 1.4.1

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.
@@ -0,0 +1,24 @@
1
+ module Dummy
2
+ class WinRMTransport
3
+ attr_reader :httpcli
4
+
5
+ def initialize
6
+ @httpcli = HTTPClient.new
7
+ end
8
+ end
9
+
10
+ class WinRMService
11
+ attr_reader :xfer
12
+
13
+ def initialize
14
+ @xfer = WinRMTransport.new
15
+ end
16
+
17
+ def set_timeout(timeout); end
18
+ def open_shell; end
19
+ def run_command; end
20
+ def get_command_output; end
21
+ def cleanup_command; end
22
+ def close_shell; end
23
+ end
24
+ end
@@ -28,6 +28,7 @@ describe Chef::Knife::BootstrapWindowsWinrm do
28
28
  allow(bootstrap).to receive(:validate_options!).and_return(nil)
29
29
  allow(bootstrap).to receive(:sleep).and_return(10)
30
30
  allow(Chef::Knife::WinrmSession).to receive(:new).and_return(session)
31
+ allow(File).to receive(:exist?).with(anything).and_call_original
31
32
  allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(true)
32
33
  end
33
34
 
@@ -17,12 +17,13 @@
17
17
  #
18
18
 
19
19
  require 'spec_helper'
20
+ require 'dummy_winrm_service'
20
21
 
21
22
  Chef::Knife::Winrm.load_deps
22
23
 
23
24
 
24
25
  describe Chef::Knife::WinrmSession do
25
- let(:winrm_service) { double('WinRMWebService') }
26
+ let(:winrm_service) { Dummy::WinRMService.new }
26
27
  let(:options) { { transport: :plaintext } }
27
28
 
28
29
  before do
@@ -40,6 +41,7 @@ describe Chef::Knife::WinrmSession do
40
41
  describe "#initialize" do
41
42
  context "when a proxy is configured" do
42
43
  let(:proxy_uri) { 'blah.com' }
44
+ let(:ssl_policy) { double('DefaultSSLPolicy', :set_custom_certs => nil) }
43
45
 
44
46
  before do
45
47
  Chef::Config[:http_proxy] = proxy_uri
@@ -49,6 +51,15 @@ describe Chef::Knife::WinrmSession do
49
51
  subject
50
52
  expect(ENV['HTTP_PROXY']).to eq("http://#{proxy_uri}")
51
53
  end
54
+
55
+ it "sets the ssl policy on the winrm client" do
56
+ expect(Chef::HTTP::DefaultSSLPolicy).to receive(:new)
57
+ .with(winrm_service.xfer.httpcli.ssl_config)
58
+ .and_return(ssl_policy)
59
+ expect(ssl_policy).to receive(:set_custom_certs)
60
+ subject
61
+ end
62
+
52
63
  end
53
64
  end
54
65
 
@@ -17,6 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'spec_helper'
20
+ require 'dummy_winrm_service'
20
21
 
21
22
  Chef::Knife::Winrm.load_deps
22
23
 
@@ -95,11 +96,7 @@ describe Chef::Knife::Winrm do
95
96
  ]
96
97
  end
97
98
  let(:winrm_session) { double('winrm_session') }
98
- let(:winrm_service) { double('WinRMWebService') }
99
-
100
- before do
101
- allow(winrm_service).to receive(:set_timeout)
102
- end
99
+ let(:winrm_service) { Dummy::WinRMService.new }
103
100
 
104
101
  subject { Chef::Knife::Winrm.new(knife_args) }
105
102
 
@@ -185,11 +182,6 @@ describe Chef::Knife::Winrm do
185
182
  end
186
183
 
187
184
  context "when configuring the WinRM transport" do
188
- before(:all) do
189
- @winrm_session = Object.new
190
- @winrm_session.define_singleton_method(:set_timeout){|timeout| ""}
191
- end
192
-
193
185
  context "kerberos option is set" do
194
186
  let(:winrm_command_http) { Chef::Knife::Winrm.new([
195
187
  '-m', 'localhost',
@@ -201,7 +193,7 @@ describe Chef::Knife::Winrm do
201
193
  ]) }
202
194
 
203
195
  it "sets the transport to kerberos" do
204
- expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', :kerberos, anything).and_return(@winrm_session)
196
+ expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', :kerberos, anything).and_return(winrm_service)
205
197
  winrm_command_http.configure_chef
206
198
  winrm_command_http.configure_session
207
199
  end
@@ -218,7 +210,7 @@ describe Chef::Knife::Winrm do
218
210
 
219
211
  it "sets the transport to plaintext" do
220
212
  winrm_command_http.config[:kerberos_realm] = nil
221
- expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', :plaintext, anything).and_return(@winrm_session)
213
+ expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', :plaintext, anything).and_return(winrm_service)
222
214
  winrm_command_http.configure_chef
223
215
  winrm_command_http.configure_session
224
216
  end
@@ -248,15 +240,15 @@ describe Chef::Knife::Winrm do
248
240
 
249
241
  it "defaults to the http uri scheme" do
250
242
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :plaintext)).and_call_original
251
- expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', anything, anything).and_return(@winrm_session)
243
+ expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', anything, anything).and_return(winrm_service)
252
244
  winrm_command_http.configure_chef
253
245
  winrm_command_http.configure_session
254
246
  end
255
247
 
256
248
  it "sets the operation timeout and verifes default" do
257
249
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :plaintext)).and_call_original
258
- expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', anything, anything).and_return(@winrm_session)
259
- expect(@winrm_session).to receive(:set_timeout).with(1800)
250
+ expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', anything, anything).and_return(winrm_service)
251
+ expect(winrm_service).to receive(:set_timeout).with(1800)
260
252
  winrm_command_http.configure_chef
261
253
  winrm_command_http.configure_session
262
254
  end
@@ -264,7 +256,7 @@ describe Chef::Knife::Winrm do
264
256
  it "sets the user specified winrm port" do
265
257
  Chef::Config[:knife] = {winrm_port: "5988"}
266
258
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :plaintext)).and_call_original
267
- expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5988/wsman', anything, anything).and_return(@winrm_session)
259
+ expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5988/wsman', anything, anything).and_return(winrm_service)
268
260
  winrm_command_http.configure_chef
269
261
  winrm_command_http.configure_session
270
262
  end
@@ -273,8 +265,8 @@ describe Chef::Knife::Winrm do
273
265
 
274
266
  it "sets operation timeout and verify 10 Minute timeout" do
275
267
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :plaintext)).and_call_original
276
- expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', anything, anything).and_return(@winrm_session)
277
- expect(@winrm_session).to receive(:set_timeout).with(600)
268
+ expect(WinRM::WinRMWebService).to receive(:new).with('http://localhost:5985/wsman', anything, anything).and_return(winrm_service)
269
+ expect(winrm_service).to receive(:set_timeout).with(600)
278
270
  winrm_command_timeout.configure_chef
279
271
  winrm_command_timeout.configure_session
280
272
  end
@@ -284,7 +276,7 @@ describe Chef::Knife::Winrm do
284
276
  it "uses the https uri scheme if the ssl transport is specified" do
285
277
  Chef::Config[:knife] = {:winrm_transport => 'ssl'}
286
278
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :ssl)).and_call_original
287
- expect(WinRM::WinRMWebService).to receive(:new).with('https://localhost:5986/wsman', anything, anything).and_return(@winrm_session)
279
+ expect(WinRM::WinRMWebService).to receive(:new).with('https://localhost:5986/wsman', anything, anything).and_return(winrm_service)
288
280
  winrm_command_https.configure_chef
289
281
  winrm_command_https.configure_session
290
282
  end
@@ -292,14 +284,14 @@ describe Chef::Knife::Winrm do
292
284
  it "uses the winrm port '5986' by default for ssl transport" do
293
285
  Chef::Config[:knife] = {:winrm_transport => 'ssl'}
294
286
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :ssl)).and_call_original
295
- expect(WinRM::WinRMWebService).to receive(:new).with('https://localhost:5986/wsman', anything, anything).and_return(@winrm_session)
287
+ expect(WinRM::WinRMWebService).to receive(:new).with('https://localhost:5986/wsman', anything, anything).and_return(winrm_service)
296
288
  winrm_command_https.configure_chef
297
289
  winrm_command_https.configure_session
298
290
  end
299
291
 
300
292
  it "defaults to validating the server when the ssl transport is used" do
301
293
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :ssl)).and_call_original
302
- expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => false)).and_return(@winrm_session)
294
+ expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => false)).and_return(winrm_service)
303
295
  winrm_command_https.configure_chef
304
296
  winrm_command_https.configure_session
305
297
  end
@@ -308,7 +300,7 @@ describe Chef::Knife::Winrm do
308
300
 
309
301
  it "validates the server when the ssl transport is used and the :winrm_ssl_verify_mode option is not configured to :verify_none" do
310
302
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :ssl)).and_call_original
311
- expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => false)).and_return(@winrm_session)
303
+ expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => false)).and_return(winrm_service)
312
304
  winrm_command_verify_peer.configure_chef
313
305
  winrm_command_verify_peer.configure_session
314
306
  end
@@ -320,14 +312,14 @@ describe Chef::Knife::Winrm do
320
312
 
321
313
  it "does not validate the server when the ssl transport is used and the :winrm_ssl_verify_mode option is set to :verify_none" do
322
314
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :ssl)).and_call_original
323
- expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => true)).and_return(@winrm_session)
315
+ expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => true)).and_return(winrm_service)
324
316
  subject.configure_chef
325
317
  subject.configure_session
326
318
  end
327
319
 
328
320
  it "prints warning output when the :winrm_ssl_verify_mode set to :verify_none to disable server validation" do
329
321
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :ssl)).and_call_original
330
- expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => true)).and_return(@winrm_session)
322
+ expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => true)).and_return(winrm_service)
331
323
  expect(subject).to receive(:warn_no_ssl_peer_verification)
332
324
 
333
325
  subject.configure_chef
@@ -352,7 +344,7 @@ describe Chef::Knife::Winrm do
352
344
 
353
345
  it "validates the server when the ssl transport is used and the :ca_trust_file option is specified even if the :winrm_ssl_verify_mode option is set to :verify_none" do
354
346
  expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(:transport => :ssl)).and_call_original
355
- expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => false)).and_return(@winrm_session)
347
+ expect(WinRM::WinRMWebService).to receive(:new).with(anything, anything, hash_including(:no_ssl_peer_verification => false)).and_return(winrm_service)
356
348
  winrm_command_ca_trust.configure_chef
357
349
  winrm_command_ca_trust.configure_session
358
350
  end
@@ -20,51 +20,35 @@ require 'spec_helper'
20
20
 
21
21
  describe Chef::Knife::WsmanTest do
22
22
  let(:http_client_mock) { HTTPClient.new }
23
+ let(:ssl_policy) { double('DefaultSSLPolicy', :set_custom_certs => nil) }
23
24
 
24
25
  before(:all) do
25
26
  Chef::Config.reset
26
27
  end
27
28
 
28
29
  before(:each) do
30
+ response_body = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header/><s:Body><wsmid:IdentifyResponse xmlns:wsmid="http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd"><wsmid:ProtocolVersion>http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd</wsmid:ProtocolVersion><wsmid:ProductVendor>Microsoft Corporation</wsmid:ProductVendor><wsmid:ProductVersion>OS: 0.0.0 SP: 0.0 Stack: 2.0</wsmid:ProductVersion></wsmid:IdentifyResponse></s:Body></s:Envelope>'
31
+ http_response_mock = HTTP::Message.new_response(response_body)
32
+ allow(http_client_mock).to receive(:post).and_return(http_response_mock)
29
33
  allow(HTTPClient).to receive(:new).and_return(http_client_mock)
30
34
  subject.config[:verbosity] = 0
31
35
  allow(subject.ui).to receive(:ask).and_return('prompted_password')
36
+ allow(Chef::HTTP::DefaultSSLPolicy).to receive(:new)
37
+ .with(http_client_mock.ssl_config)
38
+ .and_return(ssl_policy)
32
39
  end
33
40
 
34
41
  subject { Chef::Knife::WsmanTest.new(['-m', 'localhost']) }
35
42
 
36
- context 'when testing the WSMAN endpoint' do
37
- context 'and the service does not respond' do
38
- error_message = 'A connection attempt failed because the connected party did not properly respond after a period of time.'
39
-
40
- before(:each) do
41
- allow(http_client_mock).to receive(:post).and_raise(Exception.new(error_message))
42
- end
43
-
44
- it 'exits with a status code of 1' do
45
- expect(subject).to receive(:exit).with(1)
46
- subject.run
47
- end
48
-
49
- it 'writes a warning message for each node it fails to connect to' do
50
- expect(subject.ui).to receive(:warn)
51
- expect(subject).to receive(:exit).with(1)
52
- subject.run
53
- end
54
-
55
- it 'writes an error message if it fails to connect to any nodes' do
56
- expect(subject.ui).to receive(:error)
57
- expect(subject).to receive(:exit).with(1)
58
- subject.run
59
- end
60
- end
43
+ it 'sets the ssl policy' do
44
+ expect(ssl_policy).to receive(:set_custom_certs).twice
45
+ subject.run
46
+ end
61
47
 
48
+ context 'when testing the WSMAN endpoint' do
62
49
  context 'and the service responds' do
63
50
  context 'successfully' do
64
51
  it 'writes a message about a successful connection' do
65
- response_body = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header/><s:Body><wsmid:IdentifyResponse xmlns:wsmid="http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd"><wsmid:ProtocolVersion>http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd</wsmid:ProtocolVersion><wsmid:ProductVendor>Microsoft Corporation</wsmid:ProductVendor><wsmid:ProductVersion>OS: 0.0.0 SP: 0.0 Stack: 2.0</wsmid:ProductVersion></wsmid:IdentifyResponse></s:Body></s:Envelope>'
66
- http_response_mock = HTTP::Message.new_response(response_body)
67
- allow(http_client_mock).to receive(:post).and_return(http_response_mock)
68
52
  expect(subject.ui).to receive(:msg)
69
53
  subject.run
70
54
  end
@@ -94,12 +78,35 @@ describe Chef::Knife::WsmanTest do
94
78
  end
95
79
  end
96
80
  end
81
+
82
+ context 'and the service does not respond' do
83
+ error_message = 'A connection attempt failed because the connected party did not properly respond after a period of time.'
84
+
85
+ before(:each) do
86
+ allow(http_client_mock).to receive(:post).and_raise(Exception.new(error_message))
87
+ end
88
+
89
+ it 'exits with a status code of 1' do
90
+ expect(subject).to receive(:exit).with(1)
91
+ subject.run
92
+ end
93
+
94
+ it 'writes a warning message for each node it fails to connect to' do
95
+ expect(subject.ui).to receive(:warn)
96
+ expect(subject).to receive(:exit).with(1)
97
+ subject.run
98
+ end
99
+
100
+ it 'writes an error message if it fails to connect to any nodes' do
101
+ expect(subject.ui).to receive(:error)
102
+ expect(subject).to receive(:exit).with(1)
103
+ subject.run
104
+ end
105
+ end
97
106
  end
98
107
 
99
108
  context 'when not validating ssl cert' do
100
109
  before(:each) do
101
- response_body = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header/><s:Body><wsmid:IdentifyResponse xmlns:wsmid="http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd"><wsmid:ProtocolVersion>http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd</wsmid:ProtocolVersion><wsmid:ProductVendor>Microsoft Corporation</wsmid:ProductVendor><wsmid:ProductVersion>OS: 0.0.0 SP: 0.0 Stack: 2.0</wsmid:ProductVersion></wsmid:IdentifyResponse></s:Body></s:Envelope>'
102
- allow(http_client_mock).to receive(:post).and_return(HTTP::Message.new_response(response_body))
103
110
  expect(subject.ui).to receive(:msg)
104
111
  subject.config[:winrm_ssl_verify_mode] = :verify_none
105
112
  subject.config[:winrm_transport] = :ssl
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-windows
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Chisamore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: winrm
@@ -85,6 +85,7 @@ files:
85
85
  - spec/assets/win_template_rendered_without_bootstrap_install_command.txt
86
86
  - spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt
87
87
  - spec/assets/win_template_unrendered.txt
88
+ - spec/dummy_winrm_service.rb
88
89
  - spec/functional/bootstrap_download_spec.rb
89
90
  - spec/spec_helper.rb
90
91
  - spec/unit/knife/bootstrap_options_spec.rb
@@ -117,28 +118,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.4.7
121
+ rubygems_version: 2.6.3
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Plugin that adds functionality to Chef's Knife CLI for configuring/interacting
124
125
  with nodes running Microsoft Windows
125
- test_files:
126
- - features/knife_help.feature
127
- - features/support/env.rb
128
- - spec/assets/win_template_rendered_with_bootstrap_install_command.txt
129
- - spec/assets/win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt
130
- - spec/assets/win_template_rendered_without_bootstrap_install_command.txt
131
- - spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt
132
- - spec/assets/win_template_unrendered.txt
133
- - spec/functional/bootstrap_download_spec.rb
134
- - spec/spec_helper.rb
135
- - spec/unit/knife/bootstrap_options_spec.rb
136
- - spec/unit/knife/bootstrap_template_spec.rb
137
- - spec/unit/knife/bootstrap_windows_winrm_spec.rb
138
- - spec/unit/knife/core/windows_bootstrap_context_spec.rb
139
- - spec/unit/knife/windows_cert_generate_spec.rb
140
- - spec/unit/knife/windows_cert_install_spec.rb
141
- - spec/unit/knife/windows_listener_create_spec.rb
142
- - spec/unit/knife/winrm_session_spec.rb
143
- - spec/unit/knife/winrm_spec.rb
144
- - spec/unit/knife/wsman_test_spec.rb
126
+ test_files: []