]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
MODULES-1552 - Issues parsing `-m (tcp|udp)` rules
authorMorgan Haskel <morgan@puppetlabs.com>
Wed, 7 Jan 2015 17:29:56 +0000 (12:29 -0500)
committerMorgan Haskel <morgan@puppetlabs.com>
Wed, 7 Jan 2015 18:45:03 +0000 (13:45 -0500)
The parser was arbitrarily requiring `--(d|s)port` or `-m multiport` with
`-m tcp` or `-m udp`. Remove `-m (tcp|udp)` when converting to hash
unless it's `-m tcp --tcp-flags`.

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

index cda5d08bdda82f43bd49b337d3aa10aa7a4f7fc8..c8429074d651b562998ed6c5d6fed08113b42739 100644 (file)
@@ -233,7 +233,7 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
     # the actual rule will have the ! mark before the option.
     values = values.gsub(/(!)\s*(-\S+)\s*(\S*)/, '\2 "\1 \3"')
     # The match extension for tcp & udp are optional and throws off the @resource_map.
-    values = values.gsub(/-m (tcp|udp) (--(s|d)port|-m multiport)/, '\2')
+    values = values.gsub(/(?!-m tcp --tcp-flags)-m (tcp|udp) /, '')
     # '--pol ipsec' takes many optional arguments; we cheat again by adding " around them
     values = values.sub(/
         --pol\sipsec
index 5359a17f0e04ec7f26e6075aa0330e29e072eb0c..f2b0141ce5013731c862dcb763b480e4af49071c 100644 (file)
@@ -133,6 +133,21 @@ describe 'puppet resource firewall command:', :unless => UNSUPPORTED_PLATFORMS.i
     end
   end
 
+  context 'accepts rules with -m (tcp|udp) without dport/sport' do
+    before :all do
+      iptables_flush_all_tables
+      shell('iptables -A INPUT -s 10.0.0.0/8 -p udp -m udp -j ACCEPT')
+    end
+
+    it do
+      shell('puppet resource firewall') do |r|
+        r.exit_code.should be_zero
+        # don't check stdout, testing preexisting rules, output is normal
+        r.stderr.should be_empty
+      end
+    end
+  end
+
   # version of iptables that ships with el5 doesn't work with the
   # ip6tables provider
   if default['platform'] !~ /el-5/