knife-windows 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +26 -26
  3. data/CHANGELOG.md +131 -121
  4. data/DOC_CHANGES.md +22 -14
  5. data/Gemfile +14 -13
  6. data/README.md +400 -392
  7. data/RELEASE_NOTES.md +2 -26
  8. data/appveyor.yml +39 -39
  9. data/ci.gemfile +16 -16
  10. data/knife-windows.gemspec +25 -25
  11. data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +246 -233
  12. data/lib/chef/knife/bootstrap_windows_base.rb +443 -454
  13. data/lib/chef/knife/bootstrap_windows_ssh.rb +116 -115
  14. data/lib/chef/knife/bootstrap_windows_winrm.rb +102 -95
  15. data/lib/chef/knife/core/windows_bootstrap_context.rb +378 -378
  16. data/lib/chef/knife/knife_windows_base.rb +33 -33
  17. data/lib/chef/knife/windows_cert_generate.rb +155 -155
  18. data/lib/chef/knife/windows_cert_install.rb +68 -68
  19. data/lib/chef/knife/windows_helper.rb +36 -36
  20. data/lib/chef/knife/windows_listener_create.rb +107 -107
  21. data/lib/chef/knife/winrm.rb +122 -122
  22. data/lib/chef/knife/winrm_base.rb +123 -117
  23. data/lib/chef/knife/winrm_knife_base.rb +306 -305
  24. data/lib/chef/knife/winrm_session.rb +97 -91
  25. data/lib/chef/knife/winrm_shared_options.rb +47 -47
  26. data/lib/chef/knife/wsman_endpoint.rb +44 -44
  27. data/lib/chef/knife/wsman_test.rb +118 -118
  28. data/lib/knife-windows/path_helper.rb +234 -234
  29. data/lib/knife-windows/version.rb +6 -6
  30. data/spec/assets/win_template_rendered_with_bootstrap_install_command.txt +223 -223
  31. data/spec/assets/win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt +223 -223
  32. data/spec/assets/win_template_rendered_without_bootstrap_install_command.txt +335 -335
  33. data/spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt +335 -335
  34. data/spec/dummy_winrm_connection.rb +21 -0
  35. data/spec/functional/bootstrap_download_spec.rb +236 -241
  36. data/spec/spec_helper.rb +94 -94
  37. data/spec/unit/knife/bootstrap_options_spec.rb +157 -155
  38. data/spec/unit/knife/bootstrap_template_spec.rb +98 -98
  39. data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +423 -426
  40. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +177 -177
  41. data/spec/unit/knife/windows_cert_generate_spec.rb +90 -90
  42. data/spec/unit/knife/windows_cert_install_spec.rb +51 -51
  43. data/spec/unit/knife/windows_listener_create_spec.rb +76 -76
  44. data/spec/unit/knife/winrm_session_spec.rb +71 -76
  45. data/spec/unit/knife/winrm_spec.rb +500 -508
  46. data/spec/unit/knife/wsman_test_spec.rb +209 -209
  47. metadata +16 -17
  48. data/spec/dummy_winrm_service.rb +0 -24
@@ -0,0 +1,21 @@
1
+ module Dummy
2
+ class WinRMTransport
3
+ attr_reader :httpcli
4
+
5
+
6
+ def initialize
7
+ @httpcli = HTTPClient.new
8
+ end
9
+ end
10
+
11
+ class Connection
12
+ attr_reader :transport
13
+ attr_accessor :logger
14
+
15
+ def initialize
16
+ @transport = WinRMTransport.new
17
+ end
18
+
19
+ def shell; end
20
+ end
21
+ end
@@ -1,241 +1,236 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@chef.io>)
3
- # Copyright:: Copyright (c) 2012-2016 Chef Software, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
- # implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require 'spec_helper'
21
- require 'tmpdir'
22
-
23
- # These test cases exercise the Knife::Windows knife plugin's ability
24
- # to download a bootstrap msi as part of the bootstrap process on
25
- # Windows nodes. The test modifies the Windows batch file generated
26
- # from an erb template in the plugin source in order to enable execution
27
- # of only the download functionality contained in the bootstrap template.
28
- # The test relies on knowledge of the fields of the template itself and
29
- # also on knowledge of the contents and structure of the Windows batch
30
- # file generated by the template.
31
- #
32
- # Note that if the bootstrap template changes substantially, the tests
33
- # should fail and will require re-implementation. If such changes
34
- # occur, the bootstrap code should be refactored to explicitly expose
35
- # the download funcitonality separately from other tasks to make the
36
- # test more robust.
37
- describe 'Knife::Windows::Core msi download functionality for knife Windows winrm bootstrap template' do
38
-
39
- before(:all) do
40
- # Since we're always running 32-bit Ruby, fix the
41
- # PROCESSOR_ARCHITECTURE environment variable.
42
-
43
- if ENV["PROCESSOR_ARCHITEW6432"]
44
- ENV["PROCESSOR_ARCHITECTURE"] = ENV["PROCESSOR_ARCHITEW6432"]
45
- end
46
-
47
- # All file artifacts from this test will be written into this directory
48
- @temp_directory = Dir.mktmpdir("bootstrap_test")
49
-
50
- # Location to which the download script will be modified to write
51
- # the downloaded msi
52
- @local_file_download_destination = "#{@temp_directory}/chef-client-latest.msi"
53
-
54
- source_code_directory = File.dirname(__FILE__)
55
- @template_file_path ="#{source_code_directory}/../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
56
- end
57
-
58
- after(:all) do
59
- # Clear the temp directory upon exit
60
- if Dir.exists?(@temp_directory)
61
- FileUtils::remove_dir(@temp_directory)
62
- end
63
- end
64
-
65
- describe "running on any version of the Windows OS", :windows_only do
66
- let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} }) }
67
- let(:mock_winrm) { Chef::Knife::Winrm.new }
68
- let(:arch_session_result) {
69
- o = WinRM::Output.new
70
- o[:data] << {stdout: "X86\r\n"}
71
- o
72
- }
73
- let(:arch_session_results) { [arch_session_result] }
74
-
75
- before do
76
- # Stub the bootstrap context and prevent config related sections
77
- # from being populated, i.e. chef installation and first chef
78
- # run sections
79
- allow(mock_bootstrap_context).to receive(:validation_key).and_return("echo.validation_key")
80
- allow(mock_bootstrap_context).to receive(:secret).and_return("echo.encrypted_data_bag_secret")
81
- allow(mock_bootstrap_context).to receive(:config_content).and_return("echo.config_content")
82
- allow(mock_bootstrap_context).to receive(:start_chef).and_return("echo.echo start_chef_command")
83
- allow(mock_bootstrap_context).to receive(:run_list).and_return("echo.run_list")
84
- allow(mock_bootstrap_context).to receive(:install_chef).and_return("echo.echo install_chef_command")
85
-
86
- # Change the directories where bootstrap files will be created
87
- allow(mock_bootstrap_context).to receive(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
88
- allow(mock_bootstrap_context).to receive(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
89
-
90
- # Prevent password prompt during bootstrap process
91
- allow(mock_winrm.ui).to receive(:ask).and_return(nil)
92
- allow(Chef::Knife::Winrm).to receive(:new).and_return(mock_winrm)
93
-
94
- allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(mock_bootstrap_context)
95
- Chef::Config[:knife] = {:winrm_transport => 'plaintext', :chef_node_name => 'foo.example.com', :winrm_authentication_protocol => 'negotiate'}
96
- end
97
-
98
- it "downloads the chef-client MSI from the default location during winrm bootstrap" do
99
- run_download_scenario
100
- end
101
-
102
- context "when provided a custom msi_url to fetch from" do
103
- let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
104
- { :msi_url => "file:///C:/Windows/System32/xcopy.exe" }, nil, { :knife => {} }) }
105
- it "downloads the chef-client MSI from a custom path during winrm bootstrap" do
106
- run_download_scenario
107
- end
108
- end
109
-
110
- context "when provided a custom msi_url with space in path to fetch from" do
111
- let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
112
- { :msi_url => "file:///C:/Program Files/Windows NT/Accessories/wordpad.exe" }, nil, { :knife => {} }) }
113
- it "downloads the chef-client MSI from a custom path with spaces during winrm bootstrap" do
114
- run_download_scenario
115
- end
116
- end
117
- end
118
-
119
- def download_succeeded?
120
- File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
121
- end
122
-
123
- # Remove file artifacts generated by individual test cases
124
- def clean_test_case
125
- if File.exists?(@local_file_download_destination)
126
- File.delete(@local_file_download_destination)
127
- end
128
- end
129
-
130
- def run_download_scenario
131
- clean_test_case
132
-
133
- winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
134
-
135
- if chef_gte_12?
136
- winrm_bootstrapper.client_builder = instance_double("Chef::Knife::Bootstrap::ClientBuilder", :run => nil, :client_path => nil)
137
- elsif chef_lt_12?
138
- allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(true)
139
- end
140
-
141
- expect(winrm_bootstrapper).to receive(:relay_winrm_command).with("echo %PROCESSOR_ARCHITECTURE%").and_return(arch_session_results)
142
- allow(winrm_bootstrapper).to receive(:wait_for_remote_response)
143
- allow(winrm_bootstrapper).to receive(:validate_options!)
144
- allow(winrm_bootstrapper.ui).to receive(:ask).and_return(nil)
145
- winrm_bootstrapper.config[:template_file] = @template_file_path
146
- winrm_bootstrapper.config[:run_list] = []
147
- # Execute the commands locally that would normally be executed via WinRM
148
- allow(winrm_bootstrapper).to receive(:run_command) do |command|
149
- system(command)
150
- end
151
-
152
- winrm_bootstrapper.run
153
-
154
- # Download should succeed
155
- expect(download_succeeded?).to be true
156
- end
157
- end
158
-
159
- describe "bootstrap_install_command functionality through WinRM protocol", :if_chef_11 => true do
160
- context "bootstrap_install_command option is not specified" do
161
- let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
162
- before do
163
- @template_input = sample_data('win_template_unrendered.txt')
164
- @template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
165
- end
166
-
167
- it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil", :chef_lt_12_5_only => true do
168
- expect(bootstrap.send(:render_template,@template_input)).to eq(
169
- @template_output)
170
- end
171
-
172
- context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
173
- let(:template_12_5_output) { sample_data('win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt') }
174
- it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
175
- expect(bootstrap.send(:render_template,@template_input)).to eq(
176
- template_12_5_output)
177
- end
178
- end
179
- end
180
-
181
- context "bootstrap_install_command option is specified" do
182
- let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
183
- before do
184
- bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
185
- @template_input = sample_data('win_template_unrendered.txt')
186
- @template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
187
- end
188
-
189
- it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template", :chef_lt_12_5_only => true do
190
- expect(bootstrap.send(:render_template,@template_input)).to eq(
191
- @template_output)
192
- end
193
-
194
- context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
195
- let(:template_12_5_output) { sample_data('win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt') }
196
- it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
197
- expect(bootstrap.send(:render_template,@template_input)).to eq(
198
- template_12_5_output)
199
- end
200
- end
201
-
202
- after do
203
- bootstrap.config.delete(:bootstrap_install_command)
204
- Chef::Config[:knife].delete(:bootstrap_install_command)
205
- end
206
- end
207
- end
208
-
209
- describe "bootstrap_install_command functionality through SSH protocol", :if_chef_11 => true, :chef_lt_12_5_only => true do
210
- context "bootstrap_install_command option is not specified" do
211
- let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
212
- before do
213
- @template_input = sample_data('win_template_unrendered.txt')
214
- @template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
215
- end
216
-
217
- it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
218
- expect(bootstrap.send(:render_template,@template_input)).to eq(
219
- @template_output)
220
- end
221
- end
222
-
223
- context "bootstrap_install_command option is specified" do
224
- let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
225
- before do
226
- bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
227
- @template_input = sample_data('win_template_unrendered.txt')
228
- @template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
229
- end
230
-
231
- it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
232
- expect(bootstrap.send(:render_template,@template_input)).to eq(
233
- @template_output)
234
- end
235
-
236
- after do
237
- bootstrap.config.delete(:bootstrap_install_command)
238
- Chef::Config[:knife].delete(:bootstrap_install_command)
239
- end
240
- end
241
- end
1
+ #
2
+ # Author:: Adam Edwards (<adamed@chef.io>)
3
+ # Copyright:: Copyright (c) 2012-2016 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'dummy_winrm_connection'
21
+ require 'spec_helper'
22
+ require 'tmpdir'
23
+
24
+ # These test cases exercise the Knife::Windows knife plugin's ability
25
+ # to download a bootstrap msi as part of the bootstrap process on
26
+ # Windows nodes. The test modifies the Windows batch file generated
27
+ # from an erb template in the plugin source in order to enable execution
28
+ # of only the download functionality contained in the bootstrap template.
29
+ # The test relies on knowledge of the fields of the template itself and
30
+ # also on knowledge of the contents and structure of the Windows batch
31
+ # file generated by the template.
32
+ #
33
+ # Note that if the bootstrap template changes substantially, the tests
34
+ # should fail and will require re-implementation. If such changes
35
+ # occur, the bootstrap code should be refactored to explicitly expose
36
+ # the download funcitonality separately from other tasks to make the
37
+ # test more robust.
38
+ describe 'Knife::Windows::Core msi download functionality for knife Windows winrm bootstrap template' do
39
+
40
+ before(:all) do
41
+ # Since we're always running 32-bit Ruby, fix the
42
+ # PROCESSOR_ARCHITECTURE environment variable.
43
+
44
+ if ENV["PROCESSOR_ARCHITEW6432"]
45
+ ENV["PROCESSOR_ARCHITECTURE"] = ENV["PROCESSOR_ARCHITEW6432"]
46
+ end
47
+
48
+ # All file artifacts from this test will be written into this directory
49
+ @temp_directory = Dir.mktmpdir("bootstrap_test")
50
+
51
+ # Location to which the download script will be modified to write
52
+ # the downloaded msi
53
+ @local_file_download_destination = "#{@temp_directory}/chef-client-latest.msi"
54
+
55
+ source_code_directory = File.dirname(__FILE__)
56
+ @template_file_path ="#{source_code_directory}/../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
57
+ end
58
+
59
+ after(:all) do
60
+ # Clear the temp directory upon exit
61
+ if Dir.exists?(@temp_directory)
62
+ FileUtils::remove_dir(@temp_directory)
63
+ end
64
+ end
65
+
66
+ describe "running on any version of the Windows OS", :windows_only do
67
+ let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} }) }
68
+ let(:mock_winrm) { Chef::Knife::Winrm.new }
69
+
70
+ before do
71
+ # Stub the bootstrap context and prevent config related sections
72
+ # from being populated, i.e. chef installation and first chef
73
+ # run sections
74
+ allow(mock_bootstrap_context).to receive(:validation_key).and_return("echo.validation_key")
75
+ allow(mock_bootstrap_context).to receive(:secret).and_return("echo.encrypted_data_bag_secret")
76
+ allow(mock_bootstrap_context).to receive(:config_content).and_return("echo.config_content")
77
+ allow(mock_bootstrap_context).to receive(:start_chef).and_return("echo.echo start_chef_command")
78
+ allow(mock_bootstrap_context).to receive(:run_list).and_return("echo.run_list")
79
+ allow(mock_bootstrap_context).to receive(:install_chef).and_return("echo.echo install_chef_command")
80
+
81
+ # Change the directories where bootstrap files will be created
82
+ allow(mock_bootstrap_context).to receive(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
83
+ allow(mock_bootstrap_context).to receive(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
84
+
85
+ # Prevent password prompt during bootstrap process
86
+ allow(mock_winrm.ui).to receive(:ask).and_return(nil)
87
+ allow(Chef::Knife::Winrm).to receive(:new).and_return(mock_winrm)
88
+
89
+ allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(mock_bootstrap_context)
90
+ Chef::Config[:knife] = {:winrm_transport => 'plaintext', :chef_node_name => 'foo.example.com', :winrm_authentication_protocol => 'negotiate'}
91
+ end
92
+
93
+ it "downloads the chef-client MSI from the default location during winrm bootstrap" do
94
+ run_download_scenario
95
+ end
96
+
97
+ context "when provided a custom msi_url to fetch from" do
98
+ let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
99
+ { :msi_url => "file:///C:/Windows/System32/xcopy.exe" }, nil, { :knife => {} }) }
100
+ it "downloads the chef-client MSI from a custom path during winrm bootstrap" do
101
+ run_download_scenario
102
+ end
103
+ end
104
+
105
+ context "when provided a custom msi_url with space in path to fetch from" do
106
+ let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
107
+ { :msi_url => "file:///C:/Program Files/Windows NT/Accessories/wordpad.exe" }, nil, { :knife => {} }) }
108
+ it "downloads the chef-client MSI from a custom path with spaces during winrm bootstrap" do
109
+ run_download_scenario
110
+ end
111
+ end
112
+ end
113
+
114
+ def download_succeeded?
115
+ File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
116
+ end
117
+
118
+ # Remove file artifacts generated by individual test cases
119
+ def clean_test_case
120
+ if File.exists?(@local_file_download_destination)
121
+ File.delete(@local_file_download_destination)
122
+ end
123
+ end
124
+
125
+ def run_download_scenario
126
+ clean_test_case
127
+
128
+ winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
129
+
130
+ if chef_gte_12?
131
+ winrm_bootstrapper.client_builder = instance_double("Chef::Knife::Bootstrap::ClientBuilder", :run => nil, :client_path => nil)
132
+ elsif chef_lt_12?
133
+ allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(true)
134
+ end
135
+
136
+ allow(WinRM::Connection).to receive(:new).and_return(Dummy::Connection.new)
137
+ allow(winrm_bootstrapper).to receive(:wait_for_remote_response)
138
+ allow(winrm_bootstrapper).to receive(:validate_options!)
139
+ allow(winrm_bootstrapper.ui).to receive(:ask).and_return(nil)
140
+ winrm_bootstrapper.config[:template_file] = @template_file_path
141
+ winrm_bootstrapper.config[:run_list] = []
142
+ # Execute the commands locally that would normally be executed via WinRM
143
+ allow(winrm_bootstrapper).to receive(:run_command) do |command|
144
+ system(command)
145
+ end
146
+
147
+ winrm_bootstrapper.run
148
+
149
+ # Download should succeed
150
+ expect(download_succeeded?).to be true
151
+ end
152
+ end
153
+
154
+ describe "bootstrap_install_command functionality through WinRM protocol", :if_chef_11 => true do
155
+ context "bootstrap_install_command option is not specified" do
156
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
157
+ before do
158
+ @template_input = sample_data('win_template_unrendered.txt')
159
+ @template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
160
+ end
161
+
162
+ it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil", :chef_lt_12_5_only => true do
163
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
164
+ @template_output)
165
+ end
166
+
167
+ context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
168
+ let(:template_12_5_output) { sample_data('win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt') }
169
+ it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
170
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
171
+ template_12_5_output)
172
+ end
173
+ end
174
+ end
175
+
176
+ context "bootstrap_install_command option is specified" do
177
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
178
+ before do
179
+ bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
180
+ @template_input = sample_data('win_template_unrendered.txt')
181
+ @template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
182
+ end
183
+
184
+ it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template", :chef_lt_12_5_only => true do
185
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
186
+ @template_output)
187
+ end
188
+
189
+ context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
190
+ let(:template_12_5_output) { sample_data('win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt') }
191
+ it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
192
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
193
+ template_12_5_output)
194
+ end
195
+ end
196
+
197
+ after do
198
+ bootstrap.config.delete(:bootstrap_install_command)
199
+ Chef::Config[:knife].delete(:bootstrap_install_command)
200
+ end
201
+ end
202
+ end
203
+
204
+ describe "bootstrap_install_command functionality through SSH protocol", :if_chef_11 => true, :chef_lt_12_5_only => true do
205
+ context "bootstrap_install_command option is not specified" do
206
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
207
+ before do
208
+ @template_input = sample_data('win_template_unrendered.txt')
209
+ @template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
210
+ end
211
+
212
+ it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
213
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
214
+ @template_output)
215
+ end
216
+ end
217
+
218
+ context "bootstrap_install_command option is specified" do
219
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
220
+ before do
221
+ bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
222
+ @template_input = sample_data('win_template_unrendered.txt')
223
+ @template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
224
+ end
225
+
226
+ it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
227
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
228
+ @template_output)
229
+ end
230
+
231
+ after do
232
+ bootstrap.config.delete(:bootstrap_install_command)
233
+ Chef::Config[:knife].delete(:bootstrap_install_command)
234
+ end
235
+ end
236
+ end