Skip to content

Commit 5aa19fd

Browse files
committed
Don't test each rule, match on whole array.
Signed-off-by: Bryan Endres <[email protected]>
1 parent e1dc70a commit 5aa19fd

File tree

1 file changed

+18
-72
lines changed

1 file changed

+18
-72
lines changed

controls/3_5_firewall_configuration.rb

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,11 @@
5151

5252
rules = ip6tables.retrieve_rules
5353

54-
describe.one do
55-
rules.each do |rule|
56-
describe rule do
57-
it { should match(/(?=.*-A INPUT)(?=.*-i lo)(?=.*-j ACCEPT)/) }
58-
end
59-
end
60-
end
61-
62-
describe.one do
63-
rules.each do |rule|
64-
describe rule do
65-
it { should match(/(?=.*-A OUTPUT)(?=.*-o lo)(?=.*-j ACCEPT)/) }
66-
end
67-
end
68-
end
69-
70-
describe.one do
71-
rules.each do |rule|
72-
describe rule do
73-
it { should match(/(?=.*-A INPUT)(?=.*-s ::1)(?=.*-j DROP)/) }
74-
end
75-
end
54+
describe "Check for IPv6 local loopback rules" do
55+
subject { rules.join("\n") }
56+
it { should match(/(?=.*-A INPUT)(?=.*-i lo)(?=.*-j ACCEPT)/) }
57+
it { should match(/(?=.*-A OUTPUT)(?=.*-o lo)(?=.*-j ACCEPT)/) }
58+
it { should match(/(?=.*-A INPUT)(?=.*-s ::1)(?=.*-j DROP)/) }
7659
end
7760

7861
only_if { ipv6.zero? }
@@ -89,20 +72,10 @@
8972
rules = ip6tables.retrieve_rules
9073

9174
%w(tcp udp icmp).each do |proto|
92-
describe.one do
93-
rules.each do |rule|
94-
describe rule do
95-
it { should match(/(?=.*-A OUTPUT)(?=.*-p #{proto})(?=.*-m state --state NEW,ESTABLISHED)(?=.*-j ACCEPT)/) }
96-
end
97-
end
98-
end
99-
100-
describe.one do
101-
rules.each do |rule|
102-
describe rule do
103-
it { should match(/(?=.*-A INPUT)(?=.*-p #{proto})(?=.*-m state --state ESTABLISHED)(?=.*-j ACCEPT)/) }
104-
end
105-
end
75+
describe "Check for IPv6 rules on established and new outbound connections" do
76+
subject { rules.join("\n") }
77+
it { should match(/(?=.*-A OUTPUT)(?=.*-p #{proto})(?=.*-m state --state NEW,ESTABLISHED)(?=.*-j ACCEPT)/) }
78+
it { should match(/(?=.*-A INPUT)(?=.*-p #{proto})(?=.*-m state --state ESTABLISHED)(?=.*-j ACCEPT)/) }
10679
end
10780
end
10881

@@ -152,28 +125,11 @@
152125

153126
rules = iptables.retrieve_rules
154127

155-
describe.one do
156-
rules.each do |rule|
157-
describe rule do
158-
it { should match /(?=.*-A INPUT)(?=.*-i lo)(?=.*-j ACCEPT)/ }
159-
end
160-
end
161-
end
162-
163-
describe.one do
164-
rules.each do |rule|
165-
describe rule do
166-
it { should match /(?=.*-A OUTPUT)(?=.*-o lo)(?=.*-j ACCEPT)/ }
167-
end
168-
end
169-
end
170-
171-
describe.one do
172-
rules.each do |rule|
173-
describe rule do
174-
it { should match %r{(?=.*-A INPUT)(?=.*-s 127\.0\.0\.0/8)(?=.*-j DROP)} }
175-
end
176-
end
128+
describe "Check for local loopback rules" do
129+
subject { rules.join("\n") }
130+
it { should match /(?=.*-A INPUT)(?=.*-i lo)(?=.*-j ACCEPT)/ }
131+
it { should match /(?=.*-A OUTPUT)(?=.*-o lo)(?=.*-j ACCEPT)/ }
132+
it { should match %r{(?=.*-A INPUT)(?=.*-s 127\.0\.0\.0/8)(?=.*-j DROP)} }
177133
end
178134
end
179135

@@ -188,20 +144,10 @@
188144
rules = iptables.retrieve_rules
189145

190146
%w(tcp udp icmp).each do |proto|
191-
describe.one do
192-
rules.each do |rule|
193-
describe rule do
194-
it { should match /(?=.*-A OUTPUT)(?=.*-p #{proto})(?=.*-m state --state NEW,ESTABLISHED)(?=.*-j ACCEPT)/ }
195-
end
196-
end
197-
end
198-
199-
describe.one do
200-
rules.each do |rule|
201-
describe rule do
202-
it { should match /(?=.*-A INPUT)(?=.*-p #{proto})(?=.*-m state --state ESTABLISHED)(?=.*-j ACCEPT)/ }
203-
end
204-
end
147+
describe "Check for rules on established and new outbound connections" do
148+
subject { rules.join("\n") }
149+
it { should match /(?=.*-A OUTPUT)(?=.*-p #{proto})(?=.*-m state --state NEW,ESTABLISHED)(?=.*-j ACCEPT)/ }
150+
it { should match /(?=.*-A INPUT)(?=.*-p #{proto})(?=.*-m state --state ESTABLISHED)(?=.*-j ACCEPT)/ }
205151
end
206152
end
207153
end

0 commit comments

Comments
 (0)