chef 11.10.0.alpha.1-x86-mingw32 → 11.10.0.rc.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/README.md +57 -36
  2. data/distro/common/html/chef-client.8.html +4 -4
  3. data/distro/common/html/chef-expander.8.html +4 -4
  4. data/distro/common/html/chef-expanderctl.8.html +4 -4
  5. data/distro/common/html/chef-server-webui.8.html +4 -4
  6. data/distro/common/html/chef-server.8.html +4 -4
  7. data/distro/common/html/chef-shell.1.html +4 -4
  8. data/distro/common/html/chef-solo.8.html +4 -4
  9. data/distro/common/html/chef-solr.8.html +5 -5
  10. data/distro/common/html/knife-bootstrap.1.html +4 -4
  11. data/distro/common/html/knife-client.1.html +4 -4
  12. data/distro/common/html/knife-configure.1.html +4 -4
  13. data/distro/common/html/knife-cookbook-site.1.html +4 -4
  14. data/distro/common/html/knife-cookbook.1.html +4 -4
  15. data/distro/common/html/knife-data-bag.1.html +4 -4
  16. data/distro/common/html/knife-environment.1.html +4 -4
  17. data/distro/common/html/knife-exec.1.html +4 -4
  18. data/distro/common/html/knife-index.1.html +4 -4
  19. data/distro/common/html/knife-node.1.html +4 -4
  20. data/distro/common/html/knife-role.1.html +4 -4
  21. data/distro/common/html/knife-search.1.html +4 -4
  22. data/distro/common/html/knife-ssh.1.html +4 -4
  23. data/distro/common/html/knife-status.1.html +4 -4
  24. data/distro/common/html/knife-tag.1.html +4 -4
  25. data/distro/common/html/knife.1.html +4 -4
  26. data/distro/common/man/man1/knife-bootstrap.1 +58 -64
  27. data/distro/common/man/man1/knife-client.1 +19 -22
  28. data/distro/common/man/man1/knife-configure.1 +37 -46
  29. data/distro/common/man/man1/knife-cookbook-site.1 +14 -17
  30. data/distro/common/man/man1/knife-cookbook.1 +15 -18
  31. data/distro/common/man/man1/knife-data-bag.1 +14 -17
  32. data/distro/common/man/man1/knife-delete.1 +38 -47
  33. data/distro/common/man/man1/knife-deps.1 +39 -48
  34. data/distro/common/man/man1/knife-diff.1 +43 -52
  35. data/distro/common/man/man1/knife-download.1 +47 -53
  36. data/distro/common/man/man1/knife-edit.1 +32 -41
  37. data/distro/common/man/man1/knife-environment.1 +14 -17
  38. data/distro/common/man/man1/knife-exec.1 +52 -61
  39. data/distro/common/man/man1/knife-index-rebuild.1 +1 -61
  40. data/distro/common/man/man1/knife-list.1 +47 -59
  41. data/distro/common/man/man1/knife-node.1 +15 -18
  42. data/distro/common/man/man1/knife-raw.1 +28 -46
  43. data/distro/common/man/man1/knife-recipe-list.1 +1 -61
  44. data/distro/common/man/man1/knife-role.1 +19 -25
  45. data/distro/common/man/man1/knife-search.1 +53 -62
  46. data/distro/common/man/man1/knife-show.1 +36 -28
  47. data/distro/common/man/man1/knife-ssh.1 +55 -61
  48. data/distro/common/man/man1/knife-status.1 +34 -43
  49. data/distro/common/man/man1/knife-tag.1 +14 -17
  50. data/distro/common/man/man1/knife-upload.1 +47 -56
  51. data/distro/common/man/man1/knife-user.1 +17 -20
  52. data/distro/common/man/man1/knife-xargs.1 +60 -69
  53. data/lib/chef/application.rb +3 -1
  54. data/lib/chef/application/windows_service.rb +0 -1
  55. data/lib/chef/client.rb +41 -152
  56. data/lib/chef/config.rb +19 -23
  57. data/lib/chef/data_bag.rb +1 -1
  58. data/lib/chef/data_bag_item.rb +1 -1
  59. data/lib/chef/exceptions.rb +8 -0
  60. data/lib/chef/formatters/doc.rb +15 -0
  61. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +2 -1
  62. data/lib/chef/http.rb +18 -8
  63. data/lib/chef/http/authenticator.rb +4 -0
  64. data/lib/chef/http/cookie_manager.rb +3 -0
  65. data/lib/chef/http/decompressor.rb +4 -0
  66. data/lib/chef/http/json_input.rb +4 -0
  67. data/lib/chef/http/json_output.rb +4 -0
  68. data/lib/chef/http/validate_content_length.rb +94 -0
  69. data/lib/chef/knife.rb +0 -1
  70. data/lib/chef/knife/configure.rb +6 -6
  71. data/lib/chef/knife/cookbook_create.rb +2 -2
  72. data/lib/chef/knife/core/subcommand_loader.rb +49 -3
  73. data/lib/chef/knife/ssh.rb +34 -4
  74. data/lib/chef/mixin/path_sanity.rb +1 -0
  75. data/lib/chef/monologger.rb +1 -2
  76. data/lib/chef/node.rb +7 -0
  77. data/lib/chef/policy_builder.rb +49 -0
  78. data/lib/chef/policy_builder/expand_node_object.rb +230 -0
  79. data/lib/chef/policy_builder/policyfile.rb +338 -0
  80. data/lib/chef/provider/file.rb +15 -5
  81. data/lib/chef/provider/group.rb +6 -2
  82. data/lib/chef/provider/group/windows.rb +12 -2
  83. data/lib/chef/provider/http_request.rb +3 -2
  84. data/lib/chef/provider/package.rb +1 -0
  85. data/lib/chef/provider/package/aix.rb +1 -1
  86. data/lib/chef/provider/service/debian.rb +7 -2
  87. data/lib/chef/resource/file.rb +8 -1
  88. data/lib/chef/resource/package.rb +9 -0
  89. data/lib/chef/resource/service.rb +0 -1
  90. data/lib/chef/rest.rb +2 -0
  91. data/lib/chef/run_context.rb +1 -1
  92. data/lib/chef/util/file_edit.rb +1 -1
  93. data/lib/chef/util/windows/net_group.rb +7 -6
  94. data/lib/chef/version.rb +1 -1
  95. data/lib/chef/win32/version.rb +31 -18
  96. data/spec/data/cookbooks/preseed/templates/default/preseed-template-variables.seed +1 -0
  97. data/spec/functional/resource/file_spec.rb +0 -1
  98. data/spec/functional/resource/group_spec.rb +96 -16
  99. data/spec/functional/resource/package_spec.rb +17 -0
  100. data/spec/functional/resource/user_spec.rb +2 -2
  101. data/spec/functional/win32/versions_spec.rb +39 -0
  102. data/spec/integration/client/client_spec.rb +27 -28
  103. data/spec/spec_helper.rb +2 -0
  104. data/spec/support/platform_helpers.rb +7 -1
  105. data/spec/support/shared/functional/file_resource.rb +83 -43
  106. data/spec/unit/application_spec.rb +7 -5
  107. data/spec/unit/client_spec.rb +10 -3
  108. data/spec/unit/config_spec.rb +0 -30
  109. data/spec/unit/cookbook_spec.rb +1 -0
  110. data/spec/unit/data_bag_item_spec.rb +8 -0
  111. data/spec/unit/data_bag_spec.rb +6 -0
  112. data/spec/unit/http_spec.rb +48 -0
  113. data/spec/unit/knife/core/subcommand_loader_spec.rb +77 -1
  114. data/spec/unit/knife/ssh_spec.rb +107 -0
  115. data/spec/unit/mixin/path_sanity_spec.rb +6 -0
  116. data/spec/unit/mixin/securable_spec.rb +77 -3
  117. data/spec/unit/monologger_spec.rb +45 -0
  118. data/spec/unit/node_spec.rb +16 -0
  119. data/spec/unit/policy_builder/expand_node_object_spec.rb +320 -0
  120. data/spec/unit/policy_builder/policyfile_spec.rb +399 -0
  121. data/spec/unit/policy_builder_spec.rb +26 -0
  122. data/spec/unit/provider/deploy_spec.rb +3 -0
  123. data/spec/unit/provider/group/windows_spec.rb +1 -0
  124. data/spec/unit/provider/http_request_spec.rb +23 -1
  125. data/spec/unit/provider/service/debian_service_spec.rb +50 -19
  126. data/spec/unit/recipe_spec.rb +4 -0
  127. data/spec/unit/resource/package_spec.rb +5 -0
  128. data/spec/unit/rest_spec.rb +375 -278
  129. data/spec/unit/run_context_spec.rb +4 -0
  130. metadata +120 -75
  131. checksums.yaml +0 -7
@@ -273,6 +273,23 @@ describe Chef::Resource::Package, metadata do
273
273
  package_resource.should be_updated_by_last_action
274
274
  end
275
275
 
276
+ context "with variables" do
277
+ let(:package_resource) do
278
+ r = base_resource
279
+ r.cookbook_name = "preseed"
280
+ r.response_file("preseed-template-variables.seed")
281
+ r.response_file_variables({ :template_variable => 'SUPPORTS VARIABLES' })
282
+ r
283
+ end
284
+
285
+ it "preseeds the package, then installs it" do
286
+ package_resource.run_action(:install)
287
+ cmd = shell_out!("debconf-show chef-integration-test")
288
+ cmd.stdout.should include('chef-integration-test/sample-var: "SUPPORTS VARIABLES"')
289
+ package_resource.should be_updated_by_last_action
290
+ end
291
+ end
292
+
276
293
  end
277
294
  end # installing w/ preseed
278
295
  end # when package not installed
@@ -196,7 +196,7 @@ describe Chef::Resource::User, metadata do
196
196
  pw_entry.home.should == "/home/#{username}"
197
197
  end
198
198
 
199
- if OHAI_SYSTEM["platform_family"] == "rhel"
199
+ if %w{rhel fedora}.include?(OHAI_SYSTEM["platform_family"])
200
200
  # Inconsistent behavior. See: CHEF-2205
201
201
  it "creates the home dir when not explicitly asked to on RHEL (XXX)" do
202
202
  File.should exist("/home/#{username}")
@@ -340,7 +340,7 @@ describe Chef::Resource::User, metadata do
340
340
  let(:existing_manage_home) { false }
341
341
  let(:manage_home) { true }
342
342
 
343
- if OHAI_SYSTEM["platform_family"] == "rhel"
343
+ if %w{rhel fedora}.include?(OHAI_SYSTEM["platform_family"])
344
344
  # Inconsistent behavior. See: CHEF-2205
345
345
  it "created the home dir b/c of CHEF-2205 so it still exists" do
346
346
  # This behavior seems contrary to expectation and non-convergent.
@@ -50,6 +50,45 @@ describe "Chef::ReservedNames::Win32::Version", :windows_only do
50
50
  @version = Chef::ReservedNames::Win32::Version.new
51
51
  end
52
52
 
53
+ def for_each_windows_version(&block)
54
+ @version.methods.each do |method_name|
55
+ if Chef::ReservedNames::Win32::Version::WIN_VERSIONS.keys.find { | key | method_name.to_s == Chef::ReservedNames::Win32::Version.send(:method_name_from_marketing_name,key) }
56
+ yield method_name
57
+ end
58
+ end
59
+ end
60
+
61
+ context "Win32 version object" do
62
+ it "should have have one method for each marketing version" do
63
+ versions = 0
64
+ for_each_windows_version { versions += 1 }
65
+ versions.should > 0
66
+ versions.should == Chef::ReservedNames::Win32::Version::WIN_VERSIONS.length
67
+ end
68
+
69
+ it "should only contain version methods with legal method names" do
70
+ method_name_pattern = /[a-z]+([a-z]|[0-9]|_)*\?{0,1}/
71
+
72
+ for_each_windows_version do |method_name|
73
+ method_match = method_name_pattern.match(method_name.to_s)
74
+ method_match.should_not be_nil
75
+ method_name.to_s.should == method_match[0]
76
+ end
77
+ end
78
+
79
+ it "should have exactly one method that returns true" do
80
+ true_versions = 0
81
+ for_each_windows_version do |method_name|
82
+ true_versions += 1 if @version.send(method_name)
83
+ end
84
+ true_versions.should == 1
85
+ end
86
+
87
+ it "should successfully execute all version methods" do
88
+ for_each_windows_version { |method_name| @version.send(method_name.to_sym) }
89
+ end
90
+ end
91
+
53
92
  context "Windows Operating System version" do
54
93
  it "should match the version from WMI" do
55
94
  @current_os_version.should include(@version.marketing_name)
@@ -5,6 +5,19 @@ describe "chef-client" do
5
5
  extend IntegrationSupport
6
6
  include Chef::Mixin::ShellOut
7
7
 
8
+ let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") }
9
+
10
+ # Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the
11
+ # following constraints are satisfied:
12
+ # * Windows: windows can only run batch scripts as bare executables. Rubygems
13
+ # creates batch wrappers for installed gems, but we don't have batch wrappers
14
+ # in the source tree.
15
+ # * Other `chef-client` in PATH: A common case is running the tests on a
16
+ # machine that has omnibus chef installed. In that case we need to ensure
17
+ # we're running `chef-client` from the source tree and not the external one.
18
+ # cf. CHEF-4914
19
+ let(:chef_client) { "ruby #{chef_dir}/chef-client" }
20
+
8
21
  when_the_repository "has a cookbook with a no-op recipe" do
9
22
  file 'cookbooks/x/recipes/default.rb', ''
10
23
 
@@ -14,27 +27,23 @@ local_mode true
14
27
  cookbook_path "#{path_to('cookbooks')}"
15
28
  EOM
16
29
 
17
- chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "bin")
18
- result = shell_out("chef-client -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
30
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
19
31
  result.error!
20
32
  end
21
33
 
22
34
  context 'and no config file' do
23
35
  it 'should complete with success when cwd is just above cookbooks and paths are not specified' do
24
- chef_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "bin"))
25
- result = shell_out("ruby #{chef_dir}/chef-client -z -o 'x::default' --config-file-jail \"#{path_to('')}\"", :cwd => path_to(''))
36
+ result = shell_out("#{chef_client} -z -o 'x::default' --config-file-jail \"#{path_to('')}\"", :cwd => path_to(''))
26
37
  result.error!
27
38
  end
28
39
 
29
40
  it 'should complete with success when cwd is below cookbooks and paths are not specified' do
30
- chef_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "bin"))
31
- result = shell_out("ruby #{chef_dir}/chef-client -z -o 'x::default' --config-file-jail \"#{path_to('')}\"", :cwd => path_to('cookbooks/x'))
41
+ result = shell_out("#{chef_client} -z -o 'x::default' --config-file-jail \"#{path_to('')}\"", :cwd => path_to('cookbooks/x'))
32
42
  result.error!
33
43
  end
34
44
 
35
45
  it 'should fail when cwd is below high above and paths are not specified' do
36
- chef_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "bin"))
37
- result = shell_out("ruby #{chef_dir}/chef-client -z -o 'x::default' --config-file-jail \"#{path_to('')}\"", :cwd => File.expand_path('..', path_to('')))
46
+ result = shell_out("#{chef_client} -z -o 'x::default' --config-file-jail \"#{path_to('')}\"", :cwd => File.expand_path('..', path_to('')))
38
47
  result.exitstatus.should == 1
39
48
  end
40
49
  end
@@ -43,15 +52,13 @@ EOM
43
52
  file '.chef/knife.rb', 'xxx.xxx'
44
53
 
45
54
  it 'should load .chef/knife.rb when -z is specified' do
46
- chef_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "bin"))
47
- result = shell_out("ruby #{chef_dir}/chef-client -z -o 'x::default' --config-file-jail \"#{path_to('')}\"", :cwd => path_to(''))
55
+ result = shell_out("#{chef_client} -z -o 'x::default' --config-file-jail \"#{path_to('')}\"", :cwd => path_to(''))
48
56
  # FATAL: Configuration error NoMethodError: undefined method `xxx' for nil:NilClass
49
57
  result.stdout.should include("xxx")
50
58
  end
51
59
 
52
60
  it 'fails to load .chef/knife.rb when -z is specified and --config-file-jail does not include the .chef/knife.rb' do
53
- chef_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "bin"))
54
- result = shell_out("ruby #{chef_dir}/chef-client -z -o 'x::default' --config-file-jail \"#{path_to('roles')}\"", :cwd => path_to(''))
61
+ result = shell_out("#{chef_client} -z -o 'x::default' --config-file-jail \"#{path_to('roles')}\"", :cwd => path_to(''))
55
62
  result.error!
56
63
  end
57
64
  end
@@ -62,8 +69,7 @@ local_mode true
62
69
  cookbook_path "#{path_to('cookbooks')}"
63
70
  EOM
64
71
 
65
- chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "bin")
66
- result = shell_out("chef-client -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
72
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
67
73
  result.error!
68
74
  end
69
75
 
@@ -105,8 +111,7 @@ client_key #{path_to('mykey.pem').inspect}
105
111
  cookbook_path #{path_to('cookbooks').inspect}
106
112
  EOM
107
113
 
108
- chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "bin")
109
- result = shell_out("chef-client -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
114
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
110
115
  result.error!
111
116
  end
112
117
 
@@ -129,8 +134,7 @@ file #{path_to('tempfile2.txt').inspect} do
129
134
  end
130
135
  EOM
131
136
 
132
- chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "bin")
133
- result = shell_out("chef-client -c \"#{path_to('config/client.rb')}\" #{path_to('arbitrary.rb')} #{path_to('arbitrary2.rb')}", :cwd => chef_dir)
137
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" #{path_to('arbitrary.rb')} #{path_to('arbitrary2.rb')}", :cwd => chef_dir)
134
138
  result.error!
135
139
 
136
140
  IO.read(path_to('tempfile.txt')).should == '1'
@@ -150,8 +154,7 @@ file #{path_to('tempfile.txt').inspect} do
150
154
  end
151
155
  EOM
152
156
 
153
- chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "bin")
154
- result = shell_out("#{chef_dir}/chef-client -c \"#{path_to('config/client.rb')}\" arbitrary.rb", :cwd => path_to(''))
157
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" arbitrary.rb", :cwd => path_to(''))
155
158
  result.error!
156
159
 
157
160
  IO.read(path_to('tempfile.txt')).should == '1'
@@ -175,8 +178,7 @@ file #{path_to('tempfile.txt').inspect} do
175
178
  end
176
179
  EOM
177
180
 
178
- chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "bin")
179
- result = shell_out("#{chef_dir}/chef-client -c \"#{path_to('config/client.rb')}\" -o x::constant_definition arbitrary.rb", :cwd => path_to(''))
181
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o x::constant_definition arbitrary.rb", :cwd => path_to(''))
180
182
  result.error!
181
183
 
182
184
  IO.read(path_to('tempfile.txt')).should == '1'
@@ -190,8 +192,7 @@ chef_server_url 'http://omg.com/blah'
190
192
  cookbook_path "#{path_to('cookbooks')}"
191
193
  EOM
192
194
 
193
- chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "bin")
194
- result = shell_out("chef-client -c \"#{path_to('config/client.rb')}\" -o 'x::default' -z", :cwd => chef_dir)
195
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' -z", :cwd => chef_dir)
195
196
  result.error!
196
197
  end
197
198
 
@@ -201,8 +202,7 @@ chef_server_url 'http://omg.com/blah'
201
202
  cookbook_path "#{path_to('cookbooks')}"
202
203
  EOM
203
204
 
204
- chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "bin")
205
- result = shell_out("chef-client -c \"#{path_to('config/client.rb')}\" -o 'x::default' --local-mode", :cwd => chef_dir)
205
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --local-mode", :cwd => chef_dir)
206
206
  result.error!
207
207
  end
208
208
 
@@ -212,8 +212,7 @@ chef_server_url 'http://omg.com/blah'
212
212
  cookbook_path "#{path_to('cookbooks')}"
213
213
  EOM
214
214
 
215
- chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "bin")
216
- result = shell_out("chef-client -c \"#{path_to('config/client.rb')}\" -o 'x::default' -z", :cwd => chef_dir)
215
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' -z", :cwd => chef_dir)
217
216
  result.error!
218
217
  end
219
218
  end
@@ -33,6 +33,7 @@ end
33
33
  # Ruby 1.9 Compat
34
34
  $:.unshift File.expand_path("../..", __FILE__)
35
35
 
36
+
36
37
  require 'rubygems'
37
38
  require 'rspec/mocks'
38
39
 
@@ -108,6 +109,7 @@ RSpec.configure do |config|
108
109
  config.filter_run_excluding :win2k3_only => true unless windows_win2k3?
109
110
  config.filter_run_excluding :windows64_only => true unless windows64?
110
111
  config.filter_run_excluding :windows32_only => true unless windows32?
112
+ config.filter_run_excluding :windows_domain_joined_only => true unless windows_domain_joined?
111
113
  config.filter_run_excluding :solaris_only => true unless solaris?
112
114
  config.filter_run_excluding :system_windows_service_gem_only => true unless system_windows_service_gem?
113
115
  config.filter_run_excluding :unix_only => true unless unix?
@@ -27,9 +27,15 @@ def windows?
27
27
  !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
28
28
  end
29
29
 
30
+ require 'ruby-wmi' if windows?
31
+
32
+ def windows_domain_joined?
33
+ return false unless windows?
34
+ WMI::Win32_ComputerSystem.find(:first).PartOfDomain
35
+ end
36
+
30
37
  def windows_win2k3?
31
38
  return false unless windows?
32
- require 'ruby-wmi'
33
39
 
34
40
  host = WMI::Win32_OperatingSystem.find(:first)
35
41
  (host.version && host.version.start_with?("5.2"))
@@ -16,6 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require 'pry'
20
+
19
21
  shared_context "deploying with move" do
20
22
  before do
21
23
  Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
@@ -54,25 +56,62 @@ shared_examples_for "a file with the wrong content" do
54
56
  sha256_checksum(path).should == @expected_checksum
55
57
  end
56
58
 
57
- include_context "diff disabled"
59
+ describe "when diff is disabled" do
58
60
 
59
- context "when running action :create" do
60
- context "with backups enabled" do
61
- before do
62
- resource.run_action(:create)
61
+ include_context "diff disabled"
62
+
63
+ context "when running action :create" do
64
+ context "with backups enabled" do
65
+ before do
66
+ resource.run_action(:create)
67
+ end
68
+
69
+ it "overwrites the file with the updated content when the :create action is run" do
70
+ File.stat(path).mtime.should > @expected_mtime
71
+ sha256_checksum(path).should_not == @expected_checksum
72
+ end
73
+
74
+ it "backs up the existing file" do
75
+ Dir.glob(backup_glob).size.should equal(1)
76
+ end
77
+
78
+ it "is marked as updated by last action" do
79
+ resource.should be_updated_by_last_action
80
+ end
81
+
82
+ it "should restore the security contexts on selinux", :selinux_only do
83
+ selinux_security_context_restored?(path).should be_true
84
+ end
63
85
  end
64
86
 
65
- it "overwrites the file with the updated content when the :create action is run" do
66
- File.stat(path).mtime.should > @expected_mtime
67
- sha256_checksum(path).should_not == @expected_checksum
87
+ context "with backups disabled" do
88
+ before do
89
+ resource.backup(0)
90
+ resource.run_action(:create)
91
+ end
92
+
93
+ it "should not attempt to backup the existing file if :backup == 0" do
94
+ Dir.glob(backup_glob).size.should equal(0)
95
+ end
96
+
97
+ it "should restore the security contexts on selinux", :selinux_only do
98
+ selinux_security_context_restored?(path).should be_true
99
+ end
68
100
  end
101
+ end
69
102
 
70
- it "backs up the existing file" do
71
- Dir.glob(backup_glob).size.should equal(1)
103
+ describe "when running action :create_if_missing" do
104
+ before do
105
+ resource.run_action(:create_if_missing)
72
106
  end
73
107
 
74
- it "is marked as updated by last action" do
75
- resource.should be_updated_by_last_action
108
+ it "doesn't overwrite the file when the :create_if_missing action is run" do
109
+ File.stat(path).mtime.should == @expected_mtime
110
+ sha256_checksum(path).should == @expected_checksum
111
+ end
112
+
113
+ it "is not marked as updated" do
114
+ resource.should_not be_updated_by_last_action
76
115
  end
77
116
 
78
117
  it "should restore the security contexts on selinux", :selinux_only do
@@ -80,52 +119,53 @@ shared_examples_for "a file with the wrong content" do
80
119
  end
81
120
  end
82
121
 
83
- context "with backups disabled" do
122
+ describe "when running action :delete" do
84
123
  before do
85
- resource.backup(0)
86
- resource.run_action(:create)
124
+ resource.run_action(:delete)
87
125
  end
88
126
 
89
- it "should not attempt to backup the existing file if :backup == 0" do
90
- Dir.glob(backup_glob).size.should equal(0)
127
+ it "deletes the file" do
128
+ File.should_not exist(path)
91
129
  end
92
130
 
93
- it "should restore the security contexts on selinux", :selinux_only do
94
- selinux_security_context_restored?(path).should be_true
131
+ it "is marked as updated by last action" do
132
+ resource.should be_updated_by_last_action
95
133
  end
96
134
  end
135
+
97
136
  end
98
137
 
99
- describe "when running action :create_if_missing" do
100
- before do
101
- resource.run_action(:create_if_missing)
102
- end
138
+ context "when diff is enabled" do
139
+ describe 'sensitive attribute' do
140
+ context "should be insensitive by default" do
141
+ it { expect(resource.sensitive).to(be_false) }
142
+ end
103
143
 
104
- it "doesn't overwrite the file when the :create_if_missing action is run" do
105
- File.stat(path).mtime.should == @expected_mtime
106
- sha256_checksum(path).should == @expected_checksum
107
- end
144
+ context "when set" do
145
+ before { resource.sensitive(true) }
108
146
 
109
- it "is not marked as updated" do
110
- resource.should_not be_updated_by_last_action
111
- end
147
+ it "should be set on the resource" do
148
+ expect(resource.sensitive).to(be_true)
149
+ end
112
150
 
113
- it "should restore the security contexts on selinux", :selinux_only do
114
- selinux_security_context_restored?(path).should be_true
115
- end
116
- end
151
+ context "when running :create action" do
152
+ let(:provider) { resource.provider_for_action(:create) }
153
+ let(:reporter_messages) { provider.instance_variable_get("@converge_actions").actions[0][0] }
117
154
 
118
- describe "when running action :delete" do
119
- before do
120
- resource.run_action(:delete)
121
- end
155
+ before do
156
+ provider.run_action
157
+ end
122
158
 
123
- it "deletes the file" do
124
- File.should_not exist(path)
125
- end
159
+ it "should suppress the diff" do
160
+ expect(resource.diff).to(include('suppressed sensitive resource'))
161
+ expect(reporter_messages[1]).to eq("suppressed sensitive resource")
162
+ end
126
163
 
127
- it "is marked as updated by last action" do
128
- resource.should be_updated_by_last_action
164
+ it "should still include the updated checksums" do
165
+ expect(reporter_messages[0]).to include("update content in file")
166
+ end
167
+ end
168
+ end
129
169
  end
130
170
  end
131
171
  end
@@ -163,6 +163,13 @@ describe Chef::Application do
163
163
  @app.configure_logging
164
164
  end
165
165
 
166
+ it "should raise fatals if log location is invalid" do
167
+ Chef::Config[:log_location] = "/tmp/non-existing-dir/logfile"
168
+ Chef::Log.should_receive(:fatal).at_least(:once)
169
+ Process.should_receive(:exit)
170
+ @app.configure_logging
171
+ end
172
+
166
173
  shared_examples_for "log_level_is_auto" do
167
174
  context "when STDOUT is to a tty" do
168
175
  before do
@@ -306,11 +313,6 @@ describe Chef::Application do
306
313
  @config_file.unlink
307
314
  end
308
315
 
309
- it "should raise informative fatals for missing log file dir" do
310
- create_config_file('log_location "/tmp/non-existing-dir/logfile"')
311
- raises_informative_fatals_on_configure_chef
312
- end
313
-
314
316
  it "should raise informative fatals for badly written config" do
315
317
  create_config_file("text that should break the config parsing")
316
318
  raises_informative_fatals_on_configure_chef