chef 12.0.0.alpha.0 → 12.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -5
  3. data/lib/chef/api_client.rb +1 -1
  4. data/lib/chef/application.rb +16 -8
  5. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  6. data/lib/chef/chef_fs/command_line.rb +1 -1
  7. data/lib/chef/chef_fs/file_system.rb +1 -1
  8. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  9. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +3 -3
  10. data/lib/chef/chef_fs/file_system/cookbook_file.rb +2 -2
  11. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -2
  12. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -4
  13. data/lib/chef/config.rb +6 -5
  14. data/lib/chef/config_fetcher.rb +1 -1
  15. data/lib/chef/cookbook/cookbook_version_loader.rb +126 -43
  16. data/lib/chef/cookbook/metadata.rb +102 -53
  17. data/lib/chef/cookbook/syntax_check.rb +1 -1
  18. data/lib/chef/cookbook_loader.rb +62 -14
  19. data/lib/chef/cookbook_site_streaming_uploader.rb +12 -1
  20. data/lib/chef/cookbook_version.rb +13 -4
  21. data/lib/chef/data_bag.rb +28 -15
  22. data/lib/chef/data_bag_item.rb +5 -7
  23. data/lib/chef/digester.rb +5 -9
  24. data/lib/chef/dsl/recipe.rb +14 -0
  25. data/lib/chef/encrypted_data_bag_item.rb +1 -0
  26. data/lib/chef/encrypted_data_bag_item/assertions.rb +57 -0
  27. data/lib/chef/encrypted_data_bag_item/decryptor.rb +52 -28
  28. data/lib/chef/encrypted_data_bag_item/encrypted_data_bag_item_assertions.rb +37 -0
  29. data/lib/chef/encrypted_data_bag_item/encryption_failure.rb +22 -0
  30. data/lib/chef/encrypted_data_bag_item/encryptor.rb +79 -8
  31. data/lib/chef/environment.rb +1 -3
  32. data/lib/chef/exceptions.rb +18 -3
  33. data/lib/chef/formatters/base.rb +7 -0
  34. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  35. data/lib/chef/handler/json_file.rb +0 -1
  36. data/lib/chef/http/json_output.rb +1 -1
  37. data/lib/chef/json_compat.rb +24 -6
  38. data/lib/chef/knife/bootstrap.rb +2 -2
  39. data/lib/chef/knife/client_delete.rb +1 -1
  40. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  41. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  42. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  43. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  44. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  45. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  46. data/lib/chef/knife/core/node_editor.rb +2 -3
  47. data/lib/chef/knife/core/ui.rb +2 -2
  48. data/lib/chef/knife/deps.rb +2 -3
  49. data/lib/chef/mixin/shell_out.rb +1 -1
  50. data/lib/chef/mixin/windows_architecture_helper.rb +1 -0
  51. data/lib/chef/node.rb +1 -2
  52. data/lib/chef/platform/provider_mapping.rb +33 -6
  53. data/lib/chef/provider.rb +0 -2
  54. data/lib/chef/provider/cookbook_file/content.rb +1 -1
  55. data/lib/chef/provider/cron.rb +11 -0
  56. data/lib/chef/provider/deploy.rb +3 -2
  57. data/lib/chef/provider/deploy/revision.rb +2 -2
  58. data/lib/chef/provider/env.rb +1 -1
  59. data/lib/chef/provider/env/windows.rb +5 -9
  60. data/lib/chef/provider/file.rb +84 -33
  61. data/lib/chef/provider/git.rb +2 -1
  62. data/lib/chef/provider/group/aix.rb +17 -2
  63. data/lib/chef/provider/group/dscl.rb +27 -9
  64. data/lib/chef/provider/group/pw.rb +8 -1
  65. data/lib/chef/provider/http_request.rb +4 -4
  66. data/lib/chef/provider/log.rb +4 -14
  67. data/lib/chef/provider/mount/mount.rb +2 -2
  68. data/lib/chef/provider/package/ips.rb +17 -23
  69. data/lib/chef/provider/package/paludis.rb +2 -2
  70. data/lib/chef/provider/package/rpm.rb +2 -2
  71. data/lib/chef/provider/package/rubygems.rb +2 -0
  72. data/lib/chef/provider/package/yum.rb +2 -0
  73. data/lib/chef/provider/package/zypper.rb +1 -1
  74. data/lib/chef/provider/remote_file/cache_control_data.rb +2 -2
  75. data/lib/chef/provider/service/windows.rb +87 -21
  76. data/lib/chef/provider/user/aix.rb +95 -0
  77. data/lib/chef/provider/user/dscl.rb +544 -156
  78. data/lib/chef/provider/user/useradd.rb +1 -0
  79. data/lib/chef/providers.rb +1 -0
  80. data/lib/chef/resource.rb +4 -3
  81. data/lib/chef/resource/freebsd_package.rb +10 -2
  82. data/lib/chef/resource/paludis_package.rb +1 -0
  83. data/lib/chef/resource/scm.rb +10 -0
  84. data/lib/chef/resource/user.rb +27 -0
  85. data/lib/chef/resource/windows_service.rb +53 -0
  86. data/lib/chef/resource_collection.rb +23 -12
  87. data/lib/chef/resource_reporter.rb +10 -10
  88. data/lib/chef/resources.rb +1 -0
  89. data/lib/chef/role.rb +3 -3
  90. data/lib/chef/run_list.rb +6 -3
  91. data/lib/chef/user.rb +1 -1
  92. data/lib/chef/util/diff.rb +1 -2
  93. data/lib/chef/version.rb +1 -1
  94. data/lib/chef/version_constraint.rb +4 -4
  95. data/spec/data/cookbooks/angrybash/metadata.rb +2 -0
  96. data/spec/data/cookbooks/apache2/metadata.rb +2 -0
  97. data/spec/data/cookbooks/borken/metadata.rb +2 -0
  98. data/spec/data/cookbooks/ignorken/metadata.rb +2 -0
  99. data/spec/data/cookbooks/java/metadata.rb +2 -0
  100. data/spec/data/cookbooks/name-mismatch-versionnumber/README.md +4 -0
  101. data/spec/data/cookbooks/name-mismatch-versionnumber/metadata.rb +8 -0
  102. data/spec/data/cookbooks/name-mismatch-versionnumber/recipes/default.rb +8 -0
  103. data/spec/data/cookbooks/openldap/files/default/remotedir/not_a_template.erb +2 -0
  104. data/spec/data/cookbooks/preseed/metadata.rb +2 -0
  105. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/README.md +4 -0
  106. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/metadata.rb +13 -0
  107. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/recipes/default.rb +8 -0
  108. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/README.md +4 -0
  109. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/metadata.rb +10 -0
  110. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/recipes/default.rb +8 -0
  111. data/spec/data/mac_users/10.7-8.plist.xml +559 -0
  112. data/spec/data/mac_users/10.7-8.shadow.xml +11 -0
  113. data/spec/data/mac_users/10.7.plist.xml +559 -0
  114. data/spec/data/mac_users/10.7.shadow.xml +11 -0
  115. data/spec/data/mac_users/10.8.plist.xml +559 -0
  116. data/spec/data/mac_users/10.8.shadow.xml +21 -0
  117. data/spec/data/mac_users/10.9.plist.xml +560 -0
  118. data/spec/data/mac_users/10.9.shadow.xml +21 -0
  119. data/spec/data/object_loader/environments/test.json +2 -0
  120. data/spec/data/object_loader/environments/test_json_class.json +2 -0
  121. data/spec/data/object_loader/nodes/test.json +2 -0
  122. data/spec/data/object_loader/nodes/test_json_class.json +2 -0
  123. data/spec/data/object_loader/roles/test.json +2 -0
  124. data/spec/data/object_loader/roles/test_json_class.json +2 -0
  125. data/spec/functional/resource/bff_spec.rb +1 -1
  126. data/spec/functional/resource/cron_spec.rb +20 -1
  127. data/spec/functional/resource/env_spec.rb +137 -0
  128. data/spec/functional/resource/group_spec.rb +7 -5
  129. data/spec/functional/resource/remote_file_spec.rb +12 -1
  130. data/spec/functional/resource/user/dscl_spec.rb +198 -0
  131. data/spec/functional/resource/{user_spec.rb → user/useradd_spec.rb} +175 -37
  132. data/spec/integration/client/client_spec.rb +6 -4
  133. data/spec/integration/client/ipv6_spec.rb +16 -14
  134. data/spec/integration/knife/chef_fs_data_store_spec.rb +57 -46
  135. data/spec/integration/knife/chef_repo_path_spec.rb +105 -78
  136. data/spec/integration/knife/chef_repository_file_system_spec.rb +100 -84
  137. data/spec/integration/knife/chefignore_spec.rb +76 -46
  138. data/spec/integration/knife/common_options_spec.rb +16 -21
  139. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -3
  140. data/spec/integration/knife/delete_spec.rb +66 -46
  141. data/spec/integration/knife/deps_spec.rb +145 -94
  142. data/spec/integration/knife/diff_spec.rb +176 -110
  143. data/spec/integration/knife/download_spec.rb +229 -133
  144. data/spec/integration/knife/list_spec.rb +62 -54
  145. data/spec/integration/knife/raw_spec.rb +24 -9
  146. data/spec/integration/knife/redirection_spec.rb +2 -2
  147. data/spec/integration/knife/serve_spec.rb +2 -2
  148. data/spec/integration/knife/show_spec.rb +32 -26
  149. data/spec/integration/knife/upload_spec.rb +308 -165
  150. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +10 -8
  151. data/spec/integration/solo/solo_spec.rb +22 -11
  152. data/spec/spec_helper.rb +3 -0
  153. data/spec/support/lib/chef/resource/zen_follower.rb +46 -0
  154. data/spec/support/platform_helpers.rb +12 -0
  155. data/spec/support/shared/functional/file_resource.rb +10 -0
  156. data/spec/support/shared/integration/chef_zero_support.rb +130 -0
  157. data/spec/support/shared/integration/integration_helper.rb +100 -98
  158. data/spec/support/shared/integration/knife_support.rb +0 -1
  159. data/spec/support/shared/unit/provider/file.rb +6 -4
  160. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +10 -1
  161. data/spec/unit/api_client/registration_spec.rb +83 -74
  162. data/spec/unit/application_spec.rb +32 -9
  163. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +179 -0
  164. data/spec/unit/cookbook/metadata_spec.rb +190 -150
  165. data/spec/unit/cookbook/syntax_check_spec.rb +3 -2
  166. data/spec/unit/cookbook_loader_spec.rb +114 -53
  167. data/spec/unit/{cookbook_site_streaming_uploader.rb → cookbook_site_streaming_uploader_spec.rb} +21 -1
  168. data/spec/unit/data_bag_spec.rb +88 -13
  169. data/spec/unit/deprecation_spec.rb +1 -2
  170. data/spec/unit/encrypted_data_bag_item_spec.rb +145 -9
  171. data/spec/unit/environment_spec.rb +1 -1
  172. data/spec/unit/formatters/base_spec.rb +48 -0
  173. data/spec/unit/json_compat_spec.rb +48 -17
  174. data/spec/unit/knife/client_delete_spec.rb +4 -4
  175. data/spec/unit/knife/client_show_spec.rb +15 -5
  176. data/spec/unit/knife/cookbook_site_download_spec.rb +1 -1
  177. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  178. data/spec/unit/knife/data_bag_from_file_spec.rb +0 -2
  179. data/spec/unit/knife/data_bag_show_spec.rb +23 -14
  180. data/spec/unit/knife/node_show_spec.rb +32 -15
  181. data/spec/unit/knife/role_show_spec.rb +59 -0
  182. data/spec/unit/platform_spec.rb +10 -0
  183. data/spec/unit/provider/deploy_spec.rb +4 -0
  184. data/spec/unit/provider/env_spec.rb +19 -0
  185. data/spec/unit/provider/git_spec.rb +22 -2
  186. data/spec/unit/provider/group/dscl_spec.rb +38 -1
  187. data/spec/unit/provider/group/pw_spec.rb +2 -2
  188. data/spec/unit/provider/http_request_spec.rb +8 -8
  189. data/spec/unit/provider/log_spec.rb +33 -53
  190. data/spec/unit/provider/mount/mount_spec.rb +12 -3
  191. data/spec/unit/provider/package/ips_spec.rb +96 -63
  192. data/spec/unit/provider/package/paludis_spec.rb +5 -5
  193. data/spec/unit/provider/package/rpm_spec.rb +12 -0
  194. data/spec/unit/provider/package/zypper_spec.rb +28 -16
  195. data/spec/unit/provider/service/windows_spec.rb +77 -17
  196. data/spec/unit/provider/user/dscl_spec.rb +659 -264
  197. data/spec/unit/provider/user/useradd_spec.rb +1 -0
  198. data/spec/unit/recipe_spec.rb +41 -0
  199. data/spec/unit/resource/scm_spec.rb +11 -0
  200. data/spec/unit/resource/user_spec.rb +4 -0
  201. data/spec/unit/resource/windows_service_spec.rb +46 -0
  202. data/spec/unit/resource_collection_spec.rb +33 -0
  203. data/spec/unit/resource_reporter_spec.rb +48 -0
  204. data/spec/unit/resource_spec.rb +9 -2
  205. data/spec/unit/role_spec.rb +6 -0
  206. data/spec/unit/version_constraint_spec.rb +28 -0
  207. metadata +61 -4
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>SALTED-SHA512-PBKDF2</key>
6
+ <dict>
7
+ <key>entropy</key>
8
+ <data>
9
+ EmAakNsXy/i6SAjmOC+w07nYpsGhkEd79oCrIa+2BlRnE25VzCCKb3QVbj2v
10
+ IPsTNp70t7r6BH2ANZ+0akikrczVSOuzOFGwk0fMqENBp/k6JxRzQ/ifuEP7
11
+ RsABfSZK+kl2uqz5QbkVvR7ByiTDCz51ngJAPgL1n+f/WTinY2w=
12
+ </data>
13
+ <key>iterations</key>
14
+ <integer>34482</integer>
15
+ <key>salt</key>
16
+ <data>
17
+ 7pVL5HL9xg3fiUhHgUM5k2JfAGr27IEMCPSafkE5RqE=
18
+ </data>
19
+ </dict>
20
+ </dict>
21
+ </plist>
@@ -1,4 +1,6 @@
1
1
  {
2
+ /* testing that we support c-style comments */
3
+ // testing that we support c++-style comments as well
2
4
  "name": "test",
3
5
  "description": "prod",
4
6
  "run_list": []
@@ -1,4 +1,6 @@
1
1
  {
2
+ /* testing that we support c-style comments */
3
+ // testing that we support c++-style comments as well
2
4
  "name": "test",
3
5
  "json_class": "Chef::Environment",
4
6
  "description": "prod",
@@ -1,4 +1,6 @@
1
1
  {
2
+ /* testing that we support c-style comments */
3
+ // testing that we support c++-style comments as well
2
4
  "name": "test",
3
5
  "environment": "prod",
4
6
  "run_list": []
@@ -1,4 +1,6 @@
1
1
  {
2
+ /* testing that we support c-style comments */
3
+ // testing that we support c++-style comments as well
2
4
  "name": "test",
3
5
  "json_class": "Chef::Node",
4
6
  "environment": "prod",
@@ -1,4 +1,6 @@
1
1
  {
2
+ /* testing that we support c-style comments */
3
+ // testing that we support c++-style comments as well
2
4
  "name": "test",
3
5
  "description": "prod",
4
6
  "run_list": []
@@ -1,4 +1,6 @@
1
1
  {
2
+ /* testing that we support c-style comments */
3
+ // testing that we support c++-style comments as well
2
4
  "name": "test",
3
5
  "json_class": "Chef::Role",
4
6
  "description": "prod",
@@ -20,7 +20,7 @@ require 'functional/resource/base'
20
20
  require 'chef/mixin/shell_out'
21
21
 
22
22
  # Run the test only for AIX platform.
23
- describe Chef::Resource::BffPackage, :external => ohai[:platform] != 'aix' do
23
+ describe Chef::Resource::BffPackage, :requires_root, :external => ohai[:platform] != 'aix' do
24
24
  include Chef::Mixin::ShellOut
25
25
 
26
26
  let(:new_resource) do
@@ -29,10 +29,14 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
29
29
  case ohai[:platform]
30
30
  when "aix", "solaris", "opensolaris", "solaris2", "omnios"
31
31
  expect(shell_out("crontab -l #{new_resource.user} | grep \"#{cron_name}\"").exitstatus).to eq(0)
32
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{cron_name}\"").stdout.lines.to_a.size).to eq(1)
32
33
  expect(shell_out("crontab -l #{new_resource.user} | grep \"#{command}\"").exitstatus).to eq(0)
34
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{command}\"").stdout.lines.to_a.size).to eq(1)
33
35
  else
34
36
  expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{cron_name}\"").exitstatus).to eq(0)
37
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{cron_name}\"").stdout.lines.to_a.size).to eq(0)
35
38
  expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{command}\"").exitstatus).to eq(0)
39
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{command}\"").stdout.lines.to_a.size).to eq(0)
36
40
  end
37
41
  end
38
42
 
@@ -40,8 +44,10 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
40
44
  case ohai[:platform]
41
45
  when "aix", "solaris", "opensolaris", "solaris2", "omnios"
42
46
  expect(shell_out("crontab -l #{new_resource.user} | grep \"#{cron_name}\"").exitstatus).to eq(1)
47
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{new_resource.command}\"").stdout.lines.to_a.size).to eq(0)
43
48
  else
44
49
  expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{cron_name}\"").exitstatus).to eq(1)
50
+ expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{new_resource.command}\"").stdout.lines.to_a.size).to eq(0)
45
51
  end
46
52
  end
47
53
 
@@ -49,7 +55,11 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
49
55
  let(:new_resource) do
50
56
  new_resource = Chef::Resource::Cron.new("Chef functional test cron", run_context)
51
57
  new_resource.user 'root'
52
- new_resource.minute "30"
58
+ new_resource.minute '@hourly'
59
+ new_resource.hour ''
60
+ new_resource.day ''
61
+ new_resource.month ''
62
+ new_resource.weekday ''
53
63
  new_resource.command "/bin/true"
54
64
  new_resource
55
65
  end
@@ -68,6 +78,11 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
68
78
  new_resource.run_action(:create)
69
79
  cron_should_exists(new_resource.name, new_resource.command)
70
80
  end
81
+
82
+ it "should create exactly one crontab entry" do
83
+ 5.times { new_resource.run_action(:create) }
84
+ cron_should_exists(new_resource.name, new_resource.command)
85
+ end
71
86
  end
72
87
 
73
88
  describe "delete action" do
@@ -128,6 +143,10 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
128
143
  end
129
144
 
130
145
  describe "negative tests for create action" do
146
+ after do
147
+ new_resource.run_action(:delete)
148
+ end
149
+
131
150
  def cron_create_should_raise_exception
132
151
  expect { new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::Cron, /Error updating state of #{new_resource.name}, exit: 1/)
133
152
  cron_should_not_exists(new_resource.name)
@@ -0,0 +1,137 @@
1
+ #
2
+ # Author:: Adam Edwards (<adamed@getchef.com>)
3
+ # Copyright:: Copyright (c) 2014 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
+
21
+ describe Chef::Resource::Env, :windows_only do
22
+ context 'when running on Windows' do
23
+ let(:chef_env_test_lower_case) { 'chefenvtest' }
24
+ let(:chef_env_test_mixed_case) { 'chefENVtest' }
25
+ let(:env_value1) { 'value1' }
26
+ let(:env_value2) { 'value2' }
27
+ let(:test_run_context) {
28
+ node = Chef::Node.new
29
+ node.default['platform'] = 'windows'
30
+ node.default['platform_version'] = '6.1'
31
+ empty_events = Chef::EventDispatch::Dispatcher.new
32
+ Chef::RunContext.new(node, {}, empty_events)
33
+ }
34
+ let(:test_resource) {
35
+ Chef::Resource::Env.new('unknown', test_run_context)
36
+ }
37
+
38
+ before(:each) do
39
+ resource_lower = Chef::Resource::Env.new(chef_env_test_lower_case, test_run_context)
40
+ resource_lower.run_action(:delete)
41
+ resource_mixed = Chef::Resource::Env.new(chef_env_test_mixed_case, test_run_context)
42
+ resource_mixed.run_action(:delete)
43
+ end
44
+
45
+ context "when the create action is invoked" do
46
+ it 'should create an environment variable for action create' do
47
+ expect(ENV[chef_env_test_lower_case]).to eq(nil)
48
+ test_resource.key_name(chef_env_test_lower_case)
49
+ test_resource.value(env_value1)
50
+ test_resource.run_action(:create)
51
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value1)
52
+ end
53
+
54
+ it "should modify an existing variable's value to a new value" do
55
+ test_resource.key_name(chef_env_test_lower_case)
56
+ test_resource.value(env_value1)
57
+ test_resource.run_action(:create)
58
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value1)
59
+ test_resource.value(env_value2)
60
+ test_resource.run_action(:create)
61
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value2)
62
+ end
63
+
64
+ it "should modify an existing variable's value to a new value if the variable name case differs from the existing variable" do
65
+ test_resource.key_name(chef_env_test_lower_case)
66
+ test_resource.value(env_value1)
67
+ test_resource.run_action(:create)
68
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value1)
69
+ test_resource.key_name(chef_env_test_mixed_case)
70
+ test_resource.value(env_value2)
71
+ test_resource.run_action(:create)
72
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value2)
73
+ end
74
+ end
75
+
76
+ context "when the modify action is invoked" do
77
+ it "should raise an exception for modify if the variable doesn't exist" do
78
+ expect(ENV[chef_env_test_lower_case]).to eq(nil)
79
+ test_resource.key_name(chef_env_test_lower_case)
80
+ test_resource.value(env_value1)
81
+ expect {test_resource.run_action(:modify) }.to raise_error(Chef::Exceptions::Env)
82
+ end
83
+
84
+ it "should modify an existing variable's value to a new value" do
85
+ test_resource.key_name(chef_env_test_lower_case)
86
+ test_resource.value(env_value1)
87
+ test_resource.run_action(:create)
88
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value1)
89
+ test_resource.value(env_value2)
90
+ test_resource.run_action(:modify)
91
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value2)
92
+ end
93
+
94
+ # This examlpe covers Chef Issue #1754
95
+ it "should modify an existing variable's value to a new value if the variable name case differs from the existing variable" do
96
+ test_resource.key_name(chef_env_test_lower_case)
97
+ test_resource.value(env_value1)
98
+ test_resource.run_action(:create)
99
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value1)
100
+ test_resource.key_name(chef_env_test_mixed_case)
101
+ test_resource.value(env_value2)
102
+ test_resource.run_action(:modify)
103
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value2)
104
+ end
105
+ end
106
+
107
+ context "when the delete action is invoked" do
108
+ it "should delete an environment variable" do
109
+ test_resource.key_name(chef_env_test_lower_case)
110
+ test_resource.value(env_value1)
111
+ test_resource.run_action(:create)
112
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value1)
113
+ test_resource.run_action(:delete)
114
+ expect(ENV[chef_env_test_lower_case]).to eq(nil)
115
+ end
116
+
117
+ it "should not raise an exception when a non-existent environment variable is deleted" do
118
+ expect(ENV[chef_env_test_lower_case]).to eq(nil)
119
+ test_resource.key_name(chef_env_test_lower_case)
120
+ test_resource.value(env_value1)
121
+ expect{test_resource.run_action(:delete)}.not_to raise_error
122
+ expect(ENV[chef_env_test_lower_case]).to eq(nil)
123
+ end
124
+
125
+ it "should delete an existing variable's value to a new value if the specified variable name case differs from the existing variable" do
126
+ test_resource.key_name(chef_env_test_lower_case)
127
+ test_resource.value(env_value1)
128
+ test_resource.run_action(:create)
129
+ expect(ENV[chef_env_test_lower_case]).to eq(env_value1)
130
+ test_resource.key_name(chef_env_test_mixed_case)
131
+ test_resource.run_action(:delete)
132
+ expect(ENV[chef_env_test_lower_case]).to eq(nil)
133
+ expect(ENV[chef_env_test_mixed_case]).to eq(nil)
134
+ end
135
+ end
136
+ end
137
+ end
@@ -248,7 +248,7 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte
248
248
  end
249
249
  end
250
250
 
251
- let(:group_name) { "cheftest-#{SecureRandom.random_number(9999)}" }
251
+ let(:group_name) { "t-#{SecureRandom.random_number(9999)}" }
252
252
  let(:included_members) { nil }
253
253
  let(:excluded_members) { nil }
254
254
  let(:group_resource) {
@@ -330,7 +330,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" }
330
330
  end
331
331
 
332
332
  describe "group modify action", :not_supported_on_solaris do
333
- let(:spec_members){ ["spec-Gordon", "spec-Eric", "spec-Anthony"] }
333
+ let(:spec_members){ ["Gordon", "Eric", "Anthony"] }
334
334
  let(:included_members) { [spec_members[0], spec_members[1]] }
335
335
  let(:excluded_members) { [spec_members[2]] }
336
336
  let(:tested_action) { :modify }
@@ -358,7 +358,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" }
358
358
  end
359
359
 
360
360
  describe "group manage action", :not_supported_on_solaris do
361
- let(:spec_members){ ["spec-Gordon", "spec-Eric", "spec-Anthony"] }
361
+ let(:spec_members){ ["Gordon", "Eric", "Anthony"] }
362
362
  let(:included_members) { [spec_members[0], spec_members[1]] }
363
363
  let(:excluded_members) { [spec_members[2]] }
364
364
  let(:tested_action) { :manage }
@@ -388,7 +388,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" }
388
388
 
389
389
  describe "group resource with Usermod provider", :solaris_only do
390
390
  describe "when excluded_members is set" do
391
- let(:excluded_members) { ["spec-Anthony"] }
391
+ let(:excluded_members) { ["Anthony"] }
392
392
 
393
393
  it ":manage should raise an error" do
394
394
  lambda {group_resource.run_action(:manage) }.should raise_error
@@ -404,7 +404,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" }
404
404
  end
405
405
 
406
406
  describe "when append is not set" do
407
- let(:included_members) { ["spec-Gordon", "spec-Eric"] }
407
+ let(:included_members) { ["Gordon", "Eric"] }
408
408
 
409
409
  before(:each) do
410
410
  group_resource.append(false)
@@ -421,3 +421,5 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" }
421
421
  end
422
422
  end
423
423
 
424
+
425
+
@@ -73,7 +73,6 @@ describe Chef::Resource::RemoteFile do
73
73
  it "does not fetch the file" do
74
74
  resource.run_action(:create)
75
75
  end
76
-
77
76
  end
78
77
 
79
78
  context "when using normal encoding" do
@@ -225,5 +224,17 @@ describe Chef::Resource::RemoteFile do
225
224
  end
226
225
  end
227
226
 
227
+ describe "when the download of the source raises an exception" do
228
+ let(:source) { 'http://localhost:0000/seattle_capo.png' }
229
+
230
+ before do
231
+ File.should_not exist(path)
232
+ end
233
+
234
+ it "should not create the file" do
235
+ expect{ resource.run_action(:create) }.to raise_error
236
+ File.should_not exist(path)
237
+ end
238
+ end
228
239
  end
229
240
  end
@@ -0,0 +1,198 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'spec_helper'
19
+ require 'chef/mixin/shell_out'
20
+
21
+ metadata = {
22
+ :unix_only => true,
23
+ :requires_root => true,
24
+ :provider => {:user => Chef::Provider::User::Dscl}
25
+ }
26
+
27
+ describe "Chef::Resource::User with Chef::Provider::User::Dscl provider", metadata do
28
+ include Chef::Mixin::ShellOut
29
+
30
+ def clean_user
31
+ begin
32
+ shell_out!("/usr/bin/dscl . -delete '/Users/#{username}'")
33
+ rescue Mixlib::ShellOut::ShellCommandFailed
34
+ # Raised when the user is already cleaned
35
+ end
36
+ end
37
+
38
+ def user_should_exist
39
+ shell_out("/usr/bin/dscl . -ls /Users").stdout.should include username
40
+ end
41
+
42
+ def check_password(pass)
43
+ # In order to test the password we use dscl passwd command since
44
+ # that's the only command that gets the user password from CLI.
45
+ shell_out("dscl . -passwd /Users/greatchef #{pass} new_password").exitstatus.should == 0
46
+ # Now reset the password back
47
+ shell_out("dscl . -passwd /Users/greatchef new_password #{pass}").exitstatus.should == 0
48
+ end
49
+
50
+ let(:node) do
51
+ n = Chef::Node.new
52
+ n.consume_external_attrs(OHAI_SYSTEM.data.dup, {})
53
+ n
54
+ end
55
+
56
+ let(:events) do
57
+ Chef::EventDispatch::Dispatcher.new
58
+ end
59
+
60
+ let(:run_context) do
61
+ Chef::RunContext.new(node, {}, events)
62
+ end
63
+
64
+ let(:username) do
65
+ "greatchef"
66
+ end
67
+
68
+ let(:uid) { nil }
69
+ let(:gid) { 20 }
70
+ let(:home) { nil }
71
+ let(:manage_home) { false }
72
+ let(:password) { "XXXYYYZZZ" }
73
+ let(:comment) { "Great Chef" }
74
+ let(:shell) { "/bin/bash" }
75
+ let(:salt) { nil }
76
+ let(:iterations) { nil }
77
+
78
+ let(:user_resource) do
79
+ r = Chef::Resource::User.new("TEST USER RESOURCE", run_context)
80
+ r.username(username)
81
+ r.uid(uid)
82
+ r.gid(gid)
83
+ r.home(home)
84
+ r.shell(shell)
85
+ r.comment(comment)
86
+ r.manage_home(manage_home)
87
+ r.password(password)
88
+ r.salt(salt)
89
+ r.iterations(iterations)
90
+ r
91
+ end
92
+
93
+ before do
94
+ clean_user
95
+ end
96
+
97
+ after(:each) do
98
+ clean_user
99
+ end
100
+
101
+ describe "action :create" do
102
+ it "should create the user" do
103
+ user_resource.run_action(:create)
104
+ user_should_exist
105
+ check_password(password)
106
+ end
107
+ end
108
+
109
+ describe "when user exists" do
110
+ before do
111
+ existing_resource = user_resource.dup
112
+ existing_resource.run_action(:create)
113
+ user_should_exist
114
+ end
115
+
116
+ describe "when password is updated" do
117
+ it "should update the password of the user" do
118
+ user_resource.password("mykitchen")
119
+ user_resource.run_action(:create)
120
+ check_password("mykitchen")
121
+ end
122
+ end
123
+ end
124
+
125
+ describe "when password is being set via shadow hash" do
126
+ let(:password) {
127
+ if node[:platform_version].start_with?("10.7.")
128
+ # On Mac 10.7 we only need to set the password
129
+ "c9b3bd1a0cde797eef0eff16c580dab996ba3a21961cccc\
130
+ d0f5e65c61558243e50b1a490088bd4824e3b35562d383ca02260398\
131
+ ef1979b302212ec1c5383d1d05fc8d843"
132
+ else
133
+ "c734b6e4787c3727bb35e29fdd92b97c\
134
+ 1de12df509577a045728255ec7c6c5f5\
135
+ c18efa05ed02b682ffa7ebc05119900e\
136
+ b1d4880833aa7a190afc13e2bf0936b8\
137
+ 20123e8c98f0f9bcac2a629d9163caac\
138
+ 9464a8c234f3919082400b4f939bb77b\
139
+ c5adbbac718b7eb99463a7b679571e0f\
140
+ 1c9fef2ef08d0b9e9c2bcf644eed2ffc"
141
+ end
142
+ }
143
+
144
+ let(:iterations) { 25000 }
145
+ let(:salt) { "9e2e7d5ee473b496fd24cf0bbfcaedfcb291ee21740e570d1e917e874f8788ca" }
146
+
147
+ it "action :create should create the user" do
148
+ user_resource.run_action(:create)
149
+ user_should_exist
150
+ check_password("soawesome")
151
+ end
152
+
153
+ describe "when user exists" do
154
+ before do
155
+ existing_resource = user_resource.dup
156
+ existing_resource.run_action(:create)
157
+ user_should_exist
158
+ end
159
+
160
+ describe "when password is updated" do
161
+ it "should update the password of the user" do
162
+ user_resource.password("mykitchen")
163
+ user_resource.run_action(:create)
164
+ check_password("mykitchen")
165
+ end
166
+ end
167
+ end
168
+ end
169
+
170
+ describe "when a user is member of some groups" do
171
+ let(:groups) { ["staff", "operator"] }
172
+
173
+ before do
174
+ existing_resource = user_resource.dup
175
+ existing_resource.run_action(:create)
176
+
177
+ groups.each do |group|
178
+ shell_out!("/usr/bin/dscl . -append '/Groups/#{group}' GroupMembership #{username}")
179
+ end
180
+ end
181
+
182
+ after do
183
+ groups.each do |group|
184
+ # Do not raise an error when user is correctly removed
185
+ shell_out("/usr/bin/dscl . -delete '/Groups/#{group}' GroupMembership #{username}")
186
+ end
187
+ end
188
+
189
+ it ":remove action removes the user from the groups and deletes the user"do
190
+ user_resource.run_action(:remove)
191
+ groups.each do |group|
192
+ # Do not raise an error when group is empty
193
+ shell_out("dscl . read /Groups/staff GroupMembership").stdout.should_not include(group)
194
+ end
195
+ end
196
+ end
197
+
198
+ end