Skip to content

Commit 72c4ada

Browse files
committed
(CAT-962) Reinitialize and update acceptance tests - P1
Update acceptance testing to account for changes. Includes: - standard_usage_spec.rb - rules_spec.rb - resource_cmd_spec.rb - firewallchain_spec.rb - firewall_duplicate_comment_spec.rb
1 parent 1091d34 commit 72c4ada

File tree

5 files changed

+765
-0
lines changed

5 files changed

+765
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
describe 'firewall - duplicate comments' do
6+
before(:all) do
7+
update_profile_file if os[:family] == 'ubuntu' || os[:family] == 'debian'
8+
end
9+
10+
after(:each) do
11+
iptables_flush_all_tables
12+
end
13+
14+
context 'when a duplicate comment is found' do
15+
pp = <<-PUPPETCODE
16+
class { 'firewall': }
17+
resources { 'firewall':
18+
purge => true,
19+
}
20+
21+
firewall { '550 destination':
22+
proto => tcp,
23+
dport => '550',
24+
jump => accept,
25+
destination => '192.168.2.0/24',
26+
}
27+
PUPPETCODE
28+
29+
it 'raises an error' do
30+
run_shell('iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 551 -j ACCEPT -m comment --comment "550 destination"')
31+
run_shell('iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 552 -j ACCEPT -m comment --comment "550 destination"')
32+
33+
apply_manifest(pp) do |r|
34+
expect(r.stderr).to include('Duplicate names have been found within your Firewalls. This prevents the module from working correctly and must be manually resolved.')
35+
end
36+
end
37+
end
38+
end
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
describe 'puppet resource firewallchain command' do
6+
before :all do
7+
iptables_flush_all_tables
8+
ip6tables_flush_all_tables
9+
end
10+
11+
describe 'IPv4' do
12+
context 'when present' do
13+
pp1 = <<-PUPPETCODE
14+
firewallchain { 'MY_CHAIN:filter:IPv4':
15+
ensure => present,
16+
}
17+
PUPPETCODE
18+
it 'applies cleanly' do
19+
# Run it twice and test for idempotency
20+
idempotent_apply(pp1)
21+
end
22+
23+
it 'finds the chain' do
24+
run_shell('iptables-save') do |r|
25+
expect(r.stdout).to match(%r{MY_CHAIN})
26+
end
27+
end
28+
end
29+
30+
context 'when absent' do
31+
pp2 = <<-PUPPETCODE
32+
firewallchain { 'MY_CHAIN:filter:IPv4':
33+
ensure => absent,
34+
}
35+
PUPPETCODE
36+
it 'applies cleanly' do
37+
# Run it twice and test for idempotency
38+
idempotent_apply(pp2)
39+
end
40+
41+
it 'fails to find the chain' do
42+
run_shell('iptables-save') do |r|
43+
expect(r.stdout).not_to match(%r{MY_CHAIN})
44+
end
45+
end
46+
end
47+
end
48+
49+
describe 'IPv6' do
50+
context 'when present' do
51+
pp3 = <<-PUPPETCODE
52+
firewallchain { 'MY_CHAIN:filter:IPv6':
53+
ensure => present,
54+
}
55+
PUPPETCODE
56+
it 'applies cleanly' do
57+
# Run it twice and test for idempotency
58+
idempotent_apply(pp3)
59+
end
60+
61+
it 'finds the chain' do
62+
run_shell('ip6tables-save') do |r|
63+
expect(r.stdout).to match(%r{MY_CHAIN})
64+
end
65+
end
66+
end
67+
68+
context 'when absent' do
69+
pp4 = <<-PUPPETCODE
70+
firewallchain { 'MY_CHAIN:filter:IPv6':
71+
ensure => absent,
72+
}
73+
PUPPETCODE
74+
it 'applies cleanly' do
75+
# Run it twice and test for idempotency
76+
idempotent_apply(pp4)
77+
end
78+
79+
it 'fails to find the chain' do
80+
run_shell('ip6tables-save') do |r|
81+
expect(r.stdout).not_to match(%r{MY_CHAIN})
82+
end
83+
end
84+
end
85+
end
86+
87+
# XXX purge => false is not yet implemented
88+
# context 'when adding a firewall rule to a chain:' do
89+
# pp5 = <<-PUPPETCODE
90+
# firewallchain { 'MY_CHAIN:filter:IPv4':
91+
# ensure => present,
92+
# }
93+
# firewall { '100 my rule':
94+
# chain => 'MY_CHAIN',
95+
# action => 'accept',
96+
# proto => 'tcp',
97+
# dport => 5000,
98+
# }
99+
# PUPPETCODE
100+
# it 'applies cleanly' do
101+
# # Run it twice and test for idempotency
102+
# apply_manifest(pp5, :catch_failures => true)
103+
# apply_manifest(pp5, :catch_changes => do_catch_changes)
104+
# end
105+
# end
106+
107+
# context 'when not purge firewallchain chains:' do
108+
# pp6 = <<-PUPPETCODE
109+
# firewallchain { 'MY_CHAIN:filter:IPv4':
110+
# ensure => present,
111+
# purge => false,
112+
# before => Resources['firewall'],
113+
# }
114+
# resources { 'firewall':
115+
# purge => true,
116+
# }
117+
# PUPPETCODE
118+
# it 'does not purge the rule' do
119+
# # Run it twice and test for idempotency
120+
# apply_manifest(pp6, :catch_failures => true) do |r|
121+
# expect(r.stdout).to_not match(/removed/)
122+
# expect(r.stderr).to eq('')
123+
# end
124+
# apply_manifest(pp6, :catch_changes => do_catch_changes)
125+
# end
126+
127+
# pp7 = <<-PUPPETCODE
128+
# firewall { '100 my rule':
129+
# chain => 'MY_CHAIN',
130+
# action => 'accept',
131+
# proto => 'tcp',
132+
# dport => 5000,
133+
# }
134+
# PUPPETCODE
135+
# it 'still has the rule' do
136+
# # Run it twice and test for idempotency
137+
# apply_manifest(pp7, :catch_changes => do_catch_changes)
138+
# end
139+
# end
140+
141+
describe 'policy' do
142+
after :all do
143+
run_shell('iptables -t filter -P FORWARD ACCEPT')
144+
end
145+
146+
context 'when DROP' do
147+
pp8 = <<-PUPPETCODE
148+
firewallchain { 'FORWARD:filter:IPv4':
149+
policy => 'drop',
150+
}
151+
PUPPETCODE
152+
it 'applies cleanly' do
153+
# Run it twice and test for idempotency
154+
idempotent_apply(pp8)
155+
end
156+
157+
it 'finds the chain' do
158+
run_shell('iptables-save') do |r|
159+
expect(r.stdout).to match(%r{FORWARD DROP})
160+
end
161+
end
162+
end
163+
end
164+
end

0 commit comments

Comments
 (0)