summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavin Taddeo <davin@chef.io>2020-09-10 10:14:38 -0400
committerDavin Taddeo <davin@chef.io>2020-09-10 10:14:38 -0400
commite5050bbbfb578987e5a17a7c4ed27a06586fbb24 (patch)
treea016e3305fec3ef6738cb0d4f72705fad402f956
parent8f60110bfa9485eb31e33df7c27e2646fb3bcc31 (diff)
downloadchef-e5050bbbfb578987e5a17a7c4ed27a06586fbb24.tar.gz
Update the windows_firewall_profile resource to move the load_firewall_state method out of the action_class. Also add some firewall tests to the kitchen tests to avoid this issue in the future.
Signed-off-by: Davin Taddeo <davin@chef.io>
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/windows.rb10
-rw-r--r--lib/chef/resource/windows_firewall_profile.rb40
2 files changed, 32 insertions, 18 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
index 3e069a43b0..33fc16e38a 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
@@ -32,6 +32,16 @@ windows_security_policy "EnableGuestAccount" do
secvalue "1"
end
+windows_firewall_profile "Domain" do
+ default_inbound_action "Allow"
+ default_outbound_action "Allow"
+ action :enable
+end
+
+windows_firewall_profile "Public" do
+ action :disable
+end
+
users_manage "remove sysadmin" do
group_name "sysadmin"
group_id 2300
diff --git a/lib/chef/resource/windows_firewall_profile.rb b/lib/chef/resource/windows_firewall_profile.rb
index b90d9fd4d5..72dc19da88 100644
--- a/lib/chef/resource/windows_firewall_profile.rb
+++ b/lib/chef/resource/windows_firewall_profile.rb
@@ -161,24 +161,6 @@ class Chef
cmd
end
- def load_firewall_state(profile_name)
- <<-EOH
- Remove-TypeData System.Array # workaround for PS bug here: https://bit.ly/2SRMQ8M
- $#{profile_name} = Get-NetFirewallProfile -Profile #{profile_name}
- ([PSCustomObject]@{
- default_inbound_action = $#{profile_name}.DefaultInboundAction.ToString()
- default_outbound_action = $#{profile_name}.DefaultOutboundAction.ToString()
- allow_inbound_rules = $#{profile_name}.AllowInboundRules.ToString()
- allow_local_firewall_rules = $#{profile_name}.AllowLocalFirewallRules.ToString()
- allow_local_ipsec_rules = $#{profile_name}.AllowLocalIPsecRules.ToString()
- allow_user_apps = $#{profile_name}.AllowUserApps.ToString()
- allow_user_ports = $#{profile_name}.AllowUserPorts.ToString()
- allow_unicast_response = $#{profile_name}.AllowUnicastResponseToMulticast.ToString()
- display_notification = $#{profile_name}.NotifyOnListen.ToString()
- }) | ConvertTo-Json
- EOH
- end
-
def firewall_enabled?(profile_name)
cmd = <<~CODE
$#{profile_name} = Get-NetFirewallProfile -Profile #{profile_name}
@@ -194,6 +176,28 @@ class Chef
end
end
end
+
+ private
+
+ # build the command to load the current resource
+ # @return [String] current firewall state
+ def load_firewall_state(profile_name)
+ <<-EOH
+ Remove-TypeData System.Array # workaround for PS bug here: https://bit.ly/2SRMQ8M
+ $#{profile_name} = Get-NetFirewallProfile -Profile #{profile_name}
+ ([PSCustomObject]@{
+ default_inbound_action = $#{profile_name}.DefaultInboundAction.ToString()
+ default_outbound_action = $#{profile_name}.DefaultOutboundAction.ToString()
+ allow_inbound_rules = $#{profile_name}.AllowInboundRules.ToString()
+ allow_local_firewall_rules = $#{profile_name}.AllowLocalFirewallRules.ToString()
+ allow_local_ipsec_rules = $#{profile_name}.AllowLocalIPsecRules.ToString()
+ allow_user_apps = $#{profile_name}.AllowUserApps.ToString()
+ allow_user_ports = $#{profile_name}.AllowUserPorts.ToString()
+ allow_unicast_response = $#{profile_name}.AllowUnicastResponseToMulticast.ToString()
+ display_notification = $#{profile_name}.NotifyOnListen.ToString()
+ }) | ConvertTo-Json
+ EOH
+ end
end
end
end