diff options
-rw-r--r-- | kitchen-tests/cookbooks/end_to_end/recipes/windows.rb | 10 | ||||
-rw-r--r-- | lib/chef/resource/windows_firewall_profile.rb | 40 |
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 |