microwave 1.0.4 → 11.400.2

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 (249) hide show
  1. data/CONTRIBUTING.md +155 -0
  2. data/README.md +89 -0
  3. data/Rakefile +2 -2
  4. data/bin/chef-apply +25 -0
  5. data/bin/chef-shell +34 -0
  6. data/bin/chef-solo +0 -2
  7. data/bin/shef +6 -5
  8. data/lib/chef.rb +2 -4
  9. data/spec/data/big_json.json +2 -1
  10. data/spec/data/big_json_plus_one.json +2 -1
  11. data/spec/data/cookbooks/chefignore +2 -0
  12. data/spec/data/cookbooks/openldap/attributes/default.rb +10 -9
  13. data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -1
  14. data/spec/data/git_bundles/sinatra-test-app-with-callback-files.gitbundle +0 -0
  15. data/spec/data/git_bundles/sinatra-test-app-with-symlinks.gitbundle +0 -0
  16. data/spec/data/git_bundles/sinatra-test-app.gitbundle +0 -0
  17. data/spec/data/lwrp/providers/inline_compiler.rb +26 -0
  18. data/spec/data/nodes/default.rb +3 -3
  19. data/spec/data/nodes/test.example.com.rb +3 -3
  20. data/spec/data/nodes/test.rb +3 -3
  21. data/spec/data/partial_one.erb +1 -0
  22. data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +4 -0
  23. data/spec/data/run_context/cookbooks/circular-dep1/definitions/circular_dep1_res.rb +1 -0
  24. data/spec/data/run_context/cookbooks/circular-dep1/libraries/lib.rb +2 -0
  25. data/spec/data/run_context/cookbooks/circular-dep1/metadata.rb +2 -0
  26. data/spec/data/run_context/cookbooks/circular-dep1/providers/provider.rb +1 -0
  27. data/spec/data/run_context/cookbooks/circular-dep1/recipes/default.rb +0 -0
  28. data/spec/data/run_context/cookbooks/circular-dep1/resources/resource.rb +1 -0
  29. data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +3 -0
  30. data/spec/data/run_context/cookbooks/circular-dep2/definitions/circular_dep2_res.rb +1 -0
  31. data/spec/data/run_context/cookbooks/circular-dep2/libraries/lib.rb +2 -0
  32. data/spec/data/run_context/cookbooks/circular-dep2/metadata.rb +2 -0
  33. data/spec/data/run_context/cookbooks/circular-dep2/providers/provider.rb +1 -0
  34. data/spec/data/run_context/cookbooks/circular-dep2/recipes/default.rb +0 -0
  35. data/spec/data/run_context/cookbooks/circular-dep2/resources/resource.rb +1 -0
  36. data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -0
  37. data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -0
  38. data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +3 -0
  39. data/spec/data/run_context/cookbooks/dependency1/definitions/dependency1_res.rb +1 -0
  40. data/spec/data/run_context/cookbooks/dependency1/libraries/lib.rb +2 -0
  41. data/spec/data/run_context/cookbooks/dependency1/providers/provider.rb +1 -0
  42. data/spec/data/run_context/cookbooks/dependency1/recipes/default.rb +0 -0
  43. data/spec/data/run_context/cookbooks/dependency1/resources/resource.rb +1 -0
  44. data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +3 -0
  45. data/spec/data/run_context/cookbooks/dependency2/definitions/dependency2_res.rb +1 -0
  46. data/spec/data/run_context/cookbooks/dependency2/libraries/lib.rb +2 -0
  47. data/spec/data/run_context/cookbooks/dependency2/providers/provider.rb +1 -0
  48. data/spec/data/run_context/cookbooks/dependency2/recipes/default.rb +0 -0
  49. data/spec/data/run_context/cookbooks/dependency2/resources/resource.rb +1 -0
  50. data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +3 -0
  51. data/spec/data/run_context/cookbooks/no-default-attr/definitions/no_default-attr_res.rb +1 -0
  52. data/spec/data/run_context/cookbooks/no-default-attr/providers/provider.rb +1 -0
  53. data/spec/data/run_context/cookbooks/no-default-attr/recipes/default.rb +0 -0
  54. data/spec/data/run_context/cookbooks/no-default-attr/resources/resource.rb +1 -0
  55. data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +3 -0
  56. data/spec/data/run_context/cookbooks/test-with-circular-deps/definitions/test_with-circular-deps_res.rb +1 -0
  57. data/spec/data/run_context/cookbooks/test-with-circular-deps/libraries/lib.rb +2 -0
  58. data/spec/data/run_context/cookbooks/test-with-circular-deps/metadata.rb +2 -0
  59. data/spec/data/run_context/cookbooks/test-with-circular-deps/providers/provider.rb +1 -0
  60. data/spec/data/run_context/cookbooks/test-with-circular-deps/recipes/default.rb +0 -0
  61. data/spec/data/run_context/cookbooks/test-with-circular-deps/resources/resource.rb +1 -0
  62. data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +3 -0
  63. data/spec/data/run_context/cookbooks/test-with-deps/definitions/test_with-deps_res.rb +1 -0
  64. data/spec/data/run_context/cookbooks/test-with-deps/libraries/lib.rb +1 -0
  65. data/spec/data/run_context/cookbooks/test-with-deps/metadata.rb +3 -0
  66. data/spec/data/run_context/cookbooks/test-with-deps/providers/provider.rb +1 -0
  67. data/spec/data/run_context/cookbooks/test-with-deps/recipes/default.rb +0 -0
  68. data/spec/data/run_context/cookbooks/test-with-deps/recipes/server.rb +0 -0
  69. data/spec/data/run_context/cookbooks/test-with-deps/resources/resource.rb +1 -0
  70. data/spec/data/run_context/cookbooks/test/attributes/default.rb +0 -0
  71. data/spec/data/run_context/cookbooks/test/attributes/george.rb +1 -1
  72. data/spec/data/run_context/cookbooks/test/definitions/test_res.rb +1 -0
  73. data/spec/data/run_context/cookbooks/test/providers/provider.rb +1 -0
  74. data/spec/data/run_context/cookbooks/test/resources/resource.rb +1 -0
  75. data/spec/data/shef-config.rb +10 -0
  76. data/spec/functional/dsl/registry_helper_spec.rb +63 -0
  77. data/spec/functional/knife/cookbook_delete_spec.rb +0 -2
  78. data/spec/functional/knife/exec_spec.rb +4 -6
  79. data/spec/functional/knife/smoke_test.rb +34 -0
  80. data/spec/functional/knife/ssh_spec.rb +64 -3
  81. data/spec/functional/resource/cookbook_file_spec.rb +33 -2
  82. data/spec/functional/resource/deploy_revision_spec.rb +515 -0
  83. data/spec/functional/resource/directory_spec.rb +4 -0
  84. data/spec/functional/resource/file_spec.rb +56 -22
  85. data/spec/functional/resource/link_spec.rb +12 -10
  86. data/spec/functional/resource/registry_spec.rb +572 -0
  87. data/spec/functional/resource/remote_directory_spec.rb +142 -36
  88. data/spec/functional/resource/remote_file_spec.rb +28 -3
  89. data/spec/functional/resource/template_spec.rb +23 -2
  90. data/spec/functional/run_lock_spec.rb +238 -0
  91. data/spec/functional/shell_spec.rb +101 -0
  92. data/spec/functional/tiny_server_spec.rb +5 -4
  93. data/spec/functional/win32/registry_helper_spec.rb +632 -0
  94. data/spec/functional/win32/security_spec.rb +37 -0
  95. data/spec/spec_helper.rb +15 -3
  96. data/spec/stress/win32/security_spec.rb +5 -5
  97. data/spec/support/chef_helpers.rb +14 -3
  98. data/spec/support/lib/chef/resource/cat.rb +3 -5
  99. data/spec/support/lib/chef/resource/one_two_three_four.rb +8 -10
  100. data/spec/support/lib/chef/resource/zen_master.rb +8 -10
  101. data/spec/support/matchers/leak.rb +1 -1
  102. data/spec/support/platform_helpers.rb +18 -0
  103. data/spec/support/shared/functional/directory_resource.rb +85 -23
  104. data/spec/support/shared/functional/file_resource.rb +198 -53
  105. data/spec/support/shared/functional/securable_resource.rb +140 -105
  106. data/spec/support/shared/functional/securable_resource_with_reporting.rb +375 -0
  107. data/spec/support/shared/unit/file_system_support.rb +110 -0
  108. data/spec/support/shared/unit/platform_introspector.rb +162 -0
  109. data/spec/tiny_server.rb +29 -10
  110. data/spec/unit/api_client/registration_spec.rb +172 -0
  111. data/spec/unit/api_client_spec.rb +156 -103
  112. data/spec/unit/application/apply.rb +84 -0
  113. data/spec/unit/application/knife_spec.rb +5 -0
  114. data/spec/unit/application_spec.rb +57 -2
  115. data/spec/unit/chef_fs/diff_spec.rb +329 -0
  116. data/spec/unit/chef_fs/file_pattern_spec.rb +526 -0
  117. data/spec/unit/chef_fs/file_system/chef_server_root_dir_spec.rb +237 -0
  118. data/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb +568 -0
  119. data/spec/unit/chef_fs/file_system/data_bags_dir_spec.rb +220 -0
  120. data/spec/unit/chef_fs/file_system_spec.rb +136 -0
  121. data/spec/unit/client_spec.rb +188 -16
  122. data/spec/unit/config_spec.rb +54 -4
  123. data/spec/unit/cookbook/chefignore_spec.rb +2 -1
  124. data/spec/unit/cookbook/syntax_check_spec.rb +48 -109
  125. data/spec/unit/cookbook_loader_spec.rb +153 -91
  126. data/spec/unit/cookbook_manifest_spec.rb +81 -81
  127. data/spec/unit/cookbook_spec.rb +3 -20
  128. data/spec/unit/cookbook_version_spec.rb +23 -122
  129. data/spec/unit/digester_spec.rb +50 -0
  130. data/spec/unit/dsl/data_query_spec.rb +66 -0
  131. data/spec/unit/dsl/platform_introspection_spec.rb +130 -0
  132. data/spec/unit/dsl/regsitry_helper_spec.rb +55 -0
  133. data/spec/unit/encrypted_data_bag_item_spec.rb +126 -10
  134. data/spec/unit/environment_spec.rb +0 -130
  135. data/spec/unit/exceptions_spec.rb +2 -3
  136. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +23 -3
  137. data/spec/unit/json_compat_spec.rb +69 -0
  138. data/spec/unit/knife/bootstrap_spec.rb +81 -28
  139. data/spec/unit/knife/client_reregister_spec.rb +23 -22
  140. data/spec/unit/knife/configure_spec.rb +29 -26
  141. data/spec/unit/knife/cookbook_metadata_spec.rb +11 -4
  142. data/spec/unit/knife/cookbook_site_install_spec.rb +12 -2
  143. data/spec/unit/knife/cookbook_test_spec.rb +1 -0
  144. data/spec/unit/knife/cookbook_upload_spec.rb +41 -2
  145. data/spec/unit/knife/core/bootstrap_context_spec.rb +8 -1
  146. data/spec/unit/knife/core/ui_spec.rb +156 -7
  147. data/spec/unit/knife/data_bag_create_spec.rb +14 -0
  148. data/spec/unit/knife/data_bag_edit_spec.rb +14 -4
  149. data/spec/unit/knife/data_bag_from_file_spec.rb +17 -5
  150. data/spec/unit/knife/data_bag_show_spec.rb +11 -4
  151. data/spec/unit/knife/index_rebuild_spec.rb +96 -33
  152. data/spec/unit/knife/knife_help.rb +7 -7
  153. data/spec/unit/knife/node_run_list_remove_spec.rb +2 -1
  154. data/spec/unit/knife/ssh_spec.rb +121 -15
  155. data/spec/unit/knife/status_spec.rb +2 -2
  156. data/spec/unit/knife/user_create_spec.rb +86 -0
  157. data/spec/unit/knife/user_delete_spec.rb +39 -0
  158. data/spec/unit/knife/user_edit_spec.rb +42 -0
  159. data/spec/unit/knife/user_list_spec.rb +32 -0
  160. data/spec/unit/knife/user_reregister_spec.rb +53 -0
  161. data/spec/unit/knife/user_show_spec.rb +41 -0
  162. data/spec/unit/knife_spec.rb +53 -0
  163. data/spec/unit/lwrp_spec.rb +59 -17
  164. data/spec/unit/mixin/checksum_spec.rb +2 -2
  165. data/spec/unit/mixin/deep_merge_spec.rb +56 -491
  166. data/spec/unit/mixin/deprecation_spec.rb +23 -0
  167. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +6 -1
  168. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  169. data/spec/unit/mixin/securable_spec.rb +5 -3
  170. data/spec/unit/mixin/template_spec.rb +119 -0
  171. data/spec/unit/node/attribute_spec.rb +272 -137
  172. data/spec/unit/node/immutable_collections_spec.rb +139 -0
  173. data/spec/unit/node_spec.rb +411 -339
  174. data/spec/unit/platform_spec.rb +8 -8
  175. data/spec/unit/provider/breakpoint_spec.rb +8 -8
  176. data/spec/unit/provider/cookbook_file_spec.rb +4 -8
  177. data/spec/unit/provider/deploy/revision_spec.rb +2 -8
  178. data/spec/unit/provider/deploy_spec.rb +6 -40
  179. data/spec/unit/provider/directory_spec.rb +103 -68
  180. data/spec/unit/provider/erl_call_spec.rb +0 -2
  181. data/spec/unit/provider/file_spec.rb +69 -59
  182. data/spec/unit/provider/git_spec.rb +0 -10
  183. data/spec/unit/provider/group/groupadd_spec.rb +1 -1
  184. data/spec/unit/provider/group/usermod_spec.rb +2 -2
  185. data/spec/unit/provider/http_request_spec.rb +28 -69
  186. data/spec/unit/provider/ifconfig_spec.rb +2 -2
  187. data/spec/unit/provider/link_spec.rb +1 -1
  188. data/spec/unit/provider/ohai_spec.rb +4 -4
  189. data/spec/unit/provider/package/apt_spec.rb +0 -1
  190. data/spec/unit/provider/package/ips_spec.rb +0 -1
  191. data/spec/unit/provider/package/rubygems_spec.rb +0 -18
  192. data/spec/unit/provider/package/yum_spec.rb +79 -15
  193. data/spec/unit/provider/package_spec.rb +7 -5
  194. data/spec/unit/provider/registry_key_spec.rb +269 -0
  195. data/spec/unit/provider/remote_directory_spec.rb +24 -7
  196. data/spec/unit/provider/remote_file_spec.rb +36 -0
  197. data/spec/unit/provider/route_spec.rb +3 -6
  198. data/spec/unit/provider/ruby_block_spec.rb +8 -0
  199. data/spec/unit/provider/service/arch_service_spec.rb +4 -4
  200. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  201. data/spec/unit/provider/service/freebsd_service_spec.rb +4 -4
  202. data/spec/unit/provider/service/init_service_spec.rb +26 -3
  203. data/spec/unit/provider/service/insserv_service_spec.rb +1 -1
  204. data/spec/unit/provider/service/invokercd_service_spec.rb +3 -3
  205. data/spec/unit/provider/service/redhat_spec.rb +1 -1
  206. data/spec/unit/provider/service/simple_service_spec.rb +3 -3
  207. data/spec/unit/provider/service/upstart_service_spec.rb +7 -7
  208. data/spec/unit/provider/service_spec.rb +2 -2
  209. data/spec/unit/provider/subversion_spec.rb +1 -1
  210. data/spec/unit/provider/template_spec.rb +35 -11
  211. data/spec/unit/provider/user/dscl_spec.rb +57 -31
  212. data/spec/unit/provider/user_spec.rb +7 -16
  213. data/spec/unit/provider_spec.rb +4 -3
  214. data/spec/unit/recipe_spec.rb +10 -8
  215. data/spec/unit/registry_helper_spec.rb +376 -0
  216. data/spec/unit/resource/log_spec.rb +9 -0
  217. data/spec/unit/resource/registry_key_spec.rb +171 -0
  218. data/spec/unit/resource/remote_file_spec.rb +21 -23
  219. data/spec/unit/resource/ruby_block_spec.rb +7 -3
  220. data/spec/unit/resource/service_spec.rb +11 -0
  221. data/spec/unit/resource_spec.rb +27 -4
  222. data/spec/unit/rest/auth_credentials_spec.rb +2 -14
  223. data/spec/unit/rest_spec.rb +122 -187
  224. data/spec/unit/run_context/cookbook_compiler_spec.rb +181 -0
  225. data/spec/unit/run_context_spec.rb +18 -4
  226. data/spec/unit/run_list_spec.rb +0 -209
  227. data/spec/unit/run_lock_spec.rb +37 -0
  228. data/spec/unit/runner_spec.rb +101 -2
  229. data/spec/unit/scan_access_control_spec.rb +4 -4
  230. data/spec/unit/{shef → shell}/model_wrapper_spec.rb +5 -5
  231. data/spec/unit/{shef/shef_ext_spec.rb → shell/shell_ext_spec.rb} +21 -21
  232. data/spec/unit/{shef/shef_session_spec.rb → shell/shell_session_spec.rb} +12 -12
  233. data/spec/unit/shell_out_spec.rb +18 -0
  234. data/spec/unit/{shef_spec.rb → shell_spec.rb} +20 -20
  235. data/spec/unit/user_spec.rb +255 -0
  236. metadata +162 -157
  237. data/README.rdoc +0 -177
  238. data/spec/unit/certificate_spec.rb +0 -76
  239. data/spec/unit/checksum_cache_spec.rb +0 -209
  240. data/spec/unit/checksum_spec.rb +0 -94
  241. data/spec/unit/couchdb_spec.rb +0 -274
  242. data/spec/unit/index_queue_spec.rb +0 -391
  243. data/spec/unit/json_compat_spect.rb +0 -53
  244. data/spec/unit/mixin/language_spec.rb +0 -305
  245. data/spec/unit/openid_registration_spec.rb +0 -153
  246. data/spec/unit/solr_query/query_transform_spec.rb +0 -454
  247. data/spec/unit/solr_query/solr_http_request_spec.rb +0 -244
  248. data/spec/unit/solr_query_spec.rb +0 -203
  249. data/spec/unit/webui_user_spec.rb +0 -238
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Serdar Sutay (<serdar@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, 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
+ if Chef::Platform.windows?
21
+ require 'chef/win32/security'
22
+ end
23
+
24
+ describe 'Chef::Win32::Security', :windows_only do
25
+ it "has_admin_privileges? returns true when running as admin" do
26
+ Chef::ReservedNames::Win32::Security.has_admin_privileges?.should == true
27
+ end
28
+
29
+ # We've done some investigation adding a negative test and it turned
30
+ # out to be a lot of work since mixlib-shellout doesn't have user
31
+ # support for windows.
32
+ #
33
+ # TODO - Add negative tests once mixlib-shellout has user support
34
+ it "has_admin_privileges? returns false when running as non-admin" do
35
+ pending "requires user support in mixlib-shellout"
36
+ end
37
+ end
data/spec/spec_helper.rb CHANGED
@@ -18,10 +18,14 @@
18
18
  # If you need to add anything in here, don't.
19
19
  # Add it to one of the files in spec/support
20
20
 
21
- ENV['MICROWAVE_ROOT'] ||= Dir.pwd
21
+ # Configure this first so it doesn't trigger annoying warning when we use it.
22
+ # Main rspec configuration comes later
23
+ RSpec.configure do |config|
24
+ config.treat_symbols_as_metadata_keys_with_true_values = true
25
+ end
22
26
 
23
27
  # Abuse ruby's constant lookup to avoid undefined constant errors
24
- module Shef
28
+ module Shell
25
29
  JUST_TESTING_MOVE_ALONG = true unless defined? JUST_TESTING_MOVE_ALONG
26
30
  IRB = nil unless defined? IRB
27
31
  end
@@ -40,10 +44,11 @@ require 'chef'
40
44
  require 'chef/knife'
41
45
  Chef::Knife.load_commands
42
46
  require 'chef/mixins'
47
+ require 'chef/dsl'
43
48
  require 'chef/application'
44
49
  require 'chef/applications'
45
50
 
46
- require 'chef/shef'
51
+ require 'chef/shell'
47
52
  require 'chef/util/file_edit'
48
53
 
49
54
  # If you want to load anything into the testing environment
@@ -66,13 +71,20 @@ RSpec.configure do |config|
66
71
  config.filter_run :focus => true
67
72
  config.filter_run_excluding :external => true
68
73
 
74
+ # Tests that randomly fail, but may have value.
75
+ config.filter_run_excluding :volatile => true
76
+
69
77
  # Add jruby filters here
70
78
  config.filter_run_excluding :windows_only => true unless windows?
79
+ config.filter_run_excluding :not_supported_on_win2k3 => true if windows_win2k3?
80
+ config.filter_run_excluding :windows64_only => true unless windows64?
81
+ config.filter_run_excluding :windows32_only => true unless windows32?
71
82
  config.filter_run_excluding :unix_only => true unless unix?
72
83
  config.filter_run_excluding :ruby_18_only => true unless ruby_18?
73
84
  config.filter_run_excluding :ruby_19_only => true unless ruby_19?
74
85
  config.filter_run_excluding :requires_root => true unless ENV['USER'] == 'root'
75
86
  config.filter_run_excluding :requires_unprivileged_user => true if ENV['USER'] == 'root'
87
+ config.filter_run_excluding :uses_diff => true unless has_diff?
76
88
 
77
89
  config.run_all_when_everything_filtered = true
78
90
  config.treat_symbols_as_metadata_keys_with_true_values = true
@@ -48,19 +48,19 @@ describe 'Chef::ReservedNames::Win32::Security', :windows_only do
48
48
  FileUtils.rm_rf(@test_tempdir)
49
49
  end
50
50
 
51
- it "should not leak when retrieving and reading the ACE from a file" do
51
+ it "should not leak when retrieving and reading the ACE from a file", :volatile do
52
52
  lambda {
53
53
  sids = Chef::ReservedNames::Win32::Security::SecurableObject.new(@monkeyfoo).security_descriptor.dacl.select { |ace| ace.sid }
54
54
  GC.start
55
55
  }.should_not leak_memory(:warmup => 50, :iterations => 100)
56
56
  end
57
57
 
58
- it "should not leak when creating a new ACL and setting it on a file" do
58
+ it "should not leak when creating a new ACL and setting it on a file", :volatile do
59
59
  securable_object = Security::SecurableObject.new(@monkeyfoo)
60
60
  lambda {
61
- securable_object.dacl = Security::ACL.create([
62
- Chef::ReservedNames::Win32::Security::ACE.access_allowed(Security::SID.Everyone, Chef::ReservedNames::Win32::API::Security::GENERIC_READ),
63
- Chef::ReservedNames::Win32::Security::ACE.access_denied(Security::SID.from_account("Users"), Chef::ReservedNames::Win32::API::Security::GENERIC_ALL)
61
+ securable_object.dacl = Chef::ReservedNames::Win32::Security::ACL.create([
62
+ Chef::ReservedNames::Win32::Security::ACE.access_allowed(Chef::ReservedNames::Win32::Security::SID.Everyone, Chef::ReservedNames::Win32::API::Security::GENERIC_READ),
63
+ Chef::ReservedNames::Win32::Security::ACE.access_denied(Chef::ReservedNames::Win32::Security::SID.from_account("Users"), Chef::ReservedNames::Win32::API::Security::GENERIC_ALL)
64
64
  ])
65
65
  GC.start
66
66
  }.should_not leak_memory(:warmup => 50, :iterations => 100)
@@ -17,8 +17,6 @@ CHEF_SPEC_DATA = File.expand_path(File.dirname(__FILE__) + "/../data/")
17
17
  CHEF_SPEC_BACKUP_PATH = File.join(Dir.tmpdir, 'test-backup-path')
18
18
 
19
19
  Chef::Config[:log_level] = :fatal
20
- Chef::Config[:cache_type] = "Memory"
21
- Chef::Config[:cache_options] = { }
22
20
  Chef::Config[:persistent_queue] = false
23
21
  Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
24
22
 
@@ -34,7 +32,7 @@ end
34
32
  # From Ruby 1.9.2+
35
33
  # Here for backwards compatibility with Ruby 1.8.7
36
34
  # http://rubydoc.info/stdlib/tmpdir/1.9.2/Dir/Tmpname
37
- def make_tmpname(prefix_suffix, n)
35
+ def make_tmpname(prefix_suffix, n = nil)
38
36
  case prefix_suffix
39
37
  when String
40
38
  prefix = prefix_suffix
@@ -50,3 +48,16 @@ def make_tmpname(prefix_suffix, n)
50
48
  path << "-#{n}" if n
51
49
  path << suffix
52
50
  end
51
+
52
+ # NOTE:
53
+ # This is a temporary fix to get tests passing on systems that have no `diff`
54
+ # until we can replace shelling out to `diff` with ruby diff-lcs
55
+ def has_diff?
56
+ begin
57
+ diff_cmd = Mixlib::ShellOut.new("diff -v")
58
+ diff_cmd.run_command
59
+ true
60
+ rescue Errno::ENOENT
61
+ false
62
+ end
63
+ end
@@ -29,12 +29,10 @@ class Chef
29
29
  end
30
30
 
31
31
  def pretty_kitty(arg=nil)
32
- set_if_args(@pretty_kitty, arg) do
33
- case arg
34
- when true, false
35
- @pretty_kitty = arg
36
- end
32
+ if arg == true or arg == false
33
+ @pretty_kitty = arg
37
34
  end
35
+ @pretty_kitty
38
36
  end
39
37
  end
40
38
  end
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,23 +20,21 @@ class Chef
20
20
  class Resource
21
21
  class OneTwoThreeFour < Chef::Resource
22
22
  attr_reader :i_can_count
23
-
23
+
24
24
  def initialize(name, run_context)
25
25
  @resource_name = :one_two_three_four
26
26
  super
27
27
  end
28
-
28
+
29
29
  def i_can_count(tf)
30
30
  @i_can_count = tf
31
31
  end
32
-
32
+
33
33
  def something(arg=nil)
34
- set_if_args(@something, arg) do
35
- case arg
36
- when true, false
37
- @something = arg
38
- end
34
+ if arg == true or arg == false
35
+ @something = arg
39
36
  end
37
+ @something
40
38
  end
41
39
  end
42
40
  end
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,23 +23,21 @@ class Chef
23
23
  class Resource
24
24
  class ZenMaster < Chef::Resource
25
25
  attr_reader :peace
26
-
26
+
27
27
  def initialize(name, run_context=nil)
28
28
  @resource_name = :zen_master
29
29
  super
30
30
  end
31
-
31
+
32
32
  def peace(tf)
33
33
  @peace = tf
34
34
  end
35
-
35
+
36
36
  def something(arg=nil)
37
- set_if_args(@something, arg) do
38
- case arg
39
- when true, false
40
- @something = arg
41
- end
37
+ if arg == true or arg == false
38
+ @something = arg
42
39
  end
40
+ @something
43
41
  end
44
42
  end
45
43
  end
@@ -60,7 +60,7 @@ module Matchers
60
60
  def profiler
61
61
  @profiler ||= begin
62
62
  if Chef::Platform.windows?
63
- require File.join(File.dirname(__FILE__), '..', 'prof', 'win32')
63
+ require File.join(File.dirname(__FILE__), '..', 'platforms', 'prof', 'win32')
64
64
  RSpec::Prof::Win32::Profiler.new
65
65
  else
66
66
  require File.join(File.dirname(__FILE__), '..', 'prof', 'gc')
@@ -10,6 +10,24 @@ def windows?
10
10
  !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
11
11
  end
12
12
 
13
+ def windows_win2k3?
14
+ return false unless windows?
15
+ require 'ruby-wmi'
16
+
17
+ host = WMI::Win32_OperatingSystem.find(:first)
18
+ (host.version && host.version.start_with?("5.2"))
19
+ end
20
+
21
+ # detects if the hardware is 64-bit (evaluates to true in "WOW64" mode in a 32-bit app on a 64-bit system)
22
+ def windows64?
23
+ windows? && ( ENV['PROCESSOR_ARCHITECTURE'] == 'AMD64' || ENV['PROCESSOR_ARCHITEW6432'] == 'AMD64' )
24
+ end
25
+
26
+ # detects if the hardware is 32-bit
27
+ def windows32?
28
+ windows? && !windows64?
29
+ end
30
+
13
31
  # def jruby?
14
32
 
15
33
  def unix?
@@ -17,42 +17,104 @@
17
17
  #
18
18
 
19
19
  shared_examples_for "a directory resource" do
20
+
21
+ let(:expect_updated?) {true}
22
+
20
23
  context "when the target directory does not exist" do
21
- it "creates the directory when the :create action is run" do
22
- resource.run_action(:create)
23
- File.should exist(path)
24
+ before do
25
+ # assert pre-condition
26
+ File.should_not exist(path)
24
27
  end
25
28
 
26
- it "recursively creates required directories if requested" do
27
- resource.recursive(true)
28
- recursive_path = File.join(path, 'red-headed-stepchild')
29
- resource.path(recursive_path)
30
- resource.run_action(:create)
31
- File.should exist(path)
32
- File.should exist(recursive_path)
29
+ describe "when running action :create" do
30
+ context "and the recursive option is not set" do
31
+ before do
32
+ resource.run_action(:create)
33
+ end
34
+
35
+ it "creates the directory when the :create action is run" do
36
+ File.should exist(path)
37
+ end
38
+
39
+ it "is marked updated by last action" do
40
+ resource.should be_updated_by_last_action
41
+ end
42
+ end
43
+
44
+ context "and the recursive option is set" do
45
+ before do
46
+ File.should_not exist(path)
47
+
48
+ resource.recursive(true)
49
+ @recursive_path = File.join(path, 'red-headed-stepchild')
50
+ resource.path(@recursive_path)
51
+ resource.run_action(:create)
52
+ end
53
+
54
+ it "recursively creates required directories" do
55
+ File.should exist(path)
56
+ File.should exist(@recursive_path)
57
+ end
58
+
59
+ it "is marked updated by last action" do
60
+ resource.should be_updated_by_last_action
61
+ end
62
+ end
33
63
  end
34
64
  end
35
65
 
36
66
  context "when the target directory exists" do
37
67
  before(:each) do
38
- FileUtils.mkdir(path)
39
- end
68
+ # For resources such as remote_directory, simply creating the base
69
+ # directory isn't enough to test that the system is in the desired state,
70
+ # so we run the resource twice--otherwise the updated_by_last_action test
71
+ # will fail.
72
+ resource.dup.run_action(:create)
73
+ File.should exist(path)
40
74
 
41
- it "does not re-create the directory" do
42
75
  resource.run_action(:create)
43
- File.should exist(path)
44
76
  end
45
77
 
46
- it "deletes the directory when the :delete action is run" do
47
- resource.run_action(:delete)
48
- File.should_not exist(path)
78
+ describe "when running action :create" do
79
+ before do
80
+ resource.run_action(:create)
81
+ end
82
+
83
+ it "does not re-create the directory" do
84
+ File.should exist(path)
85
+ end
86
+
87
+ it "is not marked updated by last action" do
88
+ resource.should_not be_updated_by_last_action
89
+ end
49
90
  end
50
91
 
51
- it "recursively deletes directories if requested" do
52
- FileUtils.mkdir(File.join(path, 'red-headed-stepchild'))
53
- resource.recursive(true)
54
- resource.run_action(:delete)
55
- File.should_not exist(path)
92
+ describe "when running action :delete" do
93
+ context "without the recursive option" do
94
+ before do
95
+ resource.run_action(:delete)
96
+ end
97
+
98
+ it "deletes the directory" do
99
+ File.should_not exist(path)
100
+ end
101
+
102
+ it "is marked as updated by last action" do
103
+ resource.should be_updated_by_last_action
104
+ end
105
+ end
106
+
107
+ context "with the recursive option" do
108
+ before do
109
+ FileUtils.mkdir(File.join(path, 'red-headed-stepchild'))
110
+ resource.recursive(true)
111
+ resource.run_action(:delete)
112
+ end
113
+
114
+ it "recursively deletes directories" do
115
+ File.should_not exist(path)
116
+ end
117
+ end
56
118
  end
57
119
  end
58
120
 
@@ -76,7 +138,7 @@ end
76
138
 
77
139
  shared_context Chef::Resource::Directory do
78
140
  let(:path) do
79
- File.join(Dir.tmpdir, make_tmpname(directory_base, nil))
141
+ File.join(Dir.tmpdir, make_tmpname(directory_base))
80
142
  end
81
143
 
82
144
  after(:each) do
@@ -17,86 +17,203 @@
17
17
  #
18
18
 
19
19
  shared_examples_for "a file with the wrong content" do
20
- it "overwrites the file with the updated content when the :create action is run" do
21
- Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
22
- sleep 1
23
- resource.run_action(:create)
24
- File.stat(path).mtime.should > @expected_mtime
25
- sha256_checksum(path).should_not == @expected_checksum
26
- end
27
-
28
- it "doesn't overwrite the file when the :create_if_missing action is run" do
29
- sleep 1
30
- resource.run_action(:create_if_missing)
31
- File.stat(path).mtime.should == @expected_mtime
20
+ before do
21
+ # Assert starting state is as expected
22
+ File.should exist(path)
23
+ # Kinda weird, in this case @expected_checksum is the cksum of the file
24
+ # with incorrect content.
32
25
  sha256_checksum(path).should == @expected_checksum
33
26
  end
34
27
 
35
- it "should backup the existing file" do
36
- Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
37
- resource.run_action(:create)
38
- Dir.glob(backup_glob).size.should equal(1)
28
+ context "when running action :create" do
29
+ context "with backups enabled" do
30
+ before do
31
+ Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
32
+ resource.run_action(:create)
33
+ end
34
+
35
+ it "overwrites the file with the updated content when the :create action is run" do
36
+ File.stat(path).mtime.should > @expected_mtime
37
+ sha256_checksum(path).should_not == @expected_checksum
38
+ end
39
+
40
+ it "backs up the existing file" do
41
+ Dir.glob(backup_glob).size.should equal(1)
42
+ end
43
+
44
+ it "is marked as updated by last action" do
45
+ resource.should be_updated_by_last_action
46
+ end
47
+ end
48
+
49
+ context "with backups disabled" do
50
+ before do
51
+ Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
52
+ resource.backup(0)
53
+ resource.run_action(:create)
54
+ end
55
+
56
+ it "should not attempt to backup the existing file if :backup == 0" do
57
+ Dir.glob(backup_glob).size.should equal(0)
58
+ end
59
+ end
39
60
  end
40
61
 
41
- it "should not attempt to backup the existing file if :backup == 0" do
42
- Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
43
- resource.backup(0)
44
- resource.run_action(:create)
45
- Dir.glob(backup_glob).size.should equal(0)
62
+ describe "when running action :create_if_missing" do
63
+ before do
64
+ resource.run_action(:create_if_missing)
65
+ end
66
+
67
+ it "doesn't overwrite the file when the :create_if_missing action is run" do
68
+ File.stat(path).mtime.should == @expected_mtime
69
+ sha256_checksum(path).should == @expected_checksum
70
+ end
71
+
72
+ it "is not marked as updated" do
73
+ resource.should_not be_updated_by_last_action
74
+ end
46
75
  end
47
76
 
48
- it "deletes the file when the :delete action is run" do
49
- resource.run_action(:delete)
50
- File.should_not exist(path)
77
+ describe "when running action :delete" do
78
+ before do
79
+ resource.run_action(:delete)
80
+ end
81
+
82
+ it "deletes the file" do
83
+ File.should_not exist(path)
84
+ end
85
+
86
+ it "is marked as updated by last action" do
87
+ resource.should be_updated_by_last_action
88
+ end
51
89
  end
52
90
  end
53
91
 
54
92
  shared_examples_for "a file with the correct content" do
55
- it "does not overwrite the original when the :create action is run" do
56
- resource.run_action(:create)
93
+ before do
94
+ # Assert starting state is as expected
95
+ File.should exist(path)
57
96
  sha256_checksum(path).should == @expected_checksum
58
97
  end
59
98
 
60
- it "does not update the mtime/atime of the file when the :create action is run" do
61
- sleep 1
62
- File.stat(path).mtime.should == @expected_mtime
63
- File.stat(path).atime.should be_within(2).of(@expected_atime)
99
+ describe "when running action :create" do
100
+ before do
101
+ resource.run_action(:create)
102
+ end
103
+ it "does not overwrite the original when the :create action is run" do
104
+ sha256_checksum(path).should == @expected_checksum
105
+ end
106
+
107
+ it "does not update the mtime of the file when the :create action is run" do
108
+ File.stat(path).mtime.should == @expected_mtime
109
+ end
110
+
111
+ it "is not marked as updated by last action" do
112
+ resource.should_not be_updated_by_last_action
113
+ end
64
114
  end
65
115
 
66
- it "doesn't overwrite the file when the :create_if_missing action is run" do
67
- resource.run_action(:create_if_missing)
68
- sha256_checksum(path).should == @expected_checksum
116
+ describe "when running action :create_if_missing" do
117
+ before do
118
+ resource.run_action(:create_if_missing)
119
+ end
120
+
121
+ it "doesn't overwrite the file when the :create_if_missing action is run" do
122
+ sha256_checksum(path).should == @expected_checksum
123
+ end
124
+
125
+ it "is not marked as updated by last action" do
126
+ resource.should_not be_updated_by_last_action
127
+ end
69
128
  end
70
129
 
71
- it "deletes the file when the :delete action is run" do
72
- resource.run_action(:delete)
73
- File.should_not exist(path)
130
+ describe "when running action :delete" do
131
+ before do
132
+ resource.run_action(:delete)
133
+ end
134
+
135
+ it "deletes the file when the :delete action is run" do
136
+ File.should_not exist(path)
137
+ end
138
+
139
+ it "is marked as updated by last action" do
140
+ resource.should be_updated_by_last_action
141
+ end
74
142
  end
75
143
  end
76
144
 
77
145
  shared_examples_for "a file resource" do
146
+ before do
147
+ Chef::Log.level = :info
148
+ end
78
149
  # note the stripping of the drive letter from the tmpdir on windows
79
150
  let(:backup_glob) { File.join(CHEF_SPEC_BACKUP_PATH, Dir.tmpdir.sub(/^([A-Za-z]:)/, ""), "#{file_base}*") }
80
151
 
152
+ # Most tests update the resource, but a few do not. We need to test that the
153
+ # resource is marked updated or not correctly, but the test contexts are
154
+ # composed between correct/incorrect content and correct/incorrect
155
+ # permissions. We override this "let" definition in the context where content
156
+ # and permissions are correct.
157
+ let(:expect_updated?) { true }
158
+
159
+ def binread(file)
160
+ content = File.open(file, "rb") do |f|
161
+ f.read
162
+ end
163
+ content.force_encoding(Encoding::BINARY) if "".respond_to?(:force_encoding)
164
+ content
165
+ end
166
+
81
167
  context "when the target file does not exist" do
82
- it "creates the file when the :create action is run" do
83
- resource.run_action(:create)
84
- File.should exist(path)
168
+ before do
169
+ # Assert starting state is expected
170
+ File.should_not exist(path)
85
171
  end
86
172
 
87
- it "creates the file with the correct content when the :create action is run" do
88
- resource.run_action(:create)
89
- IO.read(path).should == expected_content
173
+ describe "when running action :create" do
174
+ before do
175
+ resource.run_action(:create)
176
+ end
177
+
178
+ it "creates the file when the :create action is run" do
179
+ File.should exist(path)
180
+ end
181
+
182
+ it "creates the file with the correct content when the :create action is run" do
183
+ binread(path).should == expected_content
184
+ end
185
+
186
+ it "is marked as updated by last action" do
187
+ resource.should be_updated_by_last_action
188
+ end
90
189
  end
91
190
 
92
- it "creates the file with the correct content when the :create_if_missing action is run" do
93
- resource.run_action(:create_if_missing)
94
- IO.read(path).should == expected_content
191
+ describe "when running action :create_if_missing" do
192
+ before do
193
+ resource.run_action(:create_if_missing)
194
+ end
195
+
196
+ it "creates the file with the correct content" do
197
+ binread(path).should == expected_content
198
+ end
199
+
200
+ it "is marked as updated by last action" do
201
+ resource.should be_updated_by_last_action
202
+ end
95
203
  end
96
204
 
97
- it "deletes the file when the :delete action is run" do
98
- resource.run_action(:delete)
99
- File.should_not exist(path)
205
+ describe "when running action :delete" do
206
+ before do
207
+ resource.run_action(:delete)
208
+ end
209
+
210
+ it "deletes the file when the :delete action is run" do
211
+ File.should_not exist(path)
212
+ end
213
+
214
+ it "is not marked updated by last action" do
215
+ resource.should_not be_updated_by_last_action
216
+ end
100
217
  end
101
218
  end
102
219
 
@@ -112,7 +229,10 @@ shared_examples_for "a file resource" do
112
229
 
113
230
  context "when the target file has the wrong content" do
114
231
  before(:each) do
115
- File.open(path, "w") { |f| f.print "This is so wrong!!!" }
232
+ File.open(path, "wb") { |f| f.print "This is so wrong!!!" }
233
+ now = Time.now.to_i
234
+ File.utime(now - 9000, now - 9000, path)
235
+
116
236
  @expected_mtime = File.stat(path).mtime
117
237
  @expected_checksum = sha256_checksum(path)
118
238
  end
@@ -129,20 +249,27 @@ shared_examples_for "a file resource" do
129
249
  include_context "setup broken permissions"
130
250
 
131
251
  it_behaves_like "a file with the wrong content"
132
-
252
+
133
253
  it_behaves_like "a securable resource"
134
254
  end
135
255
  end
136
256
 
137
257
  context "when the target file has the correct content" do
138
258
  before(:each) do
139
- File.open(path, "w") { |f| f.print expected_content }
259
+ File.open(path, "wb") { |f| f.print expected_content }
260
+ now = Time.now.to_i
261
+ File.utime(now - 9000, now - 9000, path)
262
+
140
263
  @expected_mtime = File.stat(path).mtime
141
- @expected_atime = File.stat(path).atime
142
264
  @expected_checksum = sha256_checksum(path)
143
265
  end
144
266
 
145
267
  describe "and the target file has the correct permissions" do
268
+
269
+ # When permissions and content are correct, chef should do nothing and
270
+ # the resource should not be marked updated.
271
+ let(:expect_updated?) { false }
272
+
146
273
  include_context "setup correct permissions"
147
274
 
148
275
  it_behaves_like "a file with the correct content"
@@ -159,11 +286,29 @@ shared_examples_for "a file resource" do
159
286
  end
160
287
  end
161
288
 
289
+ it_behaves_like "a file that inherits permissions from a parent directory"
290
+
291
+ end
292
+
293
+ shared_examples_for "a file that inherits permissions from a parent directory" do
294
+ include_context "use Windows permissions"
295
+ context "on Windows", :windows_only do
296
+ it "has only inherited aces if no explicit aces were specified" do
297
+ File.exist?(path).should == false
298
+
299
+ resource.run_action(:create)
300
+
301
+ descriptor.dacl_inherits?.should == true
302
+ descriptor.dacl.each do | ace |
303
+ ace.inherited?.should == true
304
+ end
305
+ end
306
+ end
162
307
  end
163
308
 
164
309
  shared_context Chef::Resource::File do
165
310
  let(:path) do
166
- File.join(Dir.tmpdir, make_tmpname(file_base, nil))
311
+ File.join(Dir.tmpdir, make_tmpname(file_base))
167
312
  end
168
313
 
169
314
  after(:each) do