]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
Add unit and acceptance tests for the recent iptables module
authorMike Bryant <mike@mikebryant.me.uk>
Mon, 3 Feb 2014 16:26:43 +0000 (16:26 +0000)
committerHunter Haugen <hunter@puppetlabs.com>
Tue, 4 Feb 2014 23:26:49 +0000 (15:26 -0800)
spec/acceptance/firewall_spec.rb
spec/unit/puppet/type/firewall_spec.rb

index 864fe016bd17ef38a943432282fa8f5917365e82..c8c3ccd6bf2eadc533ff0d7cf5522bff9969b297 100644 (file)
@@ -1466,6 +1466,111 @@ describe 'firewall type' do
     end
   end
 
+  describe 'recent' do
+    context 'set' do
+      it 'applies' do
+        pp = <<-EOS
+          class { '::firewall': }
+          firewall { '597 - test':
+            ensure       => 'present',
+            chain        => 'INPUT',
+            destination  => '30.0.0.0/8',
+            proto        => 'all',
+            table        => 'filter',
+            recent       => 'set',
+            rdest        => true,
+            rname        => 'list1',
+          }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+      end
+
+      it 'should contain the rule' do
+        shell('iptables -S') do |r|
+          expect(r.stdout).to match(/-A INPUT -d 30.0.0.0\/8 -m comment --comment "597 - test" -m recent --set --name list1 --rdest/)
+        end
+      end
+    end
+
+    context 'rcheck' do
+      it 'applies' do
+        pp = <<-EOS
+          class { '::firewall': }
+          firewall { '598 - test':
+            ensure       => 'present',
+            chain        => 'INPUT',
+            destination  => '30.0.0.0/8',
+            proto        => 'all',
+            table        => 'filter',
+            recent       => 'rcheck',
+            rsource      => true,
+            rname        => 'list1',
+            rseconds     => 60,
+            rhitcount    => 5,
+            rttl         => true,
+          }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+      end
+
+      it 'should contain the rule' do
+        shell('iptables -S') do |r|
+          expect(r.stdout).to match(/-A INPUT -d 30.0.0.0\/8 -m comment --comment "598 - test" -m recent --rcheck --seconds 60 --hitcount 5 --rttl --name list1 --rsource/)
+        end
+      end
+    end
+
+    context 'update' do
+      it 'applies' do
+        pp = <<-EOS
+          class { '::firewall': }
+          firewall { '599 - test':
+            ensure       => 'present',
+            chain        => 'INPUT',
+            destination  => '30.0.0.0/8',
+            proto        => 'all',
+            table        => 'filter',
+            recent       => 'update',
+          }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+      end
+
+      it 'should contain the rule' do
+        shell('iptables -S') do |r|
+          expect(r.stdout).to match(/-A INPUT -d 30.0.0.0\/8 -m comment --comment "599 - test" -m recent --update/)
+        end
+      end
+    end
+
+    context 'remove' do
+      it 'applies' do
+        pp = <<-EOS
+          class { '::firewall': }
+          firewall { '600 - test':
+            ensure       => 'present',
+            chain        => 'INPUT',
+            destination  => '30.0.0.0/8',
+            proto        => 'all',
+            table        => 'filter',
+            recent       => 'remove',
+          }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+      end
+
+      it 'should contain the rule' do
+        shell('iptables -S') do |r|
+          expect(r.stdout).to match(/-A INPUT -d 30.0.0.0\/8 -m comment --comment "600 - test" -m recent --remove/)
+        end
+      end
+    end
+  end
+
   describe 'reset' do
     it 'deletes all rules' do
       shell('ip6tables --flush')
index e9b6f46bd47f9294c8631c313f08f08323eb5b4e..afb61662b60fd4dcfe63c4d6911927c001afa0bb 100755 (executable)
@@ -348,6 +348,15 @@ describe firewall do
     end
   end
 
+  describe ':recent' do
+    ['set', 'update', 'rcheck', 'remove'].each do |recent|
+      it "should accept recent value #{recent}" do
+        @resource[:recent] = recent
+        @resource[:recent].should == "--#{recent}"
+      end
+    end
+  end
+
   describe ':action and :jump' do
     it 'should allow only 1 to be set at a time' do
       expect {