summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandra Tiffin <sandi.tiffin@gmail.com>2017-12-12 11:32:41 -0800
committerSandra Tiffin <sandi.tiffin@gmail.com>2017-12-12 11:32:41 -0800
commitb3af979455390e45e7298a0542b670fb35a9a6cc (patch)
tree70e81f9a02d92eb3a9b4c6d739e7626480a33d4a
parent2ed7c7be81b930e99affb139f1854309d55fabb5 (diff)
downloadchef-b3af979455390e45e7298a0542b670fb35a9a6cc.tar.gz
fix for data bag names partially matching search reserved words
Signed-off-by: Sandra Tiffin <sandi.tiffin@gmail.com>
-rw-r--r--lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb2
-rw-r--r--spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb17
-rw-r--r--spec/unit/knife/data_bag_create_spec.rb21
3 files changed, 30 insertions, 10 deletions
diff --git a/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb b/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
index 4b272daabc..3b1fb53da6 100644
--- a/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
+++ b/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
@@ -5,7 +5,7 @@ class Chef
module ChefFS
module DataHandler
class DataBagItemDataHandler < DataHandlerBase
- RESERVED_NAMES = /node|role|environment|client/
+ RESERVED_NAMES = /^(node|role|environment|client)$/
def normalize(data_bag_item, entry)
# If it's wrapped with raw_data, unwrap it.
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)