Skip to content

Commit

Permalink
Merge pull request #90 from Nekototori/remove_facts
Browse files Browse the repository at this point in the history
removed operatingsystemversion and old os testing
  • Loading branch information
natemccurdy committed May 1, 2019
2 parents f700777 + ec557d6 commit 43c2a08
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 384 deletions.
59 changes: 16 additions & 43 deletions manifests/exception.pp
Expand Up @@ -93,19 +93,8 @@

# Check if we're allowing a program or port/protocol and validate accordingly
if $program == undef {
#check whether to use 'localport', or just 'port' depending on OS
case $::operatingsystemversion {
/Windows Server 2003/, /Windows XP/: {
$local_port_param = 'port'
unless empty($remote_port) {
fail "Sorry, :remote_port param is not supported on ${::operatingsystemversion}"
}
}
default: {
$local_port_param = 'localport'
$remote_port_param = 'remoteport'
}
}
$local_port_param = 'localport'
$remote_port_param = 'remoteport'

$fw_command = 'portopening'

Expand Down Expand Up @@ -139,12 +128,7 @@
validate_absolute_path($program)
}

case $::operatingsystemversion {
'Windows Server 2012', 'Windows Server 2008', 'Windows Server 2008 R2', 'Windows Vista','Windows 7','Windows 8': {
validate_slength($description,255)
}
default: { }
}
validate_slength($description,255)

# Set command to check for existing rules
$netsh_exe = "${facts['os']['windows']['system32']}\\netsh.exe"
Expand All @@ -164,32 +148,21 @@
$fw_description = ''
}

case $::operatingsystemversion {
/Windows Server 2003/, /Windows XP/: {
$mode = $enabled ? {
true => 'ENABLE',
false => 'DISABLE',
}
$netsh_command = "${netsh_exe} firewall ${fw_action} ${fw_command} name=\"${display_name}\" mode=${mode} ${allow_context}"
}
default: {
$mode = $enabled ? {
true => 'yes',
false => 'no',
}
$edge = $allow_edge_traversal ? {
true => 'yes',
false => 'no',
}

if $fw_action == 'delete' and $program == undef {
$netsh_command = "${netsh_exe} advfirewall firewall ${fw_action} rule name=\"${display_name}\" ${fw_description} dir=${direction} ${allow_context} remoteip=\"${remote_ip}\""
} else {
$netsh_command = "${netsh_exe} advfirewall firewall ${fw_action} rule name=\"${display_name}\" ${fw_description} dir=${direction} action=${action} enable=${mode} edge=${edge} ${allow_context} remoteip=\"${remote_ip}\""
}
}
$mode = $enabled ? {
true => 'yes',
false => 'no',
}
$edge = $allow_edge_traversal ? {
true => 'yes',
false => 'no',
}

if $fw_action == 'delete' and $program == undef {
$netsh_command = "${netsh_exe} advfirewall firewall ${fw_action} rule name=\"${display_name}\" ${fw_description} dir=${direction} ${allow_context} remoteip=\"${remote_ip}\""
} else {
$netsh_command = "${netsh_exe} advfirewall firewall ${fw_action} rule name=\"${display_name}\" ${fw_description} dir=${direction} action=${action} enable=${mode} edge=${edge} ${allow_context} remoteip=\"${remote_ip}\""
}
#
exec { "set rule ${display_name}":
command => $netsh_command,
provider => windows,
Expand Down
9 changes: 1 addition & 8 deletions manifests/init.pp
Expand Up @@ -26,14 +26,7 @@
String $ensure = 'running',
) {

case $::operatingsystemversion {
/Windows Server 2003/,/Windows Server 2003 R2/,/Windows XP/: {
$firewall_name = 'SharedAccess'
}
default: {
$firewall_name = 'MpsSvc'
}
}
$firewall_name = 'MpsSvc'

if $ensure == 'running' {
$enabled = true
Expand Down
89 changes: 2 additions & 87 deletions spec/classes/windows_firewall/windows_firewall_spec.rb
@@ -1,52 +1,8 @@
require 'spec_helper'

describe 'windows_firewall', type: :class do
['Windows Server 2003', 'Windows Server 2003 R2', 'Windows XP'].each do |os|
['Windows 2012', 'Windows Server 2008', 'Windows Server 2008 R2', 'Windows 8', 'Windows 7'].each do |os|
context "with OS: #{os}, ensure: running" do
let :facts do
{ operatingsystemversion: os }
end
let :params do
{ ensure: 'running' }
end

it do
is_expected.to contain_service('windows_firewall').with(
'name' => 'SharedAccess',
'ensure' => 'running',
'enable' => 'true'
)
end

it do
is_expected.to contain_registry_value('EnableFirewallDomainProfile').with(
'ensure' => 'present',
'path' => '32:HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile\EnableFirewall',
'data' => '1'
)
end
it do
is_expected.to contain_registry_value('EnableFirewallPublicProfile').with(
'ensure' => 'present',
'path' => '32:HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\PublicProfile\EnableFirewall',
'data' => '1'
)
end
it do
is_expected.to contain_registry_value('EnableFirewallStandardProfile').with(
'ensure' => 'present',
'path' => '32:HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\EnableFirewall',
'data' => '1'
)
end
end
end

['Windows 2012', 'Windows Server 2008', 'Windows Server 2008 R2', 'Windows 8', 'Windows 7', 'Windows Vista'].each do |os|
context "with OS: #{os}, ensure: running" do
let :facts do
{ operatingsystemversion: os }
end
let :params do
{ ensure: 'running' }
end
Expand Down Expand Up @@ -83,48 +39,7 @@
end
end

['Windows Server 2003', 'Windows Server 2003 R2', 'Windows XP'].each do |os|
context "with OS: #{os}, ensure: stopped" do
let :facts do
{ operatingsystemversion: os }
end
let :params do
{ ensure: 'stopped' }
end

it do
is_expected.to contain_service('windows_firewall').with(
'name' => 'SharedAccess',
'ensure' => 'stopped',
'enable' => 'false'
)
end

it do
is_expected.to contain_registry_value('EnableFirewallDomainProfile').with(
'ensure' => 'present',
'path' => '32:HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile\EnableFirewall',
'data' => '0'
)
end
it do
is_expected.to contain_registry_value('EnableFirewallPublicProfile').with(
'ensure' => 'present',
'path' => '32:HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\PublicProfile\EnableFirewall',
'data' => '0'
)
end
it do
is_expected.to contain_registry_value('EnableFirewallStandardProfile').with(
'ensure' => 'present',
'path' => '32:HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\EnableFirewall',
'data' => '0'
)
end
end
end

['Windows 2012', 'Windows Server 2008', 'Windows Server 2008 R2', 'Windows 8', 'Windows 7', 'Windows Vista'].each do |os|
['Windows 2012', 'Windows Server 2008', 'Windows Server 2008 R2', 'Windows 8', 'Windows 7'].each do |os|
context "with OS: #{os}, ensure: stopped" do
let :facts do
{ operatingsystemversion: os }
Expand Down

0 comments on commit 43c2a08

Please sign in to comment.