knife-windows 1.7.0 → 1.7.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +26 -26
  3. data/CHANGELOG.md +139 -135
  4. data/DOC_CHANGES.md +22 -22
  5. data/Gemfile +13 -13
  6. data/README.md +404 -404
  7. data/RELEASE_NOTES.md +9 -9
  8. data/appveyor.yml +39 -39
  9. data/ci.gemfile +16 -16
  10. data/knife-windows.gemspec +26 -26
  11. data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +246 -246
  12. data/lib/chef/knife/bootstrap_windows_base.rb +443 -443
  13. data/lib/chef/knife/bootstrap_windows_ssh.rb +116 -116
  14. data/lib/chef/knife/bootstrap_windows_winrm.rb +102 -102
  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 +128 -128
  23. data/lib/chef/knife/winrm_knife_base.rb +307 -307
  24. data/lib/chef/knife/winrm_session.rb +98 -98
  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 +242 -234
  29. data/lib/knife-windows/version.rb +6 -6
  30. data/spec/assets/fake_trusted_certs/excluded.txt +2 -0
  31. data/spec/assets/fake_trusted_certs/github.pem +42 -0
  32. data/spec/assets/fake_trusted_certs/google.crt +41 -0
  33. data/spec/assets/win_fake_trusted_cert_script.txt +89 -0
  34. data/spec/assets/win_template_rendered_with_bootstrap_install_command.txt +223 -223
  35. data/spec/assets/win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt +223 -223
  36. data/spec/assets/win_template_rendered_without_bootstrap_install_command.txt +335 -335
  37. data/spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt +335 -335
  38. data/spec/assets/win_template_unrendered.txt +246 -246
  39. data/spec/dummy_winrm_connection.rb +21 -21
  40. data/spec/functional/bootstrap_download_spec.rb +236 -236
  41. data/spec/spec_helper.rb +94 -94
  42. data/spec/unit/knife/bootstrap_options_spec.rb +157 -157
  43. data/spec/unit/knife/bootstrap_template_spec.rb +98 -98
  44. data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +423 -423
  45. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +213 -177
  46. data/spec/unit/knife/windows_cert_generate_spec.rb +90 -90
  47. data/spec/unit/knife/windows_cert_install_spec.rb +51 -51
  48. data/spec/unit/knife/windows_listener_create_spec.rb +76 -76
  49. data/spec/unit/knife/winrm_session_spec.rb +95 -95
  50. data/spec/unit/knife/winrm_spec.rb +500 -500
  51. data/spec/unit/knife/wsman_test_spec.rb +209 -209
  52. metadata +7 -3
data/spec/spec_helper.rb CHANGED
@@ -1,94 +1,94 @@
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
- def windows?
21
- !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
22
- end
23
-
24
- require_relative '../lib/chef/knife/core/windows_bootstrap_context'
25
- require_relative '../lib/chef/knife/bootstrap_windows_winrm'
26
- require_relative '../lib/chef/knife/bootstrap_windows_ssh'
27
- require_relative '../lib/chef/knife/wsman_test'
28
-
29
- if windows?
30
- require 'ruby-wmi'
31
- end
32
-
33
- def windows2012?
34
- is_win2k12 = false
35
-
36
- if windows?
37
- this_operating_system = WMI::Win32_OperatingSystem.find(:first)
38
- os_version = this_operating_system.send('Version')
39
-
40
- # The operating system version is a string in the following form
41
- # that can be split into components based on the '.' delimiter:
42
- # MajorVersionNumber.MinorVersionNumber.BuildNumber
43
- os_version_components = os_version.split('.')
44
-
45
- if os_version_components.length < 2
46
- raise 'WMI returned a Windows version from Win32_OperatingSystem.Version ' +
47
- 'with an unexpected format. The Windows version could not be determined.'
48
- end
49
-
50
- # Windows 6.2 is Windows Server 2012, so test the major and
51
- # minor version components
52
- is_win2k12 = os_version_components[0] == '6' && os_version_components[1] == '2'
53
- end
54
-
55
- is_win2k12
56
- end
57
-
58
- def chef_gte_12?
59
- Chef::VERSION.split('.').first.to_i >= 12
60
- end
61
-
62
- def chef_gte_12_5?
63
- Chef::VERSION.split('.')[0..1].join('.').to_f >= 12.5
64
- end
65
-
66
- def chef_gte_12_6?
67
- Chef::VERSION.split('.')[0..1].join('.').to_f >= 12.6
68
- end
69
-
70
- def chef_lt_12?
71
- Chef::VERSION.split('.').first.to_i < 12
72
- end
73
-
74
- def chef_eq_11?
75
- Chef::VERSION.split('.').first.to_i == 11
76
- end
77
-
78
- def sample_data(file_name)
79
- file = File.expand_path(File.dirname("spec/assets/*"))+"/#{file_name}"
80
- File.read(file)
81
- end
82
-
83
- RSpec.configure do |config|
84
- config.run_all_when_everything_filtered = true
85
- config.filter_run :focus => true
86
- config.filter_run_excluding :windows_only => true unless windows?
87
- config.filter_run_excluding :windows_2012_only => true unless windows2012?
88
- config.filter_run_excluding :chef_gte_12_only => true unless chef_gte_12?
89
- config.filter_run_excluding :chef_gte_12_5_only => true unless chef_gte_12_5?
90
- config.filter_run_excluding :chef_gte_12_6_only => true unless chef_gte_12_6?
91
- config.filter_run_excluding :chef_lt_12_5_only => true if chef_gte_12_5?
92
- config.filter_run_excluding :chef_lt_12_only => true unless chef_lt_12?
93
- config.filter_run_excluding :if_chef_11 => true if chef_eq_11?
94
- 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
+ def windows?
21
+ !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
22
+ end
23
+
24
+ require_relative '../lib/chef/knife/core/windows_bootstrap_context'
25
+ require_relative '../lib/chef/knife/bootstrap_windows_winrm'
26
+ require_relative '../lib/chef/knife/bootstrap_windows_ssh'
27
+ require_relative '../lib/chef/knife/wsman_test'
28
+
29
+ if windows?
30
+ require 'ruby-wmi'
31
+ end
32
+
33
+ def windows2012?
34
+ is_win2k12 = false
35
+
36
+ if windows?
37
+ this_operating_system = WMI::Win32_OperatingSystem.find(:first)
38
+ os_version = this_operating_system.send('Version')
39
+
40
+ # The operating system version is a string in the following form
41
+ # that can be split into components based on the '.' delimiter:
42
+ # MajorVersionNumber.MinorVersionNumber.BuildNumber
43
+ os_version_components = os_version.split('.')
44
+
45
+ if os_version_components.length < 2
46
+ raise 'WMI returned a Windows version from Win32_OperatingSystem.Version ' +
47
+ 'with an unexpected format. The Windows version could not be determined.'
48
+ end
49
+
50
+ # Windows 6.2 is Windows Server 2012, so test the major and
51
+ # minor version components
52
+ is_win2k12 = os_version_components[0] == '6' && os_version_components[1] == '2'
53
+ end
54
+
55
+ is_win2k12
56
+ end
57
+
58
+ def chef_gte_12?
59
+ Chef::VERSION.split('.').first.to_i >= 12
60
+ end
61
+
62
+ def chef_gte_12_5?
63
+ Chef::VERSION.split('.')[0..1].join('.').to_f >= 12.5
64
+ end
65
+
66
+ def chef_gte_12_6?
67
+ Chef::VERSION.split('.')[0..1].join('.').to_f >= 12.6
68
+ end
69
+
70
+ def chef_lt_12?
71
+ Chef::VERSION.split('.').first.to_i < 12
72
+ end
73
+
74
+ def chef_eq_11?
75
+ Chef::VERSION.split('.').first.to_i == 11
76
+ end
77
+
78
+ def sample_data(file_name)
79
+ file = File.expand_path(File.dirname("spec/assets/*"))+"/#{file_name}"
80
+ File.read(file)
81
+ end
82
+
83
+ RSpec.configure do |config|
84
+ config.run_all_when_everything_filtered = true
85
+ config.filter_run :focus => true
86
+ config.filter_run_excluding :windows_only => true unless windows?
87
+ config.filter_run_excluding :windows_2012_only => true unless windows2012?
88
+ config.filter_run_excluding :chef_gte_12_only => true unless chef_gte_12?
89
+ config.filter_run_excluding :chef_gte_12_5_only => true unless chef_gte_12_5?
90
+ config.filter_run_excluding :chef_gte_12_6_only => true unless chef_gte_12_6?
91
+ config.filter_run_excluding :chef_lt_12_5_only => true if chef_gte_12_5?
92
+ config.filter_run_excluding :chef_lt_12_only => true unless chef_lt_12?
93
+ config.filter_run_excluding :if_chef_11 => true if chef_eq_11?
94
+ end
@@ -1,157 +1,157 @@
1
- #
2
- # Author:: Kartik Null Cating-Subramanian(<ksubramanian@chef.io>)
3
- # Copyright:: Copyright (c) 2015-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 implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require 'spec_helper'
20
-
21
- describe Chef::Knife::Bootstrap, :chef_gte_12_6_only do
22
- before(:all) do
23
- Chef::Config.reset
24
- end
25
-
26
- let(:bootstrap) { Chef::Knife::Bootstrap.new }
27
- let(:win_bootstrap) { nil }
28
- let(:opt_map) { {} }
29
- let(:ref_ignore) { [] }
30
- let(:win_ignore) { [] }
31
-
32
- def compare_property(sym)
33
- win_bootstrap.options.each do |win_key, win_val|
34
- unless win_ignore.include?(win_key) || opt_map.include?(win_key) then
35
- actual = win_val[sym]
36
- expected = bootstrap.options[win_key][sym]
37
- expect(actual).to eq(expected),
38
- "#{win_key} flag's #{sym} property doesn't match
39
-
40
- expected: #{expected}
41
- got: #{actual}"
42
- end
43
- end
44
- end
45
-
46
- shared_examples 'compare_options' do
47
- it 'contains the option flags' do
48
- opt_map.default_proc = proc { |map, key| key }
49
- filtered_keys = (win_bootstrap.options.keys - win_ignore).map! { |key| opt_map[key] }
50
-
51
- expect(filtered_keys).to match_array(bootstrap.options.keys - ref_ignore)
52
- end
53
-
54
- it 'uses the same long-name' do
55
- compare_property(:long)
56
- end
57
-
58
- it 'uses the same short-name' do
59
- compare_property(:short)
60
- end
61
-
62
- it 'uses the same description' do
63
- compare_property(:description)
64
- end
65
-
66
- it 'uses the same default value' do
67
- compare_property(:default)
68
- end
69
- end
70
-
71
- context 'when compared to BootstrapWindowsWinrm' do
72
- let(:win_bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new }
73
-
74
- # opt_map: Hash of symbols in windows mapping to symbols in core. Name checks are
75
- # ignored for these.
76
- let(:opt_map) { {
77
- :msi_url => :bootstrap_url,
78
- :encrypted_data_bag_secret => :secret,
79
- :encrypted_data_bag_secret_file => :secret_file,
80
- :winrm_user => :ssh_user,
81
- :winrm_password => :ssh_password,
82
- :winrm_port => :ssh_port,
83
- :winrm_ssl_verify_mode => :host_key_verify,
84
- :bootstrap_install_command => :bootstrap_install_command,
85
- :hint => :hint
86
- }}
87
-
88
- # ref_ignore: Options in core that are not implemented here.
89
- let(:ref_ignore) { [
90
- # These are irrelevant to WinRM.
91
- :bootstrap_curl_options,
92
- :bootstrap_wget_options,
93
- :forward_agent,
94
- :preserve_home,
95
- :ssh_gateway,
96
- :use_sudo,
97
- :use_sudo_password,
98
- :encrypt, # irrelevant during bootstrap
99
- :identity_file,
100
- :ssh_identity_file,
101
- :fips, #until chef 12.7 is released
102
- ]}
103
-
104
- # win_ignore: Options in windows that aren't relevant to core.
105
- let(:win_ignore) { [
106
- :attribute,
107
- :auth_timeout,
108
- :ca_trust_file,
109
- :install_as_service,
110
- :kerberos_keytab_file,
111
- :kerberos_realm,
112
- :kerberos_service,
113
- :manual,
114
- :session_timeout,
115
- :ssl_peer_fingerprint,
116
- :winrm_authentication_protocol,
117
- :winrm_transport,
118
- :fips, #until chef 12.7 is released
119
- ] }
120
-
121
- include_examples 'compare_options'
122
- end
123
-
124
- context 'when compared to BootstrapWindowsSsh' do
125
- let(:win_bootstrap) { Chef::Knife::BootstrapWindowsSsh.new }
126
-
127
- # opt_map: Hash of symbols in windows mapping to symbols in core. Name checks are
128
- # ignored for these.
129
- let(:opt_map) { {
130
- :msi_url => :bootstrap_url,
131
- :encrypted_data_bag_secret => :secret,
132
- :encrypted_data_bag_secret_file => :secret_file,
133
- :bootstrap_install_command => :bootstrap_install_command,
134
- :hint => :hint
135
- }}
136
- # ref_ignore: Options in core that are not implemented here.
137
- let(:ref_ignore) { [
138
- :bootstrap_curl_options,
139
- :bootstrap_wget_options,
140
- :preserve_home,
141
- :use_sudo,
142
- :use_sudo_password,
143
- :encrypt, # irrelevant during bootstrap
144
- :fips, #until chef 12.7 is released
145
- ]}
146
- # win_ignore: Options in windows that aren't relevant to core.
147
- let(:win_ignore) { [
148
- :auth_timeout,
149
- :install_as_service,
150
- :host_key_verification, # Deprecated - remove this when the flag is removed.
151
- :fips, #until chef 12.7 is released
152
- ] }
153
-
154
- include_examples 'compare_options'
155
- end
156
-
157
- end
1
+ #
2
+ # Author:: Kartik Null Cating-Subramanian(<ksubramanian@chef.io>)
3
+ # Copyright:: Copyright (c) 2015-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 implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Chef::Knife::Bootstrap, :chef_gte_12_6_only do
22
+ before(:all) do
23
+ Chef::Config.reset
24
+ end
25
+
26
+ let(:bootstrap) { Chef::Knife::Bootstrap.new }
27
+ let(:win_bootstrap) { nil }
28
+ let(:opt_map) { {} }
29
+ let(:ref_ignore) { [] }
30
+ let(:win_ignore) { [] }
31
+
32
+ def compare_property(sym)
33
+ win_bootstrap.options.each do |win_key, win_val|
34
+ unless win_ignore.include?(win_key) || opt_map.include?(win_key) then
35
+ actual = win_val[sym]
36
+ expected = bootstrap.options[win_key][sym]
37
+ expect(actual).to eq(expected),
38
+ "#{win_key} flag's #{sym} property doesn't match
39
+
40
+ expected: #{expected}
41
+ got: #{actual}"
42
+ end
43
+ end
44
+ end
45
+
46
+ shared_examples 'compare_options' do
47
+ it 'contains the option flags' do
48
+ opt_map.default_proc = proc { |map, key| key }
49
+ filtered_keys = (win_bootstrap.options.keys - win_ignore).map! { |key| opt_map[key] }
50
+
51
+ expect(filtered_keys).to match_array(bootstrap.options.keys - ref_ignore)
52
+ end
53
+
54
+ it 'uses the same long-name' do
55
+ compare_property(:long)
56
+ end
57
+
58
+ it 'uses the same short-name' do
59
+ compare_property(:short)
60
+ end
61
+
62
+ it 'uses the same description' do
63
+ compare_property(:description)
64
+ end
65
+
66
+ it 'uses the same default value' do
67
+ compare_property(:default)
68
+ end
69
+ end
70
+
71
+ context 'when compared to BootstrapWindowsWinrm' do
72
+ let(:win_bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new }
73
+
74
+ # opt_map: Hash of symbols in windows mapping to symbols in core. Name checks are
75
+ # ignored for these.
76
+ let(:opt_map) { {
77
+ :msi_url => :bootstrap_url,
78
+ :encrypted_data_bag_secret => :secret,
79
+ :encrypted_data_bag_secret_file => :secret_file,
80
+ :winrm_user => :ssh_user,
81
+ :winrm_password => :ssh_password,
82
+ :winrm_port => :ssh_port,
83
+ :winrm_ssl_verify_mode => :host_key_verify,
84
+ :bootstrap_install_command => :bootstrap_install_command,
85
+ :hint => :hint
86
+ }}
87
+
88
+ # ref_ignore: Options in core that are not implemented here.
89
+ let(:ref_ignore) { [
90
+ # These are irrelevant to WinRM.
91
+ :bootstrap_curl_options,
92
+ :bootstrap_wget_options,
93
+ :forward_agent,
94
+ :preserve_home,
95
+ :ssh_gateway,
96
+ :use_sudo,
97
+ :use_sudo_password,
98
+ :encrypt, # irrelevant during bootstrap
99
+ :identity_file,
100
+ :ssh_identity_file,
101
+ :fips, #until chef 12.7 is released
102
+ ]}
103
+
104
+ # win_ignore: Options in windows that aren't relevant to core.
105
+ let(:win_ignore) { [
106
+ :attribute,
107
+ :auth_timeout,
108
+ :ca_trust_file,
109
+ :install_as_service,
110
+ :kerberos_keytab_file,
111
+ :kerberos_realm,
112
+ :kerberos_service,
113
+ :manual,
114
+ :session_timeout,
115
+ :ssl_peer_fingerprint,
116
+ :winrm_authentication_protocol,
117
+ :winrm_transport,
118
+ :fips, #until chef 12.7 is released
119
+ ] }
120
+
121
+ include_examples 'compare_options'
122
+ end
123
+
124
+ context 'when compared to BootstrapWindowsSsh' do
125
+ let(:win_bootstrap) { Chef::Knife::BootstrapWindowsSsh.new }
126
+
127
+ # opt_map: Hash of symbols in windows mapping to symbols in core. Name checks are
128
+ # ignored for these.
129
+ let(:opt_map) { {
130
+ :msi_url => :bootstrap_url,
131
+ :encrypted_data_bag_secret => :secret,
132
+ :encrypted_data_bag_secret_file => :secret_file,
133
+ :bootstrap_install_command => :bootstrap_install_command,
134
+ :hint => :hint
135
+ }}
136
+ # ref_ignore: Options in core that are not implemented here.
137
+ let(:ref_ignore) { [
138
+ :bootstrap_curl_options,
139
+ :bootstrap_wget_options,
140
+ :preserve_home,
141
+ :use_sudo,
142
+ :use_sudo_password,
143
+ :encrypt, # irrelevant during bootstrap
144
+ :fips, #until chef 12.7 is released
145
+ ]}
146
+ # win_ignore: Options in windows that aren't relevant to core.
147
+ let(:win_ignore) { [
148
+ :auth_timeout,
149
+ :install_as_service,
150
+ :host_key_verification, # Deprecated - remove this when the flag is removed.
151
+ :fips, #until chef 12.7 is released
152
+ ] }
153
+
154
+ include_examples 'compare_options'
155
+ end
156
+
157
+ end