chef 11.8.4.ohai7.0-x86-mingw32 → 11.10.0.alpha.1-x86-mingw32

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 (134) hide show
  1. checksums.yaml +7 -0
  2. data/distro/common/html/chef-client.8.html +3 -3
  3. data/distro/common/html/chef-expander.8.html +3 -3
  4. data/distro/common/html/chef-expanderctl.8.html +3 -3
  5. data/distro/common/html/chef-server-webui.8.html +3 -3
  6. data/distro/common/html/chef-server.8.html +3 -3
  7. data/distro/common/html/chef-shell.1.html +3 -3
  8. data/distro/common/html/chef-solo.8.html +3 -3
  9. data/distro/common/html/chef-solr.8.html +4 -4
  10. data/distro/common/html/knife-bootstrap.1.html +3 -3
  11. data/distro/common/html/knife-client.1.html +3 -3
  12. data/distro/common/html/knife-configure.1.html +3 -3
  13. data/distro/common/html/knife-cookbook-site.1.html +3 -3
  14. data/distro/common/html/knife-cookbook.1.html +3 -3
  15. data/distro/common/html/knife-data-bag.1.html +3 -3
  16. data/distro/common/html/knife-environment.1.html +3 -3
  17. data/distro/common/html/knife-exec.1.html +3 -3
  18. data/distro/common/html/knife-index.1.html +3 -3
  19. data/distro/common/html/knife-node.1.html +3 -3
  20. data/distro/common/html/knife-role.1.html +3 -3
  21. data/distro/common/html/knife-search.1.html +3 -3
  22. data/distro/common/html/knife-ssh.1.html +3 -3
  23. data/distro/common/html/knife-status.1.html +3 -3
  24. data/distro/common/html/knife-tag.1.html +3 -3
  25. data/distro/common/html/knife.1.html +3 -3
  26. data/distro/common/man/man8/chef-client.8 +3 -3
  27. data/distro/common/man/man8/chef-solo.8 +5 -2
  28. data/lib/chef.rb +2 -0
  29. data/lib/chef/application.rb +7 -2
  30. data/lib/chef/application/apply.rb +6 -0
  31. data/lib/chef/application/client.rb +3 -1
  32. data/lib/chef/application/knife.rb +2 -0
  33. data/lib/chef/application/solo.rb +1 -1
  34. data/lib/chef/client.rb +14 -11
  35. data/lib/chef/config.rb +4 -1
  36. data/lib/chef/cookbook_uploader.rb +14 -7
  37. data/lib/chef/encrypted_data_bag_item.rb +6 -303
  38. data/lib/chef/encrypted_data_bag_item/decryption_failure.rb +22 -0
  39. data/lib/chef/encrypted_data_bag_item/decryptor.rb +201 -0
  40. data/lib/chef/encrypted_data_bag_item/encryptor.rb +142 -0
  41. data/lib/chef/encrypted_data_bag_item/unacceptable_encrypted_data_bag_item_format.rb +22 -0
  42. data/lib/chef/encrypted_data_bag_item/unsupported_cipher.rb +22 -0
  43. data/lib/chef/encrypted_data_bag_item/unsupported_encrypted_data_bag_item_format.rb +22 -0
  44. data/lib/chef/exceptions.rb +1 -0
  45. data/lib/chef/formatters/doc.rb +19 -3
  46. data/lib/chef/http/basic_client.rb +1 -1
  47. data/lib/chef/http/http_request.rb +7 -0
  48. data/lib/chef/knife.rb +8 -1
  49. data/lib/chef/knife/bootstrap.rb +1 -1
  50. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  51. data/lib/chef/knife/cookbook_upload.rb +7 -1
  52. data/lib/chef/knife/core/subcommand_loader.rb +2 -2
  53. data/lib/chef/knife/data_bag_create.rb +7 -0
  54. data/lib/chef/knife/environment_compare.rb +127 -0
  55. data/lib/chef/mixin/command.rb +11 -12
  56. data/lib/chef/mixin/deep_merge.rb +4 -4
  57. data/lib/chef/monkey_patches/net_http.rb +34 -0
  58. data/lib/chef/monkey_patches/uri.rb +70 -0
  59. data/lib/chef/platform/provider_mapping.rb +1 -0
  60. data/lib/chef/provider/cookbook_file.rb +8 -0
  61. data/lib/chef/provider/cron.rb +1 -1
  62. data/lib/chef/provider/directory.rb +7 -0
  63. data/lib/chef/provider/file.rb +17 -4
  64. data/lib/chef/provider/git.rb +23 -5
  65. data/lib/chef/provider/group.rb +30 -11
  66. data/lib/chef/provider/group/dscl.rb +26 -4
  67. data/lib/chef/provider/group/gpasswd.rb +14 -19
  68. data/lib/chef/provider/group/groupadd.rb +41 -1
  69. data/lib/chef/provider/group/groupmod.rb +46 -36
  70. data/lib/chef/provider/group/pw.rb +59 -16
  71. data/lib/chef/provider/group/suse.rb +16 -13
  72. data/lib/chef/provider/group/usermod.rb +38 -15
  73. data/lib/chef/provider/group/windows.rb +13 -6
  74. data/lib/chef/provider/ohai.rb +5 -6
  75. data/lib/chef/provider/remote_file.rb +8 -0
  76. data/lib/chef/provider/template.rb +8 -0
  77. data/lib/chef/provider/user.rb +5 -1
  78. data/lib/chef/provider/user/useradd.rb +7 -0
  79. data/lib/chef/provider/whyrun_safe_ruby_block.rb +30 -0
  80. data/lib/chef/providers.rb +1 -0
  81. data/lib/chef/resource/deploy.rb +18 -0
  82. data/lib/chef/resource/group.rb +11 -0
  83. data/lib/chef/resource/scm.rb +18 -0
  84. data/lib/chef/resource/whyrun_safe_ruby_block.rb +31 -0
  85. data/lib/chef/resources.rb +1 -0
  86. data/lib/chef/run_context.rb +11 -0
  87. data/lib/chef/shell/ext.rb +1 -1
  88. data/lib/chef/util/windows/net_group.rb +5 -1
  89. data/lib/chef/version.rb +1 -1
  90. data/spec/functional/resource/base.rb +3 -1
  91. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  92. data/spec/functional/resource/git_spec.rb +1 -1
  93. data/spec/functional/resource/group_spec.rb +257 -118
  94. data/spec/integration/client/client_spec.rb +82 -8
  95. data/spec/integration/client/ipv6_spec.rb +133 -0
  96. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +111 -0
  97. data/spec/scripts/ssl-serve.rb +52 -0
  98. data/spec/spec_helper.rb +7 -6
  99. data/spec/support/platform_helpers.rb +21 -0
  100. data/spec/support/shared/functional/windows_script.rb +2 -1
  101. data/spec/support/shared/unit/provider/file.rb +181 -43
  102. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +18 -0
  103. data/spec/unit/application/client_spec.rb +1 -0
  104. data/spec/unit/client_spec.rb +14 -1
  105. data/spec/unit/config_spec.rb +20 -0
  106. data/spec/unit/encrypted_data_bag_item_spec.rb +32 -18
  107. data/spec/unit/knife/cookbook_upload_spec.rb +14 -0
  108. data/spec/unit/knife/core/subcommand_loader_spec.rb +2 -2
  109. data/spec/unit/knife/data_bag_create_spec.rb +7 -0
  110. data/spec/unit/knife/environment_compare_spec.rb +112 -0
  111. data/spec/unit/knife_spec.rb +6 -1
  112. data/spec/unit/monkey_patches/uri_spec.rb +34 -0
  113. data/spec/unit/provider/cookbook_file_spec.rb +2 -1
  114. data/spec/unit/provider/cron_spec.rb +6 -0
  115. data/spec/unit/provider/file_spec.rb +3 -1
  116. data/spec/unit/provider/git_spec.rb +28 -4
  117. data/spec/unit/provider/group/dscl_spec.rb +1 -0
  118. data/spec/unit/provider/group/gpasswd_spec.rb +16 -9
  119. data/spec/unit/provider/group/groupadd_spec.rb +3 -4
  120. data/spec/unit/provider/group/groupmod_spec.rb +0 -1
  121. data/spec/unit/provider/group/pw_spec.rb +11 -14
  122. data/spec/unit/provider/group/usermod_spec.rb +19 -4
  123. data/spec/unit/provider/group/windows_spec.rb +0 -8
  124. data/spec/unit/provider/group_spec.rb +26 -4
  125. data/spec/unit/provider/ohai_spec.rb +1 -0
  126. data/spec/unit/provider/remote_file_spec.rb +4 -3
  127. data/spec/unit/provider/template_spec.rb +5 -3
  128. data/spec/unit/provider/user_spec.rb +6 -0
  129. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +47 -0
  130. data/spec/unit/resource/scm_spec.rb +10 -0
  131. data/spec/unit/rest/auth_credentials_spec.rb +4 -1
  132. data/spec/unit/rest_spec.rb +12 -3
  133. metadata +69 -121
  134. data/spec/functional/resource/ohai_spec.rb +0 -65
@@ -1,4 +1,7 @@
1
1
  require 'fcntl'
2
+ require 'chef/mixin/shell_out'
3
+
4
+ include Chef::Mixin::ShellOut
2
5
 
3
6
  def ruby_gte_20?
4
7
  RUBY_VERSION.to_f >= 2.0
@@ -32,6 +35,19 @@ def windows_win2k3?
32
35
  (host.version && host.version.start_with?("5.2"))
33
36
  end
34
37
 
38
+ def mac_osx_106?
39
+ if File.exists? "/usr/bin/sw_vers"
40
+ result = shell_out("/usr/bin/sw_vers")
41
+ result.stdout.each_line do |line|
42
+ if line =~ /^ProductVersion:\s10.6.*$/
43
+ return true
44
+ end
45
+ end
46
+ end
47
+
48
+ false
49
+ end
50
+
35
51
  # detects if the hardware is 64-bit (evaluates to true in "WOW64" mode in a 32-bit app on a 64-bit system)
36
52
  def windows64?
37
53
  windows? && ( ENV['PROCESSOR_ARCHITECTURE'] == 'AMD64' || ENV['PROCESSOR_ARCHITEW6432'] == 'AMD64' )
@@ -95,3 +111,8 @@ end
95
111
  def suse?
96
112
  File.exists?("/etc/SuSE-release")
97
113
  end
114
+
115
+ def root?
116
+ return false if windows?
117
+ Process.euid == 0
118
+ end
@@ -23,7 +23,8 @@ shared_context Chef::Resource::WindowsScript do
23
23
  before(:all) do
24
24
 
25
25
  ohai_reader = Ohai::System.new
26
- ohai_reader.all_plugins("platform")
26
+ ohai_reader.require_plugin("os")
27
+ ohai_reader.require_plugin("windows::platform")
27
28
 
28
29
  new_node = Chef::Node.new
29
30
  new_node.consume_external_attrs(ohai_reader.data,{})
@@ -35,46 +35,75 @@ def normalized_path
35
35
  File.expand_path(resource_path)
36
36
  end
37
37
 
38
+ # forwards-vs-reverse slashes on windows sucks
39
+ def windows_path
40
+ windows? ? normalized_path.gsub(/\\/, '/') : normalized_path
41
+ end
42
+
43
+ # this is all getting a bit stupid, CHEF-4802 cut to remove all this
38
44
  def setup_normal_file
39
- File.stub!(:exists?).with(resource_path).and_return(true)
40
- File.stub!(:directory?).with(resource_path).and_return(false)
41
- File.stub!(:directory?).with(enclosing_directory).and_return(true)
42
- File.stub!(:writable?).with(resource_path).and_return(true)
43
- file_symlink_class.stub!(:symlink?).with(resource_path).and_return(false)
44
- file_symlink_class.stub!(:symlink?).with(normalized_path).and_return(false)
45
+ [ resource_path, normalized_path, windows_path].each do |path|
46
+ File.stub(:file?).with(path).and_return(true)
47
+ File.stub(:exists?).with(path).and_return(true)
48
+ File.stub(:exist?).with(path).and_return(true)
49
+ File.stub(:directory?).with(path).and_return(false)
50
+ File.stub(:writable?).with(path).and_return(true)
51
+ file_symlink_class.stub(:symlink?).with(path).and_return(false)
52
+ File.stub(:realpath?).with(path).and_return(normalized_path)
53
+ end
54
+ File.stub(:directory?).with(enclosing_directory).and_return(true)
45
55
  end
46
56
 
47
57
  def setup_missing_file
48
- File.stub!(:exists?).with(resource_path).and_return(false)
49
- File.stub!(:directory?).with(resource_path).and_return(false)
50
- File.stub!(:directory?).with(enclosing_directory).and_return(true)
51
- File.stub!(:writable?).with(resource_path).and_return(false)
52
- file_symlink_class.stub!(:symlink?).with(resource_path).and_return(false)
58
+ [ resource_path, normalized_path, windows_path].each do |path|
59
+ File.stub(:file?).with(path).and_return(false)
60
+ File.stub(:realpath?).with(path).and_return(resource_path)
61
+ File.stub(:exists?).with(path).and_return(false)
62
+ File.stub(:exist?).with(path).and_return(false)
63
+ File.stub(:directory?).with(path).and_return(false)
64
+ File.stub(:writable?).with(path).and_return(false)
65
+ file_symlink_class.stub(:symlink?).with(path).and_return(false)
66
+ end
67
+ File.stub(:directory?).with(enclosing_directory).and_return(true)
53
68
  end
54
69
 
55
70
  def setup_symlink
56
- File.stub!(:exists?).with(resource_path).and_return(true)
57
- File.stub!(:directory?).with(normalized_path).and_return(false)
58
- File.stub!(:directory?).with(enclosing_directory).and_return(true)
59
- File.stub!(:writable?).with(resource_path).and_return(true)
60
- file_symlink_class.stub!(:symlink?).with(resource_path).and_return(true)
61
- file_symlink_class.stub!(:symlink?).with(normalized_path).and_return(true)
71
+ [ resource_path, normalized_path, windows_path].each do |path|
72
+ File.stub(:file?).with(path).and_return(true)
73
+ File.stub(:realpath?).with(path).and_return(normalized_path)
74
+ File.stub(:exists?).with(path).and_return(true)
75
+ File.stub(:exist?).with(path).and_return(true)
76
+ File.stub(:directory?).with(path).and_return(false)
77
+ File.stub(:writable?).with(path).and_return(true)
78
+ file_symlink_class.stub(:symlink?).with(path).and_return(true)
79
+ end
80
+ File.stub(:directory?).with(enclosing_directory).and_return(true)
62
81
  end
63
82
 
64
83
  def setup_unwritable_file
65
- File.stub!(:exists?).with(resource_path).and_return(true)
66
- File.stub!(:directory?).with(resource_path).and_return(false)
67
- File.stub!(:directory?).with(enclosing_directory).and_return(true)
68
- File.stub!(:writable?).with(resource_path).and_return(false)
69
- file_symlink_class.stub!(:symlink?).with(resource_path).and_return(false)
84
+ [ resource_path, normalized_path, windows_path].each do |path|
85
+ File.stub(:file?).with(path).and_return(false)
86
+ File.stub(:realpath?).with(path).and_raise(Errno::ENOENT)
87
+ File.stub(:exists?).with(path).and_return(true)
88
+ File.stub(:exist?).with(path).and_return(true)
89
+ File.stub(:directory?).with(path).and_return(false)
90
+ File.stub(:writable?).with(path).and_return(false)
91
+ file_symlink_class.stub(:symlink?).with(path).and_return(false)
92
+ end
93
+ File.stub(:directory?).with(enclosing_directory).and_return(true)
70
94
  end
71
95
 
72
96
  def setup_missing_enclosing_directory
73
- File.stub!(:exists?).with(resource_path).and_return(false)
74
- File.stub!(:directory?).with(resource_path).and_return(false)
75
- File.stub!(:directory?).with(enclosing_directory).and_return(false)
76
- File.stub!(:writable?).with(resource_path).and_return(false)
77
- file_symlink_class.stub!(:symlink?).with(resource_path).and_return(false)
97
+ [ resource_path, normalized_path, windows_path].each do |path|
98
+ File.stub(:file?).with(path).and_return(false)
99
+ File.stub(:realpath?).with(path).and_raise(Errno::ENOENT)
100
+ File.stub(:exists?).with(path).and_return(false)
101
+ File.stub(:exist?).with(path).and_return(false)
102
+ File.stub(:directory?).with(path).and_return(false)
103
+ File.stub(:writable?).with(path).and_return(false)
104
+ file_symlink_class.stub(:symlink?).with(path).and_return(false)
105
+ end
106
+ File.stub(:directory?).with(enclosing_directory).and_return(false)
78
107
  end
79
108
 
80
109
  shared_examples_for Chef::Provider::File do
@@ -93,63 +122,109 @@ shared_examples_for Chef::Provider::File do
93
122
 
94
123
  context "when loading the current resource" do
95
124
 
125
+ context "when running load_current_resource" do
126
+ #
127
+ # the content objects need the current_resource to be loaded (esp remote_file), so calling
128
+ # for content inside of load_current_resource is totally crossing the streams...
129
+ #
130
+ it "should not try to load the content when the file is present" do
131
+ setup_normal_file
132
+ provider.should_not_receive(:tempfile)
133
+ provider.should_not_receive(:content)
134
+ provider.load_current_resource
135
+ end
136
+
137
+ it "should not try to load the content when the file is missing" do
138
+ setup_missing_file
139
+ provider.should_not_receive(:tempfile)
140
+ provider.should_not_receive(:content)
141
+ provider.load_current_resource
142
+ end
143
+ end
144
+
96
145
  context "when running load_current_resource and the file exists" do
97
146
  before do
98
147
  setup_normal_file
99
- provider.load_current_resource
100
148
  end
101
149
 
150
+ let(:tempfile_sha256) { "42971f0ddce0cb20cf7660a123ffa1a1543beb2f1e7cd9d65858764a27f3201d" }
151
+
102
152
  it "should load a current resource based on the one specified at construction" do
153
+ provider.load_current_resource
103
154
  provider.current_resource.should be_a_kind_of(Chef::Resource::File)
104
155
  end
105
156
 
106
157
  it "the loaded current_resource name should be the same as the resource name" do
158
+ provider.load_current_resource
107
159
  provider.current_resource.name.should eql(resource.name)
108
160
  end
109
161
 
110
162
  it "the loaded current_resource path should be the same as the resoure path" do
163
+ provider.load_current_resource
111
164
  provider.current_resource.path.should eql(resource.path)
112
165
  end
113
166
 
114
167
  it "the loaded current_resource content should be nil" do
168
+ provider.load_current_resource
115
169
  provider.current_resource.content.should eql(nil)
116
170
  end
171
+
172
+ it "it should call checksum if we are managing content" do
173
+ provider.should_receive(:managing_content?).at_least(:once).and_return(true)
174
+ provider.should_receive(:checksum).with(resource.path).and_return(tempfile_sha256)
175
+ provider.load_current_resource
176
+ end
177
+
178
+ it "it should not call checksum if we are not managing content" do
179
+ provider.should_receive(:managing_content?).at_least(:once).and_return(false)
180
+ provider.should_not_receive(:checksum)
181
+ provider.load_current_resource
182
+ end
117
183
  end
118
184
 
119
185
  context "when running load_current_resource and the file does not exist" do
120
186
  before do
121
187
  setup_missing_file
122
- provider.load_current_resource
123
188
  end
124
189
 
125
190
  it "the current_resource should be a Chef::Resource::File" do
191
+ provider.load_current_resource
126
192
  provider.current_resource.should be_a_kind_of(Chef::Resource::File)
127
193
  end
128
194
 
129
195
  it "the current_resource name should be the same as the resource name" do
196
+ provider.load_current_resource
130
197
  provider.current_resource.name.should eql(resource.name)
131
198
  end
132
199
 
133
200
  it "the current_resource path should be the same as the resource path" do
201
+ provider.load_current_resource
134
202
  provider.current_resource.path.should eql(resource.path)
135
203
  end
136
204
 
137
205
  it "the loaded current_resource content should be nil" do
206
+ provider.load_current_resource
138
207
  provider.current_resource.content.should eql(nil)
139
208
  end
209
+
210
+ it "it should not call checksum if we are not managing content" do
211
+ provider.should_not_receive(:managing_content?)
212
+ provider.should_not_receive(:checksum)
213
+ provider.load_current_resource
214
+ end
140
215
  end
141
216
 
142
217
  context "examining file security metadata on Unix with a file that exists" do
143
218
  before do
144
219
  # fake that we're on unix even if we're on windows
145
- Chef::Platform.stub!(:windows?).and_return(false)
220
+ Chef::Platform.stub(:windows?).and_return(false)
146
221
  # mock up the filesystem to behave like unix
147
222
  setup_normal_file
148
223
  stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
149
224
  resource_real_path = File.realpath(resource.path)
150
225
  File.should_receive(:stat).with(resource_real_path).at_least(:once).and_return(stat_struct)
151
- Etc.stub!(:getgrgid).with(0).and_return(mock("Group Ent", :name => "wheel"))
152
- Etc.stub!(:getpwuid).with(0).and_return(mock("User Ent", :name => "root"))
226
+ Etc.stub(:getgrgid).with(0).and_return(mock("Group Ent", :name => "wheel"))
227
+ Etc.stub(:getpwuid).with(0).and_return(mock("User Ent", :name => "root"))
153
228
  end
154
229
 
155
230
  context "when the new_resource does not specify any state" do
@@ -218,7 +293,7 @@ shared_examples_for Chef::Provider::File do
218
293
  context "examining file security metadata on Unix with a file that does not exist" do
219
294
  before do
220
295
  # fake that we're on unix even if we're on windows
221
- Chef::Platform.stub!(:windows?).and_return(false)
296
+ Chef::Platform.stub(:windows?).and_return(false)
222
297
  setup_missing_file
223
298
  end
224
299
 
@@ -267,14 +342,14 @@ shared_examples_for Chef::Provider::File do
267
342
 
268
343
  before do
269
344
  # fake that we're on unix even if we're on windows
270
- Chef::Platform.stub!(:windows?).and_return(false)
345
+ Chef::Platform.stub(:windows?).and_return(false)
271
346
  # mock up the filesystem to behave like unix
272
347
  setup_normal_file
273
348
  stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
274
349
  resource_real_path = File.realpath(resource.path)
275
- File.stub!(:stat).with(resource_real_path).and_return(stat_struct)
276
- Etc.stub!(:getgrgid).with(0).and_return(mock("Group Ent", :name => "wheel"))
277
- Etc.stub!(:getpwuid).with(0).and_return(mock("User Ent", :name => "root"))
350
+ File.stub(:stat).with(resource_real_path).and_return(stat_struct)
351
+ Etc.stub(:getgrgid).with(0).and_return(mock("Group Ent", :name => "wheel"))
352
+ Etc.stub(:getpwuid).with(0).and_return(mock("User Ent", :name => "root"))
278
353
  provider.send(:load_resource_attributes_from_file, resource)
279
354
  end
280
355
 
@@ -368,7 +443,7 @@ shared_examples_for Chef::Provider::File do
368
443
  setup_normal_file
369
444
  provider.load_current_resource
370
445
  tempfile = double('Tempfile', :path => "/tmp/foo-bar-baz")
371
- content.stub!(:tempfile).and_return(tempfile)
446
+ content.stub(:tempfile).and_return(tempfile)
372
447
  File.should_receive(:exists?).with("/tmp/foo-bar-baz").and_return(true)
373
448
  tempfile.should_receive(:unlink).once
374
449
  end
@@ -378,11 +453,12 @@ shared_examples_for Chef::Provider::File do
378
453
  let(:tempfile_sha256) { "42971f0ddce0cb20cf7660a123ffa1a1543beb2f1e7cd9d65858764a27f3201d" }
379
454
  let(:diff_for_reporting) { "+++\n---\n+foo\n-bar\n" }
380
455
  before do
381
- provider.stub!(:contents_changed?).and_return(true)
456
+ provider.stub(:contents_changed?).and_return(true)
382
457
  diff = double('Diff', :for_output => ['+++','---','+foo','-bar'],
383
458
  :for_reporting => diff_for_reporting )
384
- diff.stub!(:diff).with(resource_path, tempfile_path).and_return(true)
459
+ diff.stub(:diff).with(resource_path, tempfile_path).and_return(true)
385
460
  provider.should_receive(:diff).at_least(:once).and_return(diff)
461
+ provider.should_receive(:managing_content?).at_least(:once).and_return(true)
386
462
  provider.should_receive(:checksum).with(tempfile_path).and_return(tempfile_sha256)
387
463
  provider.should_receive(:checksum).with(resource_path).and_return(tempfile_sha256)
388
464
  provider.deployment_strategy.should_receive(:deploy).with(tempfile_path, normalized_path)
@@ -406,7 +482,7 @@ shared_examples_for Chef::Provider::File do
406
482
  end
407
483
 
408
484
  it "does nothing when the contents have not changed" do
409
- provider.stub!(:contents_changed?).and_return(false)
485
+ provider.stub(:contents_changed?).and_return(false)
410
486
  provider.should_not_receive(:diff)
411
487
  provider.send(:do_contents_changes)
412
488
  end
@@ -443,7 +519,7 @@ shared_examples_for Chef::Provider::File do
443
519
  before do
444
520
  setup_normal_file
445
521
  provider.load_current_resource
446
- provider.stub!(:resource_updated?).and_return(true)
522
+ provider.stub(:resource_updated?).and_return(true)
447
523
  end
448
524
 
449
525
  it "should check for selinux_enabled? by default" do
@@ -508,7 +584,7 @@ shared_examples_for Chef::Provider::File do
508
584
 
509
585
  context "when resource is not updated" do
510
586
  before do
511
- provider.stub!(:resource_updated?).and_return(false)
587
+ provider.stub(:resource_updated?).and_return(false)
512
588
  end
513
589
 
514
590
  it "should not check for selinux_enabled?" do
@@ -607,3 +683,65 @@ shared_examples_for Chef::Provider::File do
607
683
 
608
684
  end
609
685
 
686
+ shared_examples_for "a file provider with content field" do
687
+ context "when testing managing_content?" do
688
+ it "should be false when creating a file without content" do
689
+ provider.action = :create
690
+ resource.stub(:content).and_return(nil)
691
+ resource.stub(:checksum).and_return(nil)
692
+ expect(provider.send(:managing_content?)).to be_false
693
+ end
694
+ it "should be true when creating a file with content" do
695
+ provider.action = :create
696
+ resource.stub(:content).and_return("flurbleblobbleblooble")
697
+ resource.stub(:checksum).and_return(nil)
698
+ expect(provider.send(:managing_content?)).to be_true
699
+ end
700
+ it "should be true when checksum is set on the content (no matter how crazy)" do
701
+ provider.action = :create_if_missing
702
+ resource.stub(:checksum).and_return("1234123234234234")
703
+ resource.stub(:content).and_return(nil)
704
+ expect(provider.send(:managing_content?)).to be_true
705
+ end
706
+ it "should be false when action is create_if_missing" do
707
+ provider.action = :create_if_missing
708
+ resource.stub(:content).and_return("flurbleblobbleblooble")
709
+ resource.stub(:checksum).and_return(nil)
710
+ expect(provider.send(:managing_content?)).to be_false
711
+ end
712
+ end
713
+ end
714
+
715
+ shared_examples_for "a file provider with source field" do
716
+ context "when testing managing_content?" do
717
+ it "should be false when creating a file without content" do
718
+ provider.action = :create
719
+ resource.stub(:content).and_return(nil)
720
+ resource.stub(:source).and_return(nil)
721
+ resource.stub(:checksum).and_return(nil)
722
+ expect(provider.send(:managing_content?)).to be_false
723
+ end
724
+ it "should be true when creating a file with content" do
725
+ provider.action = :create
726
+ resource.stub(:content).and_return(nil)
727
+ resource.stub(:source).and_return("http://somewhere.com/something.php")
728
+ resource.stub(:checksum).and_return(nil)
729
+ expect(provider.send(:managing_content?)).to be_true
730
+ end
731
+ it "should be true when checksum is set on the content (no matter how crazy)" do
732
+ provider.action = :create_if_missing
733
+ resource.stub(:content).and_return(nil)
734
+ resource.stub(:source).and_return(nil)
735
+ resource.stub(:checksum).and_return("1234123234234234")
736
+ expect(provider.send(:managing_content?)).to be_true
737
+ end
738
+ it "should be false when action is create_if_missing" do
739
+ provider.action = :create_if_missing
740
+ resource.stub(:content).and_return(nil)
741
+ resource.stub(:source).and_return("http://somewhere.com/something.php")
742
+ resource.stub(:checksum).and_return(nil)
743
+ expect(provider.send(:managing_content?)).to be_false
744
+ end
745
+ end
746
+ end
747
+
@@ -335,6 +335,24 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
335
335
  lambda { provider.check_lock }.should raise_error(Mixlib::ShellOut::ShellCommandFailed)
336
336
  end
337
337
  end
338
+
339
+ context "when in why run mode" do
340
+ before do
341
+ passwd_status = mock("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "", :stderr => "passwd: user 'chef-test' does not exist\n")
342
+ provider.should_receive(:shell_out!).
343
+ with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}).
344
+ and_return(passwd_status)
345
+ Chef::Config[:why_run] = true
346
+ end
347
+
348
+ it "should return false if the user does not exist" do
349
+ provider.check_lock.should eql(false)
350
+ end
351
+
352
+ it "should not raise an error if the user does not exist" do
353
+ lambda { provider.check_lock }.should_not raise_error
354
+ end
355
+ end
338
356
  end
339
357
 
340
358
  describe "when locking the user" do
@@ -26,6 +26,7 @@ describe Chef::Application::Client, "reconfigure" do
26
26
  @app.stub!(:configure_opt_parser).and_return(true)
27
27
  @app.stub!(:configure_chef).and_return(true)
28
28
  @app.stub!(:configure_logging).and_return(true)
29
+ @app.cli_arguments = []
29
30
  Chef::Config[:interval] = 10
30
31
 
31
32
  Chef::Config[:once] = false
@@ -169,7 +169,6 @@ shared_examples_for Chef::Client do
169
169
 
170
170
  it "should identify the node and run ohai, then register the client" do
171
171
  mock_chef_rest_for_node = mock("Chef::REST (node)")
172
- mock_chef_rest_for_client = mock("Chef::REST (client)")
173
172
  mock_chef_rest_for_node_save = mock("Chef::REST (node save)")
174
173
  mock_chef_runner = mock("Chef::Runner")
175
174
 
@@ -448,6 +447,20 @@ shared_examples_for Chef::Client do
448
447
  end
449
448
  end
450
449
 
450
+ describe "assert_cookbook_path_not_empty" do
451
+ before do
452
+ Chef::Config[:solo] = true
453
+ Chef::Config[:cookbook_path] = ["/path/to/invalid/cookbook_path"]
454
+ end
455
+ context "when any directory of cookbook_path contains no cookbook" do
456
+ it "raises CookbookNotFound error" do
457
+ expect do
458
+ @client.send(:assert_cookbook_path_not_empty, nil)
459
+ end.to raise_error(Chef::Exceptions::CookbookNotFound, 'None of the cookbook paths set in Chef::Config[:cookbook_path], ["/path/to/invalid/cookbook_path"], contain any cookbooks')
460
+ end
461
+ end
462
+ end
463
+
451
464
  end
452
465
 
453
466
  describe Chef::Client do