|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper_acceptance' |
| 4 | + |
| 5 | +def make_manifest(behaviour) |
| 6 | + pp = <<-PUPPETCODE |
| 7 | + class { 'firewall': } |
| 8 | + resources { 'firewall': |
| 9 | + purge => true, |
| 10 | + } |
| 11 | +
|
| 12 | + firewall { '550 destination': |
| 13 | + proto => tcp, |
| 14 | + dport => '550', |
| 15 | + action => accept, |
| 16 | + destination => '192.168.2.0/24', |
| 17 | + onduplicaterulebehaviour => #{behaviour} |
| 18 | + } |
| 19 | + PUPPETCODE |
| 20 | + |
| 21 | + pp |
| 22 | +end |
| 23 | + |
| 24 | +describe 'firewall - duplicate comments' do |
| 25 | + before(:all) do |
| 26 | + if os[:family] == 'ubuntu' || os[:family] == 'debian' |
| 27 | + update_profile_file |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + before(:each) do |
| 32 | + run_shell('iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 551 -j ACCEPT -m comment --comment "550 destination"') |
| 33 | + end |
| 34 | + |
| 35 | + after(:each) do |
| 36 | + iptables_flush_all_tables |
| 37 | + end |
| 38 | + |
| 39 | + context 'when onduplicateerrorhevent is set to error' do |
| 40 | + it 'raises an error' do |
| 41 | + run_shell('iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 551 -j ACCEPT -m comment --comment "550 destination"') |
| 42 | + pp = make_manifest('error') |
| 43 | + |
| 44 | + apply_manifest(pp) do |r| |
| 45 | + expect(r.stderr).to include('Error: /Stage[main]/Main/Firewall[550 destination]: Could not evaluate: Duplicate rule found for 550 destination. Skipping update.') |
| 46 | + end |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + context 'when onduplicateerrorhevent is set to warn' do |
| 51 | + run_shell('iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 551 -j ACCEPT -m comment --comment "550 destination"') |
| 52 | + |
| 53 | + it 'warns and continues' do |
| 54 | + run_shell('iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 551 -j ACCEPT -m comment --comment "550 destination"') |
| 55 | + pp = make_manifest('warn') |
| 56 | + |
| 57 | + apply_manifest(pp) do |r| |
| 58 | + expect(r.stderr).to include('Warning: Firewall[550 destination](provider=iptables): Duplicate rule found for 550 destination.. This may add an additional rule to the system.') |
| 59 | + end |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + context 'when onduplicateerrorhevent is set to ignore' do |
| 64 | + run_shell('iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 551 -j ACCEPT -m comment --comment "550 destination"') |
| 65 | + |
| 66 | + it 'continues silently' do |
| 67 | + run_shell('iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 551 -j ACCEPT -m comment --comment "550 destination"') |
| 68 | + pp = make_manifest('ignore') |
| 69 | + |
| 70 | + apply_manifest(pp) do |r| |
| 71 | + expect(r.stderr).to be_empty |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | +end |
0 commit comments