Skip to content

Commit 30db99b

Browse files
committed
(SEC-944) Add test cases
Prior to this commit there we no test cases to validate our changes to the module. This commit adds test cases for each of the configurations for onduplicaterulebehaviour.
1 parent df7e270 commit 30db99b

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

spec/spec_helper_acceptance_local.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,12 @@ def fetch_os_name
111111
}
112112
PUPPETCODE
113113
LitmusHelper.instance.apply_manifest(pp)
114+
115+
# Ensure that policycoreutils is present. In the future we could probably refactor
116+
# this so that policycoreutils is installed on platform where the os.family fact
117+
# is set to 'redhat'
118+
if ['almalinux-8', 'rocky-8'].include?("#{fetch_os_name}-#{os[:release].to_i}")
119+
LitmusHelper.instance.run_shell('yum install policycoreutils -y')
120+
end
114121
end
115122
end

0 commit comments

Comments
 (0)