summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSergey Sergeev <zhirafovod@gmail.com>2014-04-10 00:34:12 -0700
committerBryan McLellan <btm@getchef.com>2014-06-10 09:05:38 -0700
commitcee94f52d52806885fbd63d63addc3708b25f409 (patch)
tree56d97f58cb9aea164df6791cf8a4ba3d9ec64c2e /spec
parent5265dec56c99698f09c94604e72552820370ff86 (diff)
downloadchef-cee94f52d52806885fbd63d63addc3708b25f409.tar.gz
CHEF-5098 fix sensitive data output on failure
provide a way to supprese sensitive attribute for a resource * add sensitive attribute to the resource class * fix output in resource_failure_inspector if sensitive attribute set * add spec tests for resource fix implementation based on PR reivew * suppres to_text ouptut if sensitive attribute set in resource * remove rescue of unset sentitive attribute in resource_failure_inspecto
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/resource_spec.rb37
1 files changed, 36 insertions, 1 deletions
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 99217af20e..dd6d58630f 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -344,7 +344,8 @@ describe Chef::Resource do
expected_keys = [ :allowed_actions, :params, :provider, :updated,
:updated_by_last_action, :before, :supports,
:noop, :ignore_failure, :name, :source_line,
- :action, :retries, :retry_delay, :elapsed_time, :guard_interpreter]
+ :action, :retries, :retry_delay, :elapsed_time,
+ :guard_interpreter, :sensitive ]
(hash.keys - expected_keys).should == []
(expected_keys - hash.keys).should == []
hash[:name].should eql("funk")
@@ -781,6 +782,40 @@ describe Chef::Resource do
end
end
+
+ describe "resource sensitive attribute" do
+
+ before(:each) do
+ @resource_file = Chef::Resource::File.new("/nonexistent/CHEF-5098/file", @run_context)
+ @action = :create
+ end
+
+ def compiled_resource_data(resource, action, err)
+ error_inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(resource, action, err)
+ description = Chef::Formatters::ErrorDescription.new("test")
+ error_inspector.add_explanation(description)
+ Chef::Log.info("descrtiption: #{description.inspect},error_inspector: #{error_inspector}")
+ description.sections[1]["Compiled Resource:"]
+ end
+
+ it "set to false by default" do
+ @resource.sensitive.should be_false
+ end
+
+ it "when set to false should show compiled resource for failed resource" do
+ expect { @resource_file.run_action(@action) }.to raise_error { |err|
+ compiled_resource_data(@resource_file, @action, err).should match 'path "/nonexistent/CHEF-5098/file"'
+ }
+ end
+
+ it "when set to true should show compiled resource for failed resource" do
+ @resource_file.sensitive true
+ expect { @resource_file.run_action(@action) }.to raise_error { |err|
+ compiled_resource_data(@resource_file, @action, err).should eql("suppressed sensitive resource output")
+ }
+ end
+
+ end
end
describe Chef::Resource::Notification do