]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
MODULES-2186 - iptables rules with -A in comment
authorTommy McNeely <tommy@lark-it.com>
Thu, 2 Jul 2015 15:16:46 +0000 (09:16 -0600)
committerTommy McNeely <tommy@lark-it.com>
Thu, 2 Jul 2015 15:16:46 +0000 (09:16 -0600)
lib/puppet/provider/firewall/iptables.rb
spec/acceptance/firewall_spec.rb

index fcf9373d0a32f8375878c59d6e48b1541cf6e2cb..3c1bec4e7e3b4defec46eba8c9405b882f905f65 100644 (file)
@@ -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
 
index f131cfbc8d60db73ac9e617ec1269b31724ce23e..7c4cee612cb02ab4cab6cf9b61164447dc10a976 100644 (file)
@@ -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