summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneha-p6 <neha.pansare6@gmail.com>2022-01-27 17:26:24 +0530
committerNeha Pansare <neha.pansare@progress.com>2022-02-09 18:42:07 +0530
commit1db710e55ec53d12222654818f577044f63168d1 (patch)
tree4e180dfa6bdc26c05ce33e0f83ff2e97beec73ed
parent1c8f84f84d267524076e2d0c5a69bc23be04f593 (diff)
downloadchef-1db710e55ec53d12222654818f577044f63168d1.tar.gz
Validate resource spec passed to subscribes
Signed-off-by: Neha Pansare <neha.pansare@progress.com>
-rw-r--r--lib/chef/resource.rb1
-rw-r--r--spec/unit/resource_spec.rb8
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 681927f1d0..f9ab292b83 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -341,6 +341,7 @@ class Chef
def subscribes(action, resources, timing = :delayed)
resources = [resources].flatten
resources.each do |resource|
+ validate_resource_spec!(resource)
if resource.is_a?(String)
resource = UnresolvedSubscribes.new(resource, run_context)
end
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index f20a6d3bc6..86e666c00e 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -300,6 +300,14 @@ describe Chef::Resource do
end
describe "subscribes" do
+ context "with syntax error in resources parameter" do
+ it "raises an exception immediately" do
+ expect do
+ resource.subscribes(:run, "typo[missing-closing-bracket")
+ end.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
+ end
+ end
+
it "should make resources appear in the actions hash of subscribed nodes" do
run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
zr = run_context.resource_collection.find(zen_master: "coffee")