]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
Fix problem with parsing rules without quotes
authorŁukasz Czapliński <lczaplinski@opera.com>
Wed, 5 Aug 2020 15:13:44 +0000 (17:13 +0200)
committerŁukasz Czapliński <lczaplinski@opera.com>
Wed, 5 Aug 2020 15:13:44 +0000 (17:13 +0200)
lib/puppet/provider/firewall/iptables.rb
spec/fixtures/iptables/conversion_hash.rb

index ee5daaee707c36fb671c4b3d396e8c211f50fe17..76dc990ac2666ce9ede692ecaa4bc97d5af71e5d 100644 (file)
@@ -465,7 +465,7 @@ Puppet::Type.type(:firewall).provide :iptables, parent: Puppet::Provider::Firewa
       ind = values.index('-m comment --comment')
       comments = values.scan(%r{-m comment --comment "((?:\\"|[^"])*)"})
       comments += values.scan(%r{-m comment --comment ([^"\s]+)\b})
-      values = values.gsub(%r{-m comment --comment (".*?[^\\"]"|[^ ].*)( |$)}, '')
+      values = values.gsub(%r{-m comment --comment (".*?[^\\"]")( |$)}, '')
       values = values.gsub(%r{-m comment --comment ([^"].*?)[ $]}, '')
       values.insert(ind, "-m comment --comment \"#{comments.join(';')}\" ")
     end
index 89ba6852d705b8686c50fbd39177a61974027ec0..25e67bf6a28a688b6ddf4383167a32dfbc156590 100644 (file)
@@ -234,38 +234,43 @@ ARGS_TO_HASH = {
     },
   },
   'comment_string_character_validation' => {
-    line: '-A INPUT -s 192.168.0.1/32 -m comment --comment "000 allow from 192.168.0.1, please"',
+    line: '-A INPUT -s 192.168.0.1/32 -m comment --comment "000 allow from 192.168.0.1, please" -j ACCEPT',
     table: 'filter',
     params: {
       source: '192.168.0.1/32',
+      action: 'accept',
     },
   },
   'multiple_comments' => {
-    line: '-A INPUT -s 192.168.0.1/32 -m comment --comment "000 allow from 192.168.0.1, please" -m comment --comment "another comment"',
+    line: '-A INPUT -s 192.168.0.1/32 -m comment --comment "000 allow from 192.168.0.1, please" -m comment --comment "another comment" -j ACCEPT',
     table: 'filter',
     params: {
       name: '000 allow from 192.168.0.1, please;another comment',
+      action: 'accept',
     },
   },
-  'comments_without_quotes' => {
-    line: '-A INPUT -s 192.168.0.1/32 -m comment --comment comment_without_quotes',
+  'comments_without_quotes_with_underscores' => {
+    line: '-A INPUT -s 192.168.0.1/32 -m comment --comment comment_without_quotes -j ACCEPT',
     table: 'filter',
     params: {
       name: '9000 comment_without_quotes',
+      action: 'accept',
     },
   },
-  'comments_without_quotes' => {
-    line: '-A INPUT -s 192.168.0.1/32 -m comment --comment 100-comment_without-quotes',
+  'comments_without_quotes_with_dashes' => {
+    line: '-A INPUT -s 192.168.0.1/32 -m comment --comment 100-comment_without-quotes -j ACCEPT',
     table: 'filter',
     params: {
       name: '100-comment_without-quotes',
+      action: 'accept',
     },
   },
   'string_escape_sequences' => {
-    line: '-A INPUT -m comment --comment "000 parse escaped \\"s, \\"s, \\\'s, \\\'s, \\\\s and \\\\s"',
+    line: '-A INPUT -m comment --comment "000 parse escaped \\"s, \\"s, \\\'s, \\\'s, \\\\s and \\\\s" -j ACCEPT',
     table: 'filter',
     params: {
       name: '000 parse escaped "s, "s, \'s, \'s, \\s and \\s',
+      action: 'accept',
     },
   },
   'log_level_debug' => {