microwave 1.0.4 → 11.400.2

Sign up to get free protection for your applications and to get access to all the features.
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,50 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Daniel DeLeo (<dan@kallistec.com>)
4
+ # Copyright:: Copyright (c) 2009 Opscode, Inc.
5
+ # Copyright:: Copyright (c) 2009 Daniel DeLeo
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'spec_helper'
22
+
23
+ describe Chef::Digester do
24
+ before(:each) do
25
+ @cache = Chef::Digester.instance
26
+ end
27
+
28
+ describe "when computing checksums of cookbook files and templates" do
29
+
30
+ it "proxies the class method checksum_for_file to the instance" do
31
+ @cache.should_receive(:checksum_for_file).with("a_file_or_a_fail")
32
+ Chef::Digester.checksum_for_file("a_file_or_a_fail")
33
+ end
34
+
35
+ it "computes a checksum of a file" do
36
+ fixture_file = CHEF_SPEC_DATA + "/checksum/random.txt"
37
+ expected = "09ee9c8cc70501763563bcf9c218d71b2fbf4186bf8e1e0da07f0f42c80a3394"
38
+ @cache.checksum_for_file(fixture_file).should == expected
39
+ end
40
+
41
+ it "generates a checksum from a non-file IO object" do
42
+ io = StringIO.new("riseofthemachines\nriseofthechefs\n")
43
+ expected_md5 = '0e157ac1e2dd73191b76067fb6b4bceb'
44
+ @cache.generate_md5_checksum(io).should == expected_md5
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,66 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@opscode.com>)
3
+ # Copyright:: Copyright (c) 2010 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
+ require 'chef/dsl/data_query'
21
+
22
+ class DataQueryDSLTester
23
+ include Chef::DSL::DataQuery
24
+ end
25
+
26
+ describe Chef::DSL::DataQuery do
27
+ before(:each) do
28
+ @language = DataQueryDSLTester.new
29
+ @node = Hash.new
30
+ @language.stub!(:node).and_return(@node)
31
+ end
32
+
33
+ describe "when loading data bags and items" do
34
+ it "lists the items in a data bag" do
35
+ Chef::DataBag.should_receive(:load).with("bag_name").and_return("item_1" => "http://url_for/item_1", "item_2" => "http://url_for/item_2")
36
+ @language.data_bag("bag_name").sort.should == %w[item_1 item_2]
37
+ end
38
+
39
+ it "validates the name of the data bag you're trying to load" do
40
+ lambda {@language.data_bag("!# %^&& ")}.should raise_error(Chef::Exceptions::InvalidDataBagName)
41
+ end
42
+
43
+ it "fetches a data bag item" do
44
+ @item = Chef::DataBagItem.new
45
+ @item.data_bag("bag_name")
46
+ @item.raw_data = {"id" => "item_name", "FUU" => "FUU"}
47
+ Chef::DataBagItem.should_receive(:load).with("bag_name", "item_name").and_return(@item)
48
+ @language.data_bag_item("bag_name", "item_name").should == @item
49
+ end
50
+
51
+ it "validates the name of the data bag you're trying to load an item from" do
52
+ lambda {@language.data_bag_item(" %%^& ", "item_name")}.should raise_error(Chef::Exceptions::InvalidDataBagName)
53
+ end
54
+
55
+ it "validates the id of the data bag item you're trying to load" do
56
+ lambda {@language.data_bag_item("bag_name", " 987 (*&()")}.should raise_error(Chef::Exceptions::InvalidDataBagItemID)
57
+ end
58
+
59
+ it "validates that the id of the data bag item is not nil" do
60
+ lambda {@language.data_bag_item("bag_name", nil)}.should raise_error(Chef::Exceptions::InvalidDataBagItemID)
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
@@ -0,0 +1,130 @@
1
+ #
2
+ # Author:: Seth Falcon (<seth@opscode.com>)
3
+ # Copyright:: Copyright (c) 2010 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
+ require 'chef/dsl/platform_introspection'
21
+
22
+ class LanguageTester
23
+ attr_reader :node
24
+ def initialize(node)
25
+ @node = node
26
+ end
27
+ include Chef::DSL::PlatformIntrospection
28
+ end
29
+
30
+ describe "PlatformIntrospection implementors" do
31
+
32
+ let(:node) { Chef::Node.new }
33
+ let(:platform_introspector) { LanguageTester.new(node) }
34
+
35
+ it_behaves_like "a platform introspector"
36
+
37
+ end
38
+
39
+ describe Chef::DSL::PlatformIntrospection::PlatformDependentValue do
40
+ before do
41
+ platform_hash = {
42
+ :openbsd => {:default => 'free, functional, secure'},
43
+ [:redhat, :centos, :fedora, :scientific] => {:default => '"stable"'},
44
+ :ubuntu => {'10.04' => 'using upstart more', :default => 'using init more'},
45
+ :default => 'bork da bork'
46
+ }
47
+ @platform_specific_value = Chef::DSL::PlatformIntrospection::PlatformDependentValue.new(platform_hash)
48
+ end
49
+
50
+ it "returns the default value when the platform doesn't match" do
51
+ @platform_specific_value.value_for_node(:platform => :dos).should == 'bork da bork'
52
+ end
53
+
54
+ it "returns a value for a platform set as a group" do
55
+ @platform_specific_value.value_for_node(:platform => :centos).should == '"stable"'
56
+ end
57
+
58
+ it "returns a value for the platform when it was set as a symbol but fetched as a string" do
59
+ @platform_specific_value.value_for_node(:platform => "centos").should == '"stable"'
60
+ end
61
+
62
+ it "returns a value for a specific platform version" do
63
+ node = {:platform => 'ubuntu', :platform_version => '10.04'}
64
+ @platform_specific_value.value_for_node(node).should == 'using upstart more'
65
+ end
66
+
67
+ it "returns a platform-default value if the platform version doesn't match an explicit one" do
68
+ node = {:platform => 'ubuntu', :platform_version => '9.10' }
69
+ @platform_specific_value.value_for_node(node).should == 'using init more'
70
+ end
71
+
72
+ it "returns nil if there is no default and no platforms match" do
73
+ # this matches the behavior in the original implementation.
74
+ # whether or not it's correct is another matter.
75
+ platform_specific_value = Chef::DSL::PlatformIntrospection::PlatformDependentValue.new({})
76
+ platform_specific_value.value_for_node(:platform => 'foo').should be_nil
77
+ end
78
+
79
+ it "raises an argument error if the platform hash is not correctly structured" do
80
+ bad_hash = {:ubuntu => :foo} # should be :ubuntu => {:default => 'foo'}
81
+ lambda {Chef::DSL::PlatformIntrospection::PlatformDependentValue.new(bad_hash)}.should raise_error(ArgumentError)
82
+ end
83
+
84
+ end
85
+ describe Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue do
86
+ before do
87
+ @array_values = [:stop, :start, :reload]
88
+
89
+ @platform_family_hash = {
90
+ "debian" => "debian value",
91
+ [:rhel, "fedora"] => "redhatty value",
92
+ "suse" => @array_values,
93
+ :gentoo => "gentoo value",
94
+ :default => "default value"
95
+ }
96
+
97
+ @platform_family_value = Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue.new(@platform_family_hash)
98
+ end
99
+
100
+ it "returns the default value when the platform family doesn't match" do
101
+ @platform_family_value.value_for_node(:platform_family => :os2).should == 'default value'
102
+ end
103
+
104
+
105
+ it "returns a value for the platform family when it was set as a string but fetched as a symbol" do
106
+ @platform_family_value.value_for_node(:platform_family => :debian).should == "debian value"
107
+ end
108
+
109
+ it "returns a value for the platform family when it was set as a symbol but fetched as a string" do
110
+ @platform_family_value.value_for_node(:platform_family => "gentoo").should == "gentoo value"
111
+ end
112
+
113
+ it "returns an array value stored for a platform family" do
114
+ @platform_family_value.value_for_node(:platform_family => "suse").should == @array_values
115
+ end
116
+
117
+ it "returns a value for the platform family when it was set within an array hash key as a symbol" do
118
+ @platform_family_value.value_for_node(:platform_family => :rhel).should == "redhatty value"
119
+ end
120
+
121
+ it "returns a value for the platform family when it was set within an array hash key as a string" do
122
+ @platform_family_value.value_for_node(:platform_family => "fedora").should == "redhatty value"
123
+ end
124
+
125
+ it "returns nil if there is no default and no platforms match" do
126
+ platform_specific_value = Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue.new({})
127
+ platform_specific_value.value_for_node(:platform_family => 'foo').should be_nil
128
+ end
129
+
130
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # Author:: Prajakta Purohit (<prajakta@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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 "chef/dsl/registry_helper"
20
+ require "spec_helper"
21
+
22
+ describe Chef::Resource::RegistryKey do
23
+
24
+ before (:all) do
25
+ events = Chef::EventDispatch::Dispatcher.new
26
+ node = Chef::Node.new
27
+ ohai = Ohai::System.new
28
+ ohai.all_plugins
29
+ node.consume_external_attrs(ohai.data,{})
30
+ run_context = Chef::RunContext.new(node, {}, events)
31
+ @resource = Chef::Resource::new("foo", run_context)
32
+ end
33
+
34
+ context "tests registry dsl" do
35
+ it "resource can access registry_helper method registry_key_exists" do
36
+ @resource.respond_to?('registry_key_exists?').should == true
37
+ end
38
+ it "resource can access registry_helper method registry_get_values" do
39
+ @resource.respond_to?('registry_get_values').should == true
40
+ end
41
+ it "resource can access registry_helper method registry_has_subkey" do
42
+ @resource.respond_to?('registry_has_subkeys?').should == true
43
+ end
44
+ it "resource can access registry_helper method registry_get_subkeys" do
45
+ @resource.respond_to?('registry_get_subkeys').should == true
46
+ end
47
+ it "resource can access registry_helper method registry_value_exists" do
48
+ @resource.respond_to?('registry_value_exists?').should == true
49
+ end
50
+ it "resource can access registry_helper method data_value_exists" do
51
+ @resource.respond_to?('registry_data_exists?').should == true
52
+ end
53
+ end
54
+ end
55
+
@@ -19,6 +19,115 @@
19
19
  require 'spec_helper'
20
20
  require 'chef/encrypted_data_bag_item'
21
21
 
22
+ module Version1Encryptor
23
+ def self.encrypt_value(plaintext_data, key)
24
+ data = plaintext_data.to_yaml
25
+
26
+ cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
27
+ cipher.encrypt
28
+ cipher.pkcs5_keyivgen(key)
29
+ encrypted_bytes = cipher.update(data)
30
+ encrypted_bytes << cipher.final
31
+ Base64.encode64(encrypted_bytes)
32
+ end
33
+ end
34
+
35
+ describe Chef::EncryptedDataBagItem::Encryptor do
36
+
37
+ describe "generating a random IV" do
38
+ it "generates a new IV for each encryption pass" do
39
+ encryptor1 = Chef::EncryptedDataBagItem::Encryptor.new({"foo" => "bar"}, "passwd")
40
+ encryptor2 = Chef::EncryptedDataBagItem::Encryptor.new({"foo" => "bar"}, "passwd")
41
+
42
+ # No API in ruby OpenSSL to get the iv it used for the encryption back
43
+ # out. Instead we test if the encrypted data is the same. If it *is* the
44
+ # same, we assume the IV was the same each time.
45
+ encryptor1.encrypted_data.should_not == encryptor2.encrypted_data
46
+ end
47
+ end
48
+
49
+ describe "when encrypting a non-hash non-array value" do
50
+ it "serializes the value in a de-serializable way" do
51
+ encryptor = Chef::EncryptedDataBagItem::Encryptor.new(5, "passwd")
52
+ Chef::JSONCompat.from_json(encryptor.serialized_data)["json_wrapper"].should == 5
53
+ end
54
+
55
+ end
56
+
57
+ describe "wrapping secret values in an envelope" do
58
+ it "wraps the encrypted data in an envelope with the iv and version" do
59
+ encryptor = Chef::EncryptedDataBagItem::Encryptor.new({"foo" => "bar"}, "passwd")
60
+ final_data = encryptor.for_encrypted_item
61
+ final_data["encrypted_data"].should == encryptor.encrypted_data
62
+ final_data["iv"].should == Base64.encode64(encryptor.iv)
63
+ final_data["version"].should == 1
64
+ final_data["cipher"].should == "aes-256-cbc"
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ describe Chef::EncryptedDataBagItem::Decryptor do
72
+ context "when decrypting a version 1 (JSON+aes-256-cbc+random iv) encrypted value" do
73
+ before do
74
+ @encryptor = Chef::EncryptedDataBagItem::Encryptor.new({"foo" => "bar"}, "passwd")
75
+ @encrypted_value = @encryptor.for_encrypted_item
76
+
77
+ @decryptor = Chef::EncryptedDataBagItem::Decryptor.for(@encrypted_value, "passwd")
78
+ end
79
+
80
+ it "selects the correct strategy for version 1" do
81
+ @decryptor.should be_a_kind_of Chef::EncryptedDataBagItem::Decryptor::Version1Decryptor
82
+ end
83
+
84
+ it "decrypts the encrypted value" do
85
+ @decryptor.decrypted_data.should == {"json_wrapper" => {"foo" => "bar"}}.to_json
86
+ end
87
+
88
+ it "unwraps the encrypted data and returns it" do
89
+ @decryptor.for_decrypted_item.should == {"foo" => "bar"}
90
+ end
91
+
92
+ context "and the provided key is incorrect" do
93
+ before do
94
+ @decryptor = Chef::EncryptedDataBagItem::Decryptor.for(@encrypted_value, "wrong-passwd")
95
+ end
96
+
97
+ it "raises a sensible error" do
98
+ lambda { @decryptor.for_decrypted_item }.should raise_error(Chef::EncryptedDataBagItem::DecryptionFailure)
99
+ end
100
+ end
101
+
102
+ context "and the cipher is not supported" do
103
+ before do
104
+ @encrypted_value["cipher"] = "aes-256-foo"
105
+ end
106
+
107
+ it "raises a sensible error" do
108
+ lambda { @decryptor.for_decrypted_item }.should raise_error(Chef::EncryptedDataBagItem::UnsupportedCipher)
109
+ end
110
+ end
111
+
112
+ end
113
+
114
+ context "when decrypting a version 0 (YAML+aes-256-cbc+no iv) encrypted value" do
115
+ before do
116
+ @encrypted_value = Version1Encryptor.encrypt_value({"foo" => "bar"}, "passwd")
117
+
118
+ @decryptor = Chef::EncryptedDataBagItem::Decryptor.for(@encrypted_value, "passwd")
119
+ end
120
+
121
+ it "selects the correct strategy for version 0" do
122
+ @decryptor.should be_a_kind_of(Chef::EncryptedDataBagItem::Decryptor::Version0Decryptor)
123
+ end
124
+
125
+ it "decrypts the encrypted value" do
126
+ @decryptor.for_decrypted_item.should == {"foo" => "bar"}
127
+ end
128
+ end
129
+ end
130
+
22
131
  describe Chef::EncryptedDataBagItem do
23
132
  before(:each) do
24
133
  @secret = "abc123SECRET"
@@ -31,26 +140,33 @@ describe Chef::EncryptedDataBagItem do
31
140
  @secret)
32
141
  end
33
142
 
143
+
34
144
  describe "encrypting" do
35
145
 
36
146
  it "should not encrypt the 'id' key" do
37
147
  @enc_data["id"].should == "item_name"
38
148
  end
39
149
 
40
- it "should encrypt 'greeting'" do
41
- @enc_data["greeting"].should_not == @plain_data["greeting"]
42
- end
150
+ it "should encrypt non-collection objects" do
151
+ @enc_data["greeting"]["version"].should == 1
152
+ @enc_data["greeting"].should have_key("iv")
153
+
154
+ iv = @enc_data["greeting"]["iv"]
155
+ encryptor = Chef::EncryptedDataBagItem::Encryptor.new("hello", @secret, iv)
43
156
 
44
- it "should encrypt 'nested'" do
45
- nested = @enc_data["nested"]
46
- nested.class.should == String
47
- nested.should_not == @plain_data["nested"]
157
+ @enc_data["greeting"]["encrypted_data"].should == encryptor.for_encrypted_item["encrypted_data"]
48
158
  end
49
159
 
50
- it "from_plain_hash" do
51
- eh1 = Chef::EncryptedDataBagItem.from_plain_hash(@plain_data, @secret)
52
- eh1.class.should == Chef::EncryptedDataBagItem
160
+ it "should encrypt nested values" do
161
+ @enc_data["nested"]["version"].should == 1
162
+ @enc_data["nested"].should have_key("iv")
163
+
164
+ iv = @enc_data["nested"]["iv"]
165
+ encryptor = Chef::EncryptedDataBagItem::Encryptor.new(@plain_data["nested"], @secret, iv)
166
+
167
+ @enc_data["nested"]["encrypted_data"].should == encryptor.for_encrypted_item["encrypted_data"]
53
168
  end
169
+
54
170
  end
55
171
 
56
172
  describe "decrypting" do