Skip to content

Commit

Permalink
(MODULES-1592) Allow src_type and dst_type prefixed with '! ' to pass…
Browse files Browse the repository at this point in the history
… validation
  • Loading branch information
Jason Stangroome authored and jonnytdevops committed Jun 15, 2015
1 parent 27d063d commit a9f8c61
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/puppet/type/firewall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,10 @@ def should_to_s(value)
* XRESOLVE - undocumented
EOS

newvalues(:UNSPEC, :UNICAST, :LOCAL, :BROADCAST, :ANYCAST, :MULTICAST,
:BLACKHOLE, :UNREACHABLE, :PROHIBIT, :THROW, :NAT, :XRESOLVE)
newvalues(*[:UNSPEC, :UNICAST, :LOCAL, :BROADCAST, :ANYCAST, :MULTICAST,
:BLACKHOLE, :UNREACHABLE, :PROHIBIT, :THROW, :NAT, :XRESOLVE].collect do |address_type|
[address_type, "! #{address_type}".to_sym]
end.flatten)
end

newproperty(:src_type, :required_features => :address_type) do
Expand All @@ -348,8 +350,10 @@ def should_to_s(value)
* XRESOLVE - undocumented
EOS

newvalues(:UNSPEC, :UNICAST, :LOCAL, :BROADCAST, :ANYCAST, :MULTICAST,
:BLACKHOLE, :UNREACHABLE, :PROHIBIT, :THROW, :NAT, :XRESOLVE)
newvalues(*[:UNSPEC, :UNICAST, :LOCAL, :BROADCAST, :ANYCAST, :MULTICAST,
:BLACKHOLE, :UNREACHABLE, :PROHIBIT, :THROW, :NAT, :XRESOLVE].collect do |address_type|
[address_type, "! #{address_type}".to_sym]
end.flatten)
end

newproperty(:proto) do
Expand Down
49 changes: 49 additions & 0 deletions spec/acceptance/firewall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,30 @@ class { '::firewall': }
end
end

context '! MULTICAST' do
it 'applies' do
pp = <<-EOS
class { '::firewall': }
firewall { '563 - test inversion':
proto => tcp,
action => accept,
#{type} => '! MULTICAST',
}
EOS

apply_manifest(pp, :catch_failures => true)
unless fact('selinux') == 'true'
apply_manifest(pp, :catch_changes => true)
end
end

it 'should contain the rule' do
shell('iptables-save') do |r|
expect(r.stdout).to match(/-A INPUT -p tcp -m addrtype( !\s.*\sMULTICAST|\s.*\s! MULTICAST) -m comment --comment "563 - test inversion" -j ACCEPT/)
end
end
end

context 'BROKEN' do
it 'fails' do
pp = <<-EOS
Expand Down Expand Up @@ -1617,6 +1641,31 @@ class { '::firewall': }
end
end

context '! MULTICAST' do
it 'applies' do
pp = <<-EOS
class { '::firewall': }
firewall { '603 - test inversion':
proto => tcp,
action => accept,
#{type} => '! MULTICAST',
provider => 'ip6tables',
}
EOS

apply_manifest(pp, :catch_failures => true)
unless fact('selinux') == 'true'
apply_manifest(pp, :catch_changes => true)
end
end

it 'should contain the rule' do
shell('ip6tables-save') do |r|
expect(r.stdout).to match(/-A INPUT -p tcp -m addrtype( !\s.*\sMULTICAST|\s.*\s! MULTICAST) -m comment --comment "603 - test inversion" -j ACCEPT/)
end
end
end

context 'BROKEN' do
it 'fails' do
pp = <<-EOS
Expand Down

0 comments on commit a9f8c61

Please sign in to comment.