diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 10 | ||||
-rw-r--r-- | spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb | 17 | ||||
-rw-r--r-- | spec/unit/knife/data_bag_create_spec.rb | 21 | ||||
-rw-r--r-- | spec/unit/resource/file/verification_spec.rb | 22 |
4 files changed, 56 insertions, 14 deletions
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index b58159fcc9..d508e76b24 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -476,7 +476,15 @@ shared_examples_for Chef::Provider::File do allow(File).to receive(:directory?).with("C:\\Windows\\system32/cmd.exe").and_return(false) provider.new_resource.verify windows? ? "REM" : "true" provider.new_resource.verify windows? ? "cmd.exe /c exit 1" : "false" - expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, "Proposed content for #{provider.new_resource.path} failed verification #{windows? ? "cmd.exe /c exit 1" : "false"}") + end + + it "does not show verification for sensitive resources" do + allow(File).to receive(:directory?).with("C:\\Windows\\system32/cmd.exe").and_return(false) + provider.new_resource.verify windows? ? "REM" : "true" + provider.new_resource.verify windows? ? "cmd.exe /c exit 1" : "false" + provider.new_resource.sensitive true + expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, "Proposed content for #{provider.new_resource.path} failed verification [sensitive]") end end end diff --git a/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb b/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb index fea7a2d54d..6d6e2fb0e6 100644 --- a/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb +++ b/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb @@ -66,14 +66,17 @@ describe Chef::ChefFS::DataHandler::DataBagItemDataHandler do end end - context "valid data" do - let(:entry) { TestDataBagItem.new("luggage", "bag") } - let(:object) do - { "raw_data" => { "id" => "bag" } } - end - it "validates the data bag item" do - expect(handler.verify_integrity(object, entry)).to be_nil + context "using a reserved word as part of the data bag name" do + %w{xnode rolex xenvironmentx xclientx}.each do |bag_name| + let(:entry) { TestDataBagItem.new("#{bag_name}", "bag") } + let(:object) do + { "raw_data" => { "id" => "bag" } } + end + it "allows the data bag name '#{bag_name}'" do + expect(handler.verify_integrity(object, entry)).to be_nil + end end end + end end diff --git a/spec/unit/knife/data_bag_create_spec.rb b/spec/unit/knife/data_bag_create_spec.rb index c586a8df1d..169c6e1845 100644 --- a/spec/unit/knife/data_bag_create_spec.rb +++ b/spec/unit/knife/data_bag_create_spec.rb @@ -46,8 +46,8 @@ describe Chef::Knife::DataBagCreate do allow(knife).to receive(:config).and_return(config) end - context "when data_bag already exist" do - it "doesn't creates a data bag" do + context "when data_bag already exists" do + it "doesn't create a data bag" do expect(knife).to receive(:create_object).and_yield(raw_hash) expect(rest).to receive(:get).with("data/#{bag_name}") expect(rest).to_not receive(:post).with("data", { "name" => bag_name }) @@ -114,6 +114,23 @@ describe Chef::Knife::DataBagCreate do end end + context "when given a data bag name partially matching a reserved name for search" do + %w{xnode rolex xenvironmentx xclientx}.each do |name| + let(:bag_name) { name } + + before do + knife.name_args = [bag_name] + end + + it "creates a data bag named '#{name}'" do + expect(rest).to receive(:post).with("data", { "name" => bag_name }) + expect(knife.ui).to receive(:info).with("Created data_bag[#{bag_name}]") + + knife.run + end + end + end + context "no secret is specified for encryption" do let(:item) do item = Chef::DataBagItem.from_hash(raw_hash) diff --git a/spec/unit/resource/file/verification_spec.rb b/spec/unit/resource/file/verification_spec.rb index feacd715a4..e46040268a 100644 --- a/spec/unit/resource/file/verification_spec.rb +++ b/spec/unit/resource/file/verification_spec.rb @@ -66,6 +66,11 @@ describe Chef::Resource::File::Verification do v = Chef::Resource::File::Verification.new(parent_resource, nil, {}, &f_block) expect(v.verify(temp_path)).to eq(false) end + + it "responds to to_s" do + v = Chef::Resource::File::Verification.new(parent_resource, nil, {}) {} + expect(v.to_s).to eq("<Proc>") + end end context "with a verification command(String)" do @@ -110,23 +115,32 @@ describe Chef::Resource::File::Verification do v = Chef::Resource::File::Verification.new(parent_resource, "true", {}) expect(v.verify(temp_path)).to eq(true) end + + it "responds to to_s" do + v = Chef::Resource::File::Verification.new(parent_resource, "some command --here", {}) + expect(v.to_s).to eq("some command --here") + end end context "with a named verification(Symbol)" do + let(:registered_verification) { double("registered_verification") } + subject { described_class.new(parent_resource, :cats, {}) } before(:each) do class Chef::Resource::File::Verification::Turtle < Chef::Resource::File::Verification provides :cats def verify(path, opts) end end + allow(Chef::Resource::File::Verification::Turtle).to receive(:new).and_return(registered_verification) end it "delegates to the registered verification" do - registered_verification = double() - allow(Chef::Resource::File::Verification::Turtle).to receive(:new).and_return(registered_verification) - v = Chef::Resource::File::Verification.new(parent_resource, :cats, {}) expect(registered_verification).to receive(:verify).with(temp_path, {}) - v.verify(temp_path, {}) + subject.verify(temp_path, {}) + end + + it "responds to to_s" do + expect(subject.to_s).to eq(":cats (Chef::Resource::File::Verification::Turtle)") end end end |