summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-11-06 14:55:03 -0800
committerTim Smith <tsmith@chef.io>2018-11-07 10:21:58 -0800
commit04c1a5c8e344fc60c5438dd15c095748625b39fa (patch)
tree9b0dcd12e53a6384fbb3162862a875b3113e0a3b
parentab904069fdaed0f4301aa1868778c68b8492be14 (diff)
downloadchef-firewall_ports_14.tar.gz
Coerce arrays of ints to an array of stringsfirewall_ports_14
Otherwise it won't compare to the PS output Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/windows_firewall_rule.rb6
-rw-r--r--spec/unit/resource/windows_firewall_rule_spec.rb13
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/chef/resource/windows_firewall_rule.rb b/lib/chef/resource/windows_firewall_rule.rb
index 9c8522dc5a..271b9fcc41 100644
--- a/lib/chef/resource/windows_firewall_rule.rb
+++ b/lib/chef/resource/windows_firewall_rule.rb
@@ -42,14 +42,16 @@ class Chef
description: "The local address the firewall rule applies to."
property :local_port, [String, Integer, Array],
- coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort },
+ # split various formats of comma separated lists and provide a sorted array of strings to match PS output
+ coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort.map { |x| x.to_s } },
description: "The local port the firewall rule applies to."
property :remote_address, String,
description: "The remote address the firewall rule applies to."
property :remote_port, [String, Integer, Array],
- coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort },
+ # split various formats of comma separated lists and provide a sorted array of strings to match PS output
+ coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort.map { |x| x.to_s } },
description: "The remote port the firewall rule applies to."
property :direction, [Symbol, String],
diff --git a/spec/unit/resource/windows_firewall_rule_spec.rb b/spec/unit/resource/windows_firewall_rule_spec.rb
index 228e94f9c0..629e91d74f 100644
--- a/spec/unit/resource/windows_firewall_rule_spec.rb
+++ b/spec/unit/resource/windows_firewall_rule_spec.rb
@@ -55,7 +55,7 @@ describe Chef::Resource::WindowsFirewallRule do
it "the local_port property accepts integers" do
resource.local_port(8080)
- expect(resource.local_port).to eql([8080])
+ expect(resource.local_port).to eql(["8080"])
end
it "the local_port property accepts strings" do
@@ -73,6 +73,11 @@ describe Chef::Resource::WindowsFirewallRule do
expect(resource.local_port).to eql(%w{8080 8081})
end
+ it "the local_port property accepts arrays and coerces to a sorta array of strings" do
+ resource.local_port([8081, 8080])
+ expect(resource.local_port).to eql(%w{8080 8081})
+ end
+
it "the remote_address property accepts strings" do
resource.remote_address("8.8.4.4")
expect(resource.remote_address).to eql("8.8.4.4")
@@ -85,7 +90,7 @@ describe Chef::Resource::WindowsFirewallRule do
it "the remote_port property accepts integers" do
resource.remote_port(8081)
- expect(resource.remote_port).to eql([8081])
+ expect(resource.remote_port).to eql(["8081"])
end
it "the remote_port property accepts comma separated lists without spaces" do
@@ -98,9 +103,9 @@ describe Chef::Resource::WindowsFirewallRule do
expect(resource.remote_port).to eql(%w{8080 8081})
end
- it "the remote_port property accepts arrays and sorts the array" do
+ it "the remote_port property accepts arrays and coerces to a sorta array of strings" do
resource.remote_port([8081, 8080])
- expect(resource.remote_port).to eql([8080, 8081])
+ expect(resource.remote_port).to eql(%w{8080 8081})
end
it "the direction property accepts :inbound and :outbound" do