From: Tommy McNeely Date: Thu, 2 Jul 2015 15:16:46 +0000 (-0600) Subject: MODULES-2186 - iptables rules with -A in comment X-Git-Tag: 1.7.0~9^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=511f21cc6a6ea8837cfa4e3c515d21577f4da654;p=puppet-modules%2Fpuppetlabs-firewall.git MODULES-2186 - iptables rules with -A in comment --- diff --git a/lib/puppet/provider/firewall/iptables.rb b/lib/puppet/provider/firewall/iptables.rb index fcf9373..3c1bec4 100644 --- a/lib/puppet/provider/firewall/iptables.rb +++ b/lib/puppet/provider/firewall/iptables.rb @@ -535,7 +535,7 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir def delete_args # Split into arguments - line = properties[:line].gsub(/\-A /, '-D ').split(/\s(?=(?:[^"]|"[^"]*")*$)/).map{|v| v.gsub(/"/, '')} + line = properties[:line].gsub(/^\-A /, '-D ').split(/\s(?=(?:[^"]|"[^"]*")*$)/).map{|v| v.gsub(/"/, '')} line.unshift("-t", properties[:table]) end diff --git a/spec/acceptance/firewall_spec.rb b/spec/acceptance/firewall_spec.rb index f131cfb..7c4cee6 100644 --- a/spec/acceptance/firewall_spec.rb +++ b/spec/acceptance/firewall_spec.rb @@ -2330,4 +2330,44 @@ describe 'firewall type', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfami end end + context 'comment containing "-A "' do + it 'adds the rule' do + pp = <<-EOS + class { '::firewall': } + firewall { '700 - blah-A Test Rule': + jump => 'LOG', + log_prefix => 'FW-A-INPUT: ', + } + EOS + + apply_manifest(pp, :catch_failures => true) + end + + it 'should contain the rule' do + shell('iptables-save') do |r| + expect(r.stdout).to match(/-A INPUT -p tcp -m comment --comment "700 - blah-A Test Rule" -j LOG --log-prefix "FW-A-INPUT: "/) + end + end + + it 'removes the rule' do + pp = <<-EOS + class { '::firewall': } + firewall { '700 - blah-A Test Rule': + ensure => absent, + jump => 'LOG', + log_prefix => 'FW-A-INPUT: ', + } + EOS + + apply_manifest(pp, :catch_failures => true) + end + + it 'should not contain the rule' do + shell('iptables-save') do |r| + expect(r.stdout).to_not match(/-A INPUT -p tcp -m comment --comment "700 - blah-A Test Rule" -j LOG --log-prefix "FW-A-INPUT: "/) + end + end + end + + end