summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Magnus Rakvåg <tor.magnus@outlook.com>2019-10-07 19:12:03 +0200
committerTor Magnus Rakvåg <tor.magnus@outlook.com>2019-10-07 19:14:09 +0200
commit2f6c1141bba783b1d5ceb1a29397f28c0a7a02c4 (patch)
treeb29e8cb777a19472fcb5021ab0e5c532d3056253
parent44aa430f4e441f6aa11b6eb422cc413aa3b49e6e (diff)
downloadchef-2f6c1141bba783b1d5ceb1a29397f28c0a7a02c4.tar.gz
unkown profiles should raise a validation error
Signed-off-by: Tor Magnus Rakvåg <tor.magnus@outlook.com>
-rw-r--r--lib/chef/resource/windows_firewall_rule.rb7
-rw-r--r--spec/unit/resource/windows_firewall_rule_spec.rb5
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/chef/resource/windows_firewall_rule.rb b/lib/chef/resource/windows_firewall_rule.rb
index c7071e535e..0dbf9ec6b0 100644
--- a/lib/chef/resource/windows_firewall_rule.rb
+++ b/lib/chef/resource/windows_firewall_rule.rb
@@ -70,7 +70,12 @@ class Chef
property :profile, [Symbol, String, Array],
default: :any,
description: "The profile the firewall rule applies to.",
- coerce: proc { |p| Array(p).map(&:downcase).map(&:to_sym).sort }
+ coerce: proc { |p| Array(p).map(&:downcase).map(&:to_sym).sort },
+ callbacks: {
+ 'contains values not in :public, :private :domain, :any or :notapplicable' => lambda {
+ |p| p.all? { |e| %i{public private domain any notapplicable}.include?(e) }
+ }
+ }
property :program, String,
description: "The program the firewall rule applies to."
diff --git a/spec/unit/resource/windows_firewall_rule_spec.rb b/spec/unit/resource/windows_firewall_rule_spec.rb
index ff6cf776e6..d8d88941c4 100644
--- a/spec/unit/resource/windows_firewall_rule_spec.rb
+++ b/spec/unit/resource/windows_firewall_rule_spec.rb
@@ -152,6 +152,11 @@ describe Chef::Resource::WindowsFirewallRule do
expect(resource.profile).to eql([:notapplicable])
end
+ it "the profile property raises on any unknown values" do
+ expect { resource.profile(:other) }.to raise_error(Chef::Exceptions::ValidationFailed)
+ expect { resource.profile([:public, :other]) }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
it "the profile property coerces strings to symbols" do
resource.profile("Public")
expect(resource.profile).to eql([:public])