chef 12.3.0 → 12.4.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +86 -7
  3. data/distro/common/markdown/man1/chef-shell.mkd +4 -4
  4. data/distro/common/markdown/man1/knife-bootstrap.mkd +1 -1
  5. data/distro/common/markdown/man1/knife-client.mkd +1 -1
  6. data/distro/common/markdown/man1/knife-configure.mkd +1 -1
  7. data/distro/common/markdown/man1/knife-cookbook-site.mkd +1 -1
  8. data/distro/common/markdown/man1/knife-cookbook.mkd +4 -4
  9. data/distro/common/markdown/man1/knife-data-bag.mkd +1 -1
  10. data/distro/common/markdown/man1/knife-environment.mkd +3 -3
  11. data/distro/common/markdown/man1/knife-exec.mkd +1 -1
  12. data/distro/common/markdown/man1/knife-index.mkd +1 -1
  13. data/distro/common/markdown/man1/knife-node.mkd +1 -1
  14. data/distro/common/markdown/man1/knife-role.mkd +3 -3
  15. data/distro/common/markdown/man1/knife-search.mkd +2 -2
  16. data/distro/common/markdown/man1/knife-ssh.mkd +1 -1
  17. data/distro/common/markdown/man1/knife-status.mkd +1 -1
  18. data/distro/common/markdown/man1/knife-tag.mkd +1 -1
  19. data/distro/common/markdown/man1/knife.mkd +2 -2
  20. data/distro/common/markdown/man8/chef-client.mkd +1 -2
  21. data/distro/common/markdown/man8/chef-expander.mkd +1 -2
  22. data/distro/common/markdown/man8/chef-expanderctl.mkd +1 -2
  23. data/distro/common/markdown/man8/chef-server-webui.mkd +1 -1
  24. data/distro/common/markdown/man8/chef-server.mkd +1 -2
  25. data/distro/common/markdown/man8/chef-solo.mkd +2 -2
  26. data/distro/common/markdown/man8/chef-solr.mkd +1 -1
  27. data/lib/chef/client.rb +2 -2
  28. data/lib/chef/config.rb +17 -709
  29. data/lib/chef/cookbook/metadata.rb +9 -5
  30. data/lib/chef/cookbook_loader.rb +1 -1
  31. data/lib/chef/cookbook_site_streaming_uploader.rb +2 -18
  32. data/lib/chef/dsl/definitions.rb +44 -0
  33. data/lib/chef/dsl/recipe.rb +50 -35
  34. data/lib/chef/dsl/resources.rb +28 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +2 -0
  36. data/lib/chef/event_loggers/windows_eventlog.rb +1 -11
  37. data/lib/chef/exceptions.rb +4 -0
  38. data/lib/chef/file_access_control/unix.rb +5 -0
  39. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +17 -0
  40. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +21 -9
  41. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +2 -0
  42. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +2 -0
  43. data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -0
  44. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +4 -0
  45. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +11 -1
  46. data/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +2 -0
  47. data/lib/chef/http/authenticator.rb +3 -0
  48. data/lib/chef/http/basic_client.rb +10 -6
  49. data/lib/chef/http/json_input.rb +6 -1
  50. data/lib/chef/key.rb +271 -0
  51. data/lib/chef/knife.rb +11 -1
  52. data/lib/chef/knife/bootstrap.rb +6 -0
  53. data/lib/chef/knife/bootstrap/templates/chef-full.erb +166 -23
  54. data/lib/chef/knife/client_key_create.rb +67 -0
  55. data/lib/chef/knife/client_key_delete.rb +76 -0
  56. data/lib/chef/knife/client_key_edit.rb +80 -0
  57. data/lib/chef/knife/client_key_list.rb +69 -0
  58. data/lib/chef/knife/client_key_show.rb +76 -0
  59. data/lib/chef/knife/key_create.rb +108 -0
  60. data/lib/chef/knife/key_create_base.rb +50 -0
  61. data/lib/chef/knife/key_delete.rb +55 -0
  62. data/lib/chef/knife/key_edit.rb +114 -0
  63. data/lib/chef/knife/key_edit_base.rb +55 -0
  64. data/lib/chef/knife/key_list.rb +88 -0
  65. data/lib/chef/knife/key_list_base.rb +45 -0
  66. data/lib/chef/knife/key_show.rb +53 -0
  67. data/lib/chef/knife/ssh.rb +26 -28
  68. data/lib/chef/knife/user_key_create.rb +69 -0
  69. data/lib/chef/knife/user_key_delete.rb +76 -0
  70. data/lib/chef/knife/user_key_edit.rb +80 -0
  71. data/lib/chef/knife/user_key_list.rb +69 -0
  72. data/lib/chef/knife/user_key_show.rb +76 -0
  73. data/lib/chef/log.rb +2 -0
  74. data/lib/chef/log/syslog.rb +46 -0
  75. data/lib/chef/log/winevt.rb +99 -0
  76. data/lib/chef/mixin/provides.rb +8 -1
  77. data/lib/chef/mixin/unformatter.rb +32 -0
  78. data/lib/chef/mixin/uris.rb +33 -0
  79. data/lib/chef/mixin/wstring.rb +31 -0
  80. data/lib/chef/node.rb +21 -2
  81. data/lib/chef/platform/provider_mapping.rb +8 -4
  82. data/lib/chef/platform/query_helpers.rb +1 -5
  83. data/lib/chef/platform/service_helpers.rb +21 -21
  84. data/lib/chef/provider.rb +33 -0
  85. data/lib/chef/provider/cron/unix.rb +1 -0
  86. data/lib/chef/provider/file.rb +5 -3
  87. data/lib/chef/provider/lwrp_base.rb +76 -58
  88. data/lib/chef/provider/ohai.rb +1 -0
  89. data/lib/chef/provider/package.rb +7 -4
  90. data/lib/chef/provider/package/aix.rb +1 -0
  91. data/lib/chef/provider/package/smartos.rb +5 -5
  92. data/lib/chef/provider/package/windows.rb +90 -6
  93. data/lib/chef/provider/package/yum.rb +102 -32
  94. data/lib/chef/provider/reboot.rb +1 -0
  95. data/lib/chef/provider/registry_key.rb +2 -0
  96. data/lib/chef/provider/remote_file.rb +1 -0
  97. data/lib/chef/provider/remote_file/content.rb +5 -1
  98. data/lib/chef/provider/remote_file/fetcher.rb +22 -8
  99. data/lib/chef/provider/remote_file/network_file.rb +48 -0
  100. data/lib/chef/provider/service/aix.rb +13 -12
  101. data/lib/chef/provider_resolver.rb +87 -0
  102. data/lib/chef/providers.rb +1 -0
  103. data/lib/chef/resource.rb +67 -8
  104. data/lib/chef/resource/bash.rb +1 -0
  105. data/lib/chef/resource/bff_package.rb +1 -2
  106. data/lib/chef/resource/breakpoint.rb +1 -0
  107. data/lib/chef/resource/csh.rb +1 -0
  108. data/lib/chef/resource/deploy.rb +1 -0
  109. data/lib/chef/resource/erl_call.rb +1 -0
  110. data/lib/chef/resource/execute.rb +1 -0
  111. data/lib/chef/resource/file.rb +18 -0
  112. data/lib/chef/resource/http_request.rb +1 -0
  113. data/lib/chef/resource/ifconfig.rb +1 -2
  114. data/lib/chef/resource/log.rb +1 -2
  115. data/lib/chef/resource/lwrp_base.rb +106 -87
  116. data/lib/chef/resource/ohai.rb +1 -0
  117. data/lib/chef/resource/package.rb +1 -0
  118. data/lib/chef/resource/perl.rb +1 -0
  119. data/lib/chef/resource/portage_package.rb +1 -0
  120. data/lib/chef/resource/python.rb +1 -0
  121. data/lib/chef/resource/reboot.rb +2 -0
  122. data/lib/chef/resource/registry_key.rb +1 -0
  123. data/lib/chef/resource/remote_file.rb +1 -1
  124. data/lib/chef/resource/route.rb +1 -2
  125. data/lib/chef/resource/ruby.rb +1 -0
  126. data/lib/chef/resource/ruby_block.rb +1 -0
  127. data/lib/chef/resource/scm.rb +1 -0
  128. data/lib/chef/resource/script.rb +1 -0
  129. data/lib/chef/resource/service.rb +1 -0
  130. data/lib/chef/resource/subversion.rb +1 -0
  131. data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +24 -2
  133. data/lib/chef/resource/windows_script.rb +1 -0
  134. data/lib/chef/resource/yum_package.rb +1 -1
  135. data/lib/chef/resource_definition.rb +1 -0
  136. data/lib/chef/resource_reporter.rb +3 -10
  137. data/lib/chef/resource_resolver.rb +20 -10
  138. data/lib/chef/run_context.rb +1 -0
  139. data/lib/chef/run_list/versioned_recipe_list.rb +18 -0
  140. data/lib/chef/run_status.rb +2 -4
  141. data/lib/chef/shell.rb +1 -1
  142. data/lib/chef/util/path_helper.rb +3 -204
  143. data/lib/chef/util/windows/net_user.rb +73 -118
  144. data/lib/chef/version.rb +8 -4
  145. data/lib/chef/win32/api.rb +2 -1
  146. data/lib/chef/win32/api/installer.rb +1 -1
  147. data/lib/chef/win32/api/net.rb +115 -2
  148. data/lib/chef/win32/api/security.rb +24 -0
  149. data/lib/chef/win32/api/unicode.rb +1 -1
  150. data/lib/chef/win32/eventlog.rb +31 -0
  151. data/lib/chef/win32/net.rb +190 -0
  152. data/lib/chef/win32/security.rb +51 -2
  153. data/lib/chef/win32/security/sid.rb +17 -0
  154. data/spec/data/lwrp/providers/buck_passer.rb +18 -2
  155. data/spec/data/lwrp/providers/buck_passer_2.rb +18 -2
  156. data/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb +14 -2
  157. data/spec/data/lwrp_override/resources/foo.rb +5 -0
  158. data/spec/functional/knife/ssh_spec.rb +2 -2
  159. data/spec/functional/rebooter_spec.rb +1 -1
  160. data/spec/functional/resource/aixinit_service_spec.rb +1 -1
  161. data/spec/functional/resource/user/windows_spec.rb +125 -0
  162. data/spec/functional/shell_spec.rb +25 -10
  163. data/spec/functional/win32/sid_spec.rb +55 -0
  164. data/spec/integration/client/client_spec.rb +53 -29
  165. data/spec/integration/knife/deps_spec.rb +8 -14
  166. data/spec/integration/knife/upload_spec.rb +18 -0
  167. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  168. data/spec/integration/recipes/provider_choice.rb +41 -0
  169. data/spec/integration/recipes/recipe_dsl_spec.rb +259 -0
  170. data/spec/spec_helper.rb +6 -1
  171. data/spec/support/key_helpers.rb +104 -0
  172. data/spec/support/lib/chef/resource/cat.rb +1 -0
  173. data/spec/support/lib/chef/resource/one_two_three_four.rb +2 -0
  174. data/spec/support/lib/chef/resource/zen_follower.rb +1 -0
  175. data/spec/support/lib/chef/resource/zen_master.rb +2 -0
  176. data/spec/support/mock/platform.rb +1 -1
  177. data/spec/support/pedant/Gemfile.lock +67 -0
  178. data/spec/support/shared/functional/securable_resource.rb +34 -12
  179. data/spec/support/shared/integration/integration_helper.rb +6 -5
  180. data/spec/support/shared/unit/provider/file.rb +31 -8
  181. data/spec/unit/application/client_spec.rb +2 -2
  182. data/spec/unit/client_spec.rb +21 -4
  183. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
  184. data/spec/unit/cookbook/metadata_spec.rb +15 -0
  185. data/spec/unit/cookbook/syntax_check_spec.rb +1 -1
  186. data/spec/unit/cookbook_loader_spec.rb +1 -1
  187. data/spec/unit/cookbook_site_streaming_uploader_spec.rb +0 -21
  188. data/spec/unit/data_bag_spec.rb +1 -1
  189. data/spec/unit/event_dispatch/dispatcher_spec.rb +61 -0
  190. data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +75 -0
  191. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +149 -112
  192. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +7 -0
  193. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
  194. data/spec/unit/http/authenticator_spec.rb +69 -0
  195. data/spec/unit/http/basic_client_spec.rb +16 -0
  196. data/spec/unit/key_spec.rb +634 -0
  197. data/spec/unit/knife/bootstrap_spec.rb +14 -1
  198. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
  199. data/spec/unit/knife/core/ui_spec.rb +1 -1
  200. data/spec/unit/knife/data_bag_from_file_spec.rb +1 -1
  201. data/spec/unit/knife/environment_from_file_spec.rb +1 -1
  202. data/spec/unit/knife/key_create_spec.rb +224 -0
  203. data/spec/unit/knife/key_delete_spec.rb +135 -0
  204. data/spec/unit/knife/key_edit_spec.rb +267 -0
  205. data/spec/unit/knife/key_helper.rb +74 -0
  206. data/spec/unit/knife/key_list_spec.rb +216 -0
  207. data/spec/unit/knife/key_show_spec.rb +126 -0
  208. data/spec/unit/knife/ssh_spec.rb +23 -26
  209. data/spec/unit/knife_spec.rb +33 -1
  210. data/spec/unit/log/syslog_spec.rb +53 -0
  211. data/spec/unit/log/winevt_spec.rb +55 -0
  212. data/spec/unit/lwrp_spec.rb +105 -51
  213. data/spec/unit/mixin/path_sanity_spec.rb +2 -2
  214. data/spec/unit/mixin/template_spec.rb +2 -2
  215. data/spec/unit/mixin/unformatter_spec.rb +61 -0
  216. data/spec/unit/mixin/uris_spec.rb +45 -0
  217. data/spec/unit/platform/query_helpers_spec.rb +1 -1
  218. data/spec/unit/policy_builder/policyfile_spec.rb +7 -3
  219. data/spec/unit/provider/deploy/revision_spec.rb +1 -1
  220. data/spec/unit/provider/deploy_spec.rb +1 -1
  221. data/spec/unit/provider/directory_spec.rb +1 -1
  222. data/spec/unit/provider/execute_spec.rb +1 -1
  223. data/spec/unit/provider/package/aix_spec.rb +20 -8
  224. data/spec/unit/provider/package/smartos_spec.rb +50 -40
  225. data/spec/unit/provider/package/windows_spec.rb +104 -25
  226. data/spec/unit/provider/package/yum_spec.rb +111 -1
  227. data/spec/unit/provider/package_spec.rb +6 -0
  228. data/spec/unit/provider/remote_file/fetcher_spec.rb +20 -1
  229. data/spec/unit/provider/remote_file/network_file_spec.rb +45 -0
  230. data/spec/unit/provider/service/aix_service_spec.rb +26 -11
  231. data/spec/unit/provider/user/dscl_spec.rb +1 -1
  232. data/spec/unit/provider_spec.rb +20 -0
  233. data/spec/unit/recipe_spec.rb +1 -1
  234. data/spec/unit/resource/batch_spec.rb +1 -0
  235. data/spec/unit/resource/powershell_spec.rb +1 -0
  236. data/spec/unit/resource/remote_file_spec.rb +10 -0
  237. data/spec/unit/resource/windows_package_spec.rb +16 -2
  238. data/spec/unit/resource_spec.rb +40 -24
  239. data/spec/unit/rest_spec.rb +10 -20
  240. data/spec/unit/role_spec.rb +1 -1
  241. data/spec/unit/run_context_spec.rb +31 -0
  242. data/spec/unit/shell_spec.rb +4 -4
  243. data/tasks/external_tests.rb +29 -0
  244. data/tasks/rspec.rb +14 -1
  245. metadata +105 -28
  246. data/spec/unit/config_spec.rb +0 -544
  247. data/spec/unit/util/path_helper_spec.rb +0 -255
@@ -1,544 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Author:: Kyle Goodwin (<kgoodwin@primerevenue.com>)
4
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 'chef/exceptions'
22
- require 'chef/util/path_helper'
23
-
24
- describe Chef::Config do
25
- describe "config attribute writer: chef_server_url" do
26
- before do
27
- Chef::Config.chef_server_url = "https://junglist.gen.nz"
28
- end
29
-
30
- it "sets the server url" do
31
- expect(Chef::Config.chef_server_url).to eq("https://junglist.gen.nz")
32
- end
33
-
34
- context "when the url has a leading space" do
35
- before do
36
- Chef::Config.chef_server_url = " https://junglist.gen.nz"
37
- end
38
-
39
- it "strips the space from the url when setting" do
40
- expect(Chef::Config.chef_server_url).to eq("https://junglist.gen.nz")
41
- end
42
-
43
- end
44
-
45
- context "when the url is a frozen string" do
46
- before do
47
- Chef::Config.chef_server_url = " https://junglist.gen.nz".freeze
48
- end
49
-
50
- it "strips the space from the url when setting without raising an error" do
51
- expect(Chef::Config.chef_server_url).to eq("https://junglist.gen.nz")
52
- end
53
- end
54
-
55
- end
56
-
57
- describe "when configuring formatters" do
58
- # if TTY and not(force-logger)
59
- # formatter = configured formatter or default formatter
60
- # formatter goes to STDOUT/ERR
61
- # if log file is writeable
62
- # log level is configured level or info
63
- # log location is file
64
- # else
65
- # log level is warn
66
- # log location is STDERR
67
- # end
68
- # elsif not(TTY) and force formatter
69
- # formatter = configured formatter or default formatter
70
- # if log_location specified
71
- # formatter goes to log_location
72
- # else
73
- # formatter goes to STDOUT/ERR
74
- # end
75
- # else
76
- # formatter = "null"
77
- # log_location = configured-value or defualt
78
- # log_level = info or defualt
79
- # end
80
- #
81
- it "has an empty list of formatters by default" do
82
- expect(Chef::Config.formatters).to eq([])
83
- end
84
-
85
- it "configures a formatter with a short name" do
86
- Chef::Config.add_formatter(:doc)
87
- expect(Chef::Config.formatters).to eq([[:doc, nil]])
88
- end
89
-
90
- it "configures a formatter with a file output" do
91
- Chef::Config.add_formatter(:doc, "/var/log/formatter.log")
92
- expect(Chef::Config.formatters).to eq([[:doc, "/var/log/formatter.log"]])
93
- end
94
-
95
- end
96
-
97
- describe "class method: manage_secret_key" do
98
- before do
99
- allow(Chef::FileCache).to receive(:load).and_return(true)
100
- allow(Chef::FileCache).to receive(:has_key?).with("chef_server_cookie_id").and_return(false)
101
- end
102
-
103
- it "should generate and store a chef server cookie id" do
104
- expect(Chef::FileCache).to receive(:store).with("chef_server_cookie_id", /\w{40}/).and_return(true)
105
- Chef::Config.manage_secret_key
106
- end
107
-
108
- describe "when the filecache has a chef server cookie id key" do
109
- before do
110
- allow(Chef::FileCache).to receive(:has_key?).with("chef_server_cookie_id").and_return(true)
111
- end
112
-
113
- it "should not generate and store a chef server cookie id" do
114
- expect(Chef::FileCache).not_to receive(:store).with("chef_server_cookie_id", /\w{40}/)
115
- Chef::Config.manage_secret_key
116
- end
117
- end
118
-
119
- end
120
-
121
- [ false, true ].each do |is_windows|
122
-
123
- context "On #{is_windows ? 'Windows' : 'Unix'}" do
124
- def to_platform(*args)
125
- Chef::Config.platform_specific_path(*args)
126
- end
127
-
128
- before :each do
129
- allow(Chef::Platform).to receive(:windows?).and_return(is_windows)
130
- end
131
-
132
- describe "class method: platform_specific_path" do
133
- if is_windows
134
- it "should return a windows path on windows systems" do
135
- path = "/etc/chef/cookbooks"
136
- allow(Chef::Config).to receive(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
137
- # match on a regex that looks for the base path with an optional
138
- # system drive at the beginning (c:)
139
- # system drive is not hardcoded b/c it can change and b/c it is not present on linux systems
140
- expect(Chef::Config.platform_specific_path(path)).to eq("C:\\chef\\cookbooks")
141
- end
142
- else
143
- it "should return given path on non-windows systems" do
144
- path = "/etc/chef/cookbooks"
145
- expect(Chef::Config.platform_specific_path(path)).to eq("/etc/chef/cookbooks")
146
- end
147
- end
148
- end
149
-
150
- describe "default values" do
151
- let :primary_cache_path do
152
- if is_windows
153
- "#{Chef::Config.env['SYSTEMDRIVE']}\\chef"
154
- else
155
- "/var/chef"
156
- end
157
- end
158
-
159
- let :secondary_cache_path do
160
- if is_windows
161
- "#{Chef::Config[:user_home]}\\.chef"
162
- else
163
- "#{Chef::Config[:user_home]}/.chef"
164
- end
165
- end
166
-
167
- before do
168
- if is_windows
169
- allow(Chef::Config).to receive(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
170
- Chef::Config[:user_home] = 'C:\Users\charlie'
171
- else
172
- Chef::Config[:user_home] = '/Users/charlie'
173
- end
174
-
175
- allow(Chef::Config).to receive(:path_accessible?).and_return(false)
176
- end
177
-
178
- describe "Chef::Config[:cache_path]" do
179
- context "when /var/chef exists and is accessible" do
180
- it "defaults to /var/chef" do
181
- allow(Chef::Config).to receive(:path_accessible?).with(to_platform("/var/chef")).and_return(true)
182
- expect(Chef::Config[:cache_path]).to eq(primary_cache_path)
183
- end
184
- end
185
-
186
- context "when /var/chef does not exist and /var is accessible" do
187
- it "defaults to /var/chef" do
188
- allow(File).to receive(:exists?).with(to_platform("/var/chef")).and_return(false)
189
- allow(Chef::Config).to receive(:path_accessible?).with(to_platform("/var")).and_return(true)
190
- expect(Chef::Config[:cache_path]).to eq(primary_cache_path)
191
- end
192
- end
193
-
194
- context "when /var/chef does not exist and /var is not accessible" do
195
- it "defaults to $HOME/.chef" do
196
- allow(File).to receive(:exists?).with(to_platform("/var/chef")).and_return(false)
197
- allow(Chef::Config).to receive(:path_accessible?).with(to_platform("/var")).and_return(false)
198
- expect(Chef::Config[:cache_path]).to eq(secondary_cache_path)
199
- end
200
- end
201
-
202
- context "when /var/chef exists and is not accessible" do
203
- it "defaults to $HOME/.chef" do
204
- allow(File).to receive(:exists?).with(to_platform("/var/chef")).and_return(true)
205
- allow(File).to receive(:readable?).with(to_platform("/var/chef")).and_return(true)
206
- allow(File).to receive(:writable?).with(to_platform("/var/chef")).and_return(false)
207
-
208
- expect(Chef::Config[:cache_path]).to eq(secondary_cache_path)
209
- end
210
- end
211
-
212
- context "when chef is running in local mode" do
213
- before do
214
- Chef::Config.local_mode = true
215
- end
216
-
217
- context "and config_dir is /a/b/c" do
218
- before do
219
- Chef::Config.config_dir to_platform('/a/b/c')
220
- end
221
-
222
- it "cache_path is /a/b/c/local-mode-cache" do
223
- expect(Chef::Config.cache_path).to eq(to_platform('/a/b/c/local-mode-cache'))
224
- end
225
- end
226
-
227
- context "and config_dir is /a/b/c/" do
228
- before do
229
- Chef::Config.config_dir to_platform('/a/b/c/')
230
- end
231
-
232
- it "cache_path is /a/b/c/local-mode-cache" do
233
- expect(Chef::Config.cache_path).to eq(to_platform('/a/b/c/local-mode-cache'))
234
- end
235
- end
236
- end
237
- end
238
-
239
- it "Chef::Config[:file_backup_path] defaults to /var/chef/backup" do
240
- allow(Chef::Config).to receive(:cache_path).and_return(primary_cache_path)
241
- backup_path = is_windows ? "#{primary_cache_path}\\backup" : "#{primary_cache_path}/backup"
242
- expect(Chef::Config[:file_backup_path]).to eq(backup_path)
243
- end
244
-
245
- it "Chef::Config[:ssl_verify_mode] defaults to :verify_peer" do
246
- expect(Chef::Config[:ssl_verify_mode]).to eq(:verify_peer)
247
- end
248
-
249
- it "Chef::Config[:ssl_ca_path] defaults to nil" do
250
- expect(Chef::Config[:ssl_ca_path]).to be_nil
251
- end
252
-
253
- # TODO can this be removed?
254
- if !is_windows
255
- it "Chef::Config[:ssl_ca_file] defaults to nil" do
256
- expect(Chef::Config[:ssl_ca_file]).to be_nil
257
- end
258
- end
259
-
260
- it "Chef::Config[:data_bag_path] defaults to /var/chef/data_bags" do
261
- allow(Chef::Config).to receive(:cache_path).and_return(primary_cache_path)
262
- data_bag_path = is_windows ? "#{primary_cache_path}\\data_bags" : "#{primary_cache_path}/data_bags"
263
- expect(Chef::Config[:data_bag_path]).to eq(data_bag_path)
264
- end
265
-
266
- it "Chef::Config[:environment_path] defaults to /var/chef/environments" do
267
- allow(Chef::Config).to receive(:cache_path).and_return(primary_cache_path)
268
- environment_path = is_windows ? "#{primary_cache_path}\\environments" : "#{primary_cache_path}/environments"
269
- expect(Chef::Config[:environment_path]).to eq(environment_path)
270
- end
271
-
272
- describe "setting the config dir" do
273
-
274
- context "when the config file is /etc/chef/client.rb" do
275
-
276
- before do
277
- Chef::Config.config_file = to_platform("/etc/chef/client.rb")
278
- end
279
-
280
- it "config_dir is /etc/chef" do
281
- expect(Chef::Config.config_dir).to eq(to_platform("/etc/chef"))
282
- end
283
-
284
- context "and chef is running in local mode" do
285
- before do
286
- Chef::Config.local_mode = true
287
- end
288
-
289
- it "config_dir is /etc/chef" do
290
- expect(Chef::Config.config_dir).to eq(to_platform("/etc/chef"))
291
- end
292
- end
293
-
294
- context "when config_dir is set to /other/config/dir/" do
295
- before do
296
- Chef::Config.config_dir = to_platform("/other/config/dir/")
297
- end
298
-
299
- it "yields the explicit value" do
300
- expect(Chef::Config.config_dir).to eq(to_platform("/other/config/dir/"))
301
- end
302
- end
303
-
304
- end
305
-
306
- context "when the user's home dir is /home/charlie/" do
307
- before do
308
- Chef::Config.user_home = to_platform("/home/charlie")
309
- end
310
-
311
- it "config_dir is /home/charlie/.chef/" do
312
- expect(Chef::Config.config_dir).to eq(Chef::Util::PathHelper.join(to_platform("/home/charlie/.chef"), ''))
313
- end
314
-
315
- context "and chef is running in local mode" do
316
- before do
317
- Chef::Config.local_mode = true
318
- end
319
-
320
- it "config_dir is /home/charlie/.chef/" do
321
- expect(Chef::Config.config_dir).to eq(Chef::Util::PathHelper.join(to_platform("/home/charlie/.chef"), ''))
322
- end
323
- end
324
- end
325
-
326
- end
327
-
328
- if is_windows
329
- describe "finding the windows embedded dir" do
330
- let(:default_config_location) { "c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
331
- let(:alternate_install_location) { "c:/my/alternate/install/place/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
332
- let(:non_omnibus_location) { "c:/my/dev/stuff/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
333
-
334
- let(:default_ca_file) { "c:/opscode/chef/embedded/ssl/certs/cacert.pem" }
335
-
336
- it "finds the embedded dir in the default location" do
337
- allow(Chef::Config).to receive(:_this_file).and_return(default_config_location)
338
- expect(Chef::Config.embedded_dir).to eq("c:/opscode/chef/embedded")
339
- end
340
-
341
- it "finds the embedded dir in a custom install location" do
342
- allow(Chef::Config).to receive(:_this_file).and_return(alternate_install_location)
343
- expect(Chef::Config.embedded_dir).to eq("c:/my/alternate/install/place/chef/embedded")
344
- end
345
-
346
- it "doesn't error when not in an omnibus install" do
347
- allow(Chef::Config).to receive(:_this_file).and_return(non_omnibus_location)
348
- expect(Chef::Config.embedded_dir).to be_nil
349
- end
350
-
351
- it "sets the ssl_ca_cert path if the cert file is available" do
352
- allow(Chef::Config).to receive(:_this_file).and_return(default_config_location)
353
- allow(File).to receive(:exist?).with(default_ca_file).and_return(true)
354
- expect(Chef::Config.ssl_ca_file).to eq(default_ca_file)
355
- end
356
- end
357
- end
358
- end
359
-
360
- describe "Chef::Config[:user_home]" do
361
- it "should set when HOME is provided" do
362
- expected = to_platform("/home/kitten")
363
- allow(Chef::Util::PathHelper).to receive(:home).and_return(expected)
364
- expect(Chef::Config[:user_home]).to eq(expected)
365
- end
366
-
367
- it "falls back to the current working directory when HOME and USERPROFILE is not set" do
368
- allow(Chef::Util::PathHelper).to receive(:home).and_return(nil)
369
- expect(Chef::Config[:user_home]).to eq(Dir.pwd)
370
- end
371
- end
372
-
373
- describe "Chef::Config[:encrypted_data_bag_secret]" do
374
- let(:db_secret_default_path){ to_platform("/etc/chef/encrypted_data_bag_secret") }
375
-
376
- before do
377
- allow(File).to receive(:exist?).with(db_secret_default_path).and_return(secret_exists)
378
- end
379
-
380
- context "/etc/chef/encrypted_data_bag_secret exists" do
381
- let(:secret_exists) { true }
382
- it "sets the value to /etc/chef/encrypted_data_bag_secret" do
383
- expect(Chef::Config[:encrypted_data_bag_secret]).to eq db_secret_default_path
384
- end
385
- end
386
-
387
- context "/etc/chef/encrypted_data_bag_secret does not exist" do
388
- let(:secret_exists) { false }
389
- it "sets the value to nil" do
390
- expect(Chef::Config[:encrypted_data_bag_secret]).to be_nil
391
- end
392
- end
393
- end
394
-
395
- describe "Chef::Config[:event_handlers]" do
396
- it "sets a event_handlers to an empty array by default" do
397
- expect(Chef::Config[:event_handlers]).to eq([])
398
- end
399
- it "should be able to add custom handlers" do
400
- o = Object.new
401
- Chef::Config[:event_handlers] << o
402
- expect(Chef::Config[:event_handlers]).to be_include(o)
403
- end
404
- end
405
-
406
- describe "Chef::Config[:user_valid_regex]" do
407
- context "on a platform that is not Windows" do
408
- it "allows one letter usernames" do
409
- any_match = Chef::Config[:user_valid_regex].any? { |regex| regex.match('a') }
410
- expect(any_match).to be_truthy
411
- end
412
- end
413
- end
414
-
415
- describe "Chef::Config[:internal_locale]" do
416
- let(:shell_out) do
417
- double("Chef::Mixin::ShellOut double", :exitstatus => 0, :stdout => locales)
418
- end
419
-
420
- let(:locales) { locale_array.join("\n") }
421
-
422
- before do
423
- allow(Chef::Config).to receive(:shell_out_with_systems_locale!).with("locale -a").and_return(shell_out)
424
- end
425
-
426
- shared_examples_for "a suitable locale" do
427
- it "returns an English UTF-8 locale" do
428
- expect(Chef::Log).to_not receive(:warn).with(/Please install an English UTF-8 locale for Chef to use/)
429
- expect(Chef::Log).to_not receive(:debug).with(/Defaulting to locale en_US.UTF-8 on Windows/)
430
- expect(Chef::Log).to_not receive(:debug).with(/No usable locale -a command found/)
431
- expect(Chef::Config.guess_internal_locale).to eq expected_locale
432
- end
433
- end
434
-
435
- context "when the result includes 'C.UTF-8'" do
436
- include_examples "a suitable locale" do
437
- let(:locale_array) { [expected_locale, "en_US.UTF-8"] }
438
- let(:expected_locale) { "C.UTF-8" }
439
- end
440
- end
441
-
442
- context "when the result includes 'en_US.UTF-8'" do
443
- include_examples "a suitable locale" do
444
- let(:locale_array) { ["en_CA.UTF-8", expected_locale, "en_NZ.UTF-8"] }
445
- let(:expected_locale) { "en_US.UTF-8" }
446
- end
447
- end
448
-
449
- context "when the result includes 'en_US.utf8'" do
450
- include_examples "a suitable locale" do
451
- let(:locale_array) { ["en_CA.utf8", "en_US.utf8", "en_NZ.utf8"] }
452
- let(:expected_locale) { "en_US.UTF-8" }
453
- end
454
- end
455
-
456
- context "when the result includes 'en.UTF-8'" do
457
- include_examples "a suitable locale" do
458
- let(:locale_array) { ["en.ISO8859-1", expected_locale] }
459
- let(:expected_locale) { "en.UTF-8" }
460
- end
461
- end
462
-
463
- context "when the result includes 'en_*.UTF-8'" do
464
- include_examples "a suitable locale" do
465
- let(:locale_array) { [expected_locale, "en_CA.UTF-8", "en_GB.UTF-8"] }
466
- let(:expected_locale) { "en_AU.UTF-8" }
467
- end
468
- end
469
-
470
- context "when the result includes 'en_*.utf8'" do
471
- include_examples "a suitable locale" do
472
- let(:locale_array) { ["en_AU.utf8", "en_CA.utf8", "en_GB.utf8"] }
473
- let(:expected_locale) { "en_AU.UTF-8" }
474
- end
475
- end
476
-
477
- context "when the result does not include 'en_*.UTF-8'" do
478
- let(:locale_array) { ["af_ZA", "af_ZA.ISO8859-1", "af_ZA.ISO8859-15", "af_ZA.UTF-8"] }
479
-
480
- it "should fall back to C locale" do
481
- expect(Chef::Log).to receive(:warn).with("Please install an English UTF-8 locale for Chef to use, falling back to C locale and disabling UTF-8 support.")
482
- expect(Chef::Config.guess_internal_locale).to eq 'C'
483
- end
484
- end
485
-
486
- context "on error" do
487
- let(:locale_array) { [] }
488
-
489
- before do
490
- allow(Chef::Config).to receive(:shell_out_with_systems_locale!).and_raise("THIS IS AN ERROR")
491
- end
492
-
493
- it "should default to 'en_US.UTF-8'" do
494
- if is_windows
495
- expect(Chef::Log).to receive(:debug).with("Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else.")
496
- else
497
- expect(Chef::Log).to receive(:debug).with("No usable locale -a command found, assuming you have en_US.UTF-8 installed.")
498
- end
499
- expect(Chef::Config.guess_internal_locale).to eq "en_US.UTF-8"
500
- end
501
- end
502
- end
503
- end
504
- end
505
-
506
- describe "Treating deprecation warnings as errors" do
507
-
508
- context "when using our default RSpec configuration" do
509
-
510
- it "defaults to treating deprecation warnings as errors" do
511
- expect(Chef::Config[:treat_deprecation_warnings_as_errors]).to be(true)
512
- end
513
-
514
- it "sets CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS environment variable" do
515
- expect(ENV['CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS']).to eq("1")
516
- end
517
-
518
- it "treats deprecation warnings as errors in child processes when testing" do
519
- # Doing a full integration test where we launch a child process is slow
520
- # and liable to break for weird reasons (bundler env stuff, etc.), so
521
- # we're just checking that the presence of the environment variable
522
- # causes treat_deprecation_warnings_as_errors to be set to true after a
523
- # config reset.
524
- Chef::Config.reset
525
- expect(Chef::Config[:treat_deprecation_warnings_as_errors]).to be(true)
526
- end
527
-
528
- end
529
-
530
- context "outside of our test environment" do
531
-
532
- before do
533
- ENV.delete('CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS')
534
- Chef::Config.reset
535
- end
536
-
537
- it "defaults to NOT treating deprecation warnings as errors" do
538
- expect(Chef::Config[:treat_deprecation_warnings_as_errors]).to be(false)
539
- end
540
- end
541
-
542
-
543
- end
544
- end