]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
MODULES-1453 - overly aggressive gsub
authorMorgan Haskel <morgan@puppetlabs.com>
Fri, 23 Jan 2015 23:36:54 +0000 (15:36 -0800)
committerMorgan Haskel <morgan@puppetlabs.com>
Fri, 23 Jan 2015 23:36:54 +0000 (15:36 -0800)
Make sure there's a space after '-A' before gsubbing with '-D'. Was
causing issues with `ensure => absent` and `log_prefix =>
'FW-A-<whatever>'`

lib/puppet/provider/firewall/iptables.rb
spec/acceptance/firewall_spec.rb

index 2a1b7d59cdf36aa4aa9d90ef789eda363a879d57..74fa219a31cc6ad5fa9763edec3ca5f409e4b275 100644 (file)
@@ -438,7 +438,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
 
index 92df09390d71a2e4f0b20406a7302bee5e7ce5a0..ac47f71750d79b5e4d0b30b414bfaa330a0ab042 100644 (file)
@@ -2207,4 +2207,43 @@ describe 'firewall type', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfami
     end
   end
 
+  context 'log_prefix containing -A' do
+    it 'adds the rule' do
+      pp = <<-EOS
+      class { '::firewall': }
+      firewall { '700 - test':
+        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 "100 foo bar" -j LOG --log-prefix "FW-A-INPUT: "/)
+      end
+    end
+
+    it 'removes the rule' do
+      pp = <<-EOS
+      class { '::firewall': }
+      firewall { '700 - test':
+        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 "100 foo bar" -j LOG --log-prefix "FW-A-INPUT: "/)
+      end
+    end
+  end
+
 end