root / spec / defines / simplerule_spec.rb @ 3e2b5119
Historique | Voir | Annoter | Télécharger (7,96 ko)
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
require 'spec_helper'
|
4 |
|
5 |
describe 'nftables::simplerule' do |
6 |
let(:pre_condition) { 'include nftables' } |
7 |
|
8 |
let(:title) { 'my_default_rule_name' } |
9 |
|
10 |
on_supported_os.each do |os, os_facts|
|
11 |
context "on #{os}" do |
12 |
let(:facts) { os_facts }
|
13 |
|
14 |
describe 'minimum instantiation' do |
15 |
it { is_expected.to compile } |
16 |
|
17 |
it { |
18 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
19 |
content: 'accept', |
20 |
order: '50' |
21 |
) |
22 |
} |
23 |
end
|
24 |
|
25 |
describe 'dport without protocol' do |
26 |
let(:params) do |
27 |
{ |
28 |
dport: 333, |
29 |
} |
30 |
end
|
31 |
|
32 |
it { is_expected.not_to compile } |
33 |
end
|
34 |
|
35 |
describe 'sport without protocol' do |
36 |
let(:params) do |
37 |
{ |
38 |
sport: 333, |
39 |
} |
40 |
end
|
41 |
|
42 |
it { is_expected.not_to compile } |
43 |
end
|
44 |
|
45 |
describe 'all parameters provided' do |
46 |
let(:title) { 'my_big_rule' } |
47 |
let(:params) do |
48 |
{ |
49 |
action: 'accept', |
50 |
comment: 'this is my rule', |
51 |
counter: true, |
52 |
dport: 333, |
53 |
sport: 444, |
54 |
proto: 'udp', |
55 |
chain: 'default_out', |
56 |
daddr: '2001:1458::/32', |
57 |
saddr: '2001:145c::/32', |
58 |
} |
59 |
end
|
60 |
|
61 |
it { is_expected.to compile } |
62 |
|
63 |
it { |
64 |
expect(subject).to contain_nftables__rule('default_out-my_big_rule').with(
|
65 |
content: 'udp sport {444} udp dport {333} ip6 saddr 2001:145c::/32 ip6 daddr 2001:1458::/32 counter accept comment "this is my rule"', |
66 |
order: '50' |
67 |
) |
68 |
} |
69 |
end
|
70 |
|
71 |
describe 'port range' do |
72 |
let(:params) do |
73 |
{ |
74 |
dport: '333-334', |
75 |
sport: '1-2', |
76 |
proto: 'tcp', |
77 |
} |
78 |
end
|
79 |
|
80 |
it { is_expected.to compile } |
81 |
|
82 |
it { |
83 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
84 |
content: 'tcp sport {1-2} tcp dport {333-334} accept' |
85 |
) |
86 |
} |
87 |
end
|
88 |
|
89 |
describe 'port array' do |
90 |
let(:params) do |
91 |
{ |
92 |
dport: [333, 335], |
93 |
sport: [433, 435], |
94 |
proto: 'tcp', |
95 |
} |
96 |
end
|
97 |
|
98 |
it { is_expected.to compile } |
99 |
|
100 |
it { |
101 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
102 |
content: 'tcp sport {433, 435} tcp dport {333, 335} accept' |
103 |
) |
104 |
} |
105 |
end
|
106 |
|
107 |
describe 'port array and range' do |
108 |
let(:params) do |
109 |
{ |
110 |
dport: [333, 335, '338-339'], |
111 |
sport: [433, 435, '438-439'], |
112 |
proto: 'tcp', |
113 |
} |
114 |
end
|
115 |
|
116 |
it { is_expected.to compile } |
117 |
|
118 |
it { |
119 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
120 |
content: 'tcp sport {433, 435, 438-439} tcp dport {333, 335, 338-339} accept' |
121 |
) |
122 |
} |
123 |
end
|
124 |
|
125 |
describe 'only sport TCP traffic' do |
126 |
let(:params) do |
127 |
{ |
128 |
sport: 555, |
129 |
proto: 'tcp', |
130 |
} |
131 |
end
|
132 |
|
133 |
it { is_expected.to compile } |
134 |
|
135 |
it { |
136 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
137 |
content: 'tcp sport {555} accept' |
138 |
) |
139 |
} |
140 |
end
|
141 |
|
142 |
describe 'only IPv4 TCP traffic' do |
143 |
let(:params) do |
144 |
{ |
145 |
dport: 333, |
146 |
proto: 'tcp4', |
147 |
} |
148 |
end
|
149 |
|
150 |
it { is_expected.to compile } |
151 |
|
152 |
it { |
153 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
154 |
content: 'ip version 4 tcp dport {333} accept' |
155 |
) |
156 |
} |
157 |
end
|
158 |
|
159 |
describe 'only IPv6 UDP traffic' do |
160 |
let(:params) do |
161 |
{ |
162 |
dport: 33, |
163 |
proto: 'udp6', |
164 |
} |
165 |
end
|
166 |
|
167 |
it { is_expected.to compile } |
168 |
|
169 |
it { |
170 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
171 |
content: 'ip6 version 6 udp dport {33} accept' |
172 |
) |
173 |
} |
174 |
end
|
175 |
|
176 |
describe 'only IPv6 TCP traffic' do |
177 |
let(:params) do |
178 |
{ |
179 |
dport: 35, |
180 |
proto: 'tcp6', |
181 |
} |
182 |
end
|
183 |
|
184 |
it { is_expected.to compile } |
185 |
|
186 |
it { |
187 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
188 |
content: 'ip6 version 6 tcp dport {35} accept' |
189 |
) |
190 |
} |
191 |
end
|
192 |
|
193 |
describe 'with an IPv4 CIDR as daddr' do |
194 |
let(:params) do |
195 |
{ |
196 |
daddr: '192.168.0.1/24', |
197 |
dport: 33, |
198 |
proto: 'tcp', |
199 |
} |
200 |
end
|
201 |
|
202 |
it { is_expected.to compile } |
203 |
|
204 |
it { |
205 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
206 |
content: 'tcp dport {33} ip daddr 192.168.0.1/24 accept' |
207 |
) |
208 |
} |
209 |
end
|
210 |
|
211 |
describe 'with an IPv6 address as daddr' do |
212 |
let(:params) do |
213 |
{ |
214 |
daddr: '2001:1458::1', |
215 |
} |
216 |
end
|
217 |
|
218 |
it { is_expected.to compile } |
219 |
|
220 |
it { |
221 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
222 |
content: 'ip6 daddr 2001:1458::1 accept' |
223 |
) |
224 |
} |
225 |
end
|
226 |
|
227 |
describe 'with an IPv6 address as saddr' do |
228 |
let(:params) do |
229 |
{ |
230 |
saddr: '2001:1458:0000:0000:0000:0000:0000:0003', |
231 |
} |
232 |
end
|
233 |
|
234 |
it { is_expected.to compile } |
235 |
|
236 |
it { |
237 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
238 |
content: 'ip6 saddr 2001:1458:0000:0000:0000:0000:0000:0003 accept' |
239 |
) |
240 |
} |
241 |
end
|
242 |
|
243 |
describe 'with an IPv4 address as saddr' do |
244 |
let(:params) do |
245 |
{ |
246 |
saddr: '172.16.1.5', |
247 |
} |
248 |
end
|
249 |
|
250 |
it { is_expected.to compile } |
251 |
|
252 |
it { |
253 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
254 |
content: 'ip saddr 172.16.1.5 accept' |
255 |
) |
256 |
} |
257 |
end
|
258 |
|
259 |
describe 'with an IPv6 set as daddr, default set_type' do |
260 |
let(:params) do |
261 |
{ |
262 |
daddr: '@my6_set', |
263 |
} |
264 |
end
|
265 |
|
266 |
it { is_expected.to compile } |
267 |
|
268 |
it { |
269 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
270 |
content: 'ip6 daddr @my6_set accept' |
271 |
) |
272 |
} |
273 |
end
|
274 |
|
275 |
describe 'with a IPv4 set as daddr' do |
276 |
let(:params) do |
277 |
{ |
278 |
daddr: '@my4_set', |
279 |
set_type: 'ip', |
280 |
} |
281 |
end
|
282 |
|
283 |
it { is_expected.to compile } |
284 |
|
285 |
it { |
286 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
287 |
content: 'ip daddr @my4_set accept' |
288 |
) |
289 |
} |
290 |
end
|
291 |
|
292 |
describe 'with a IPv6 set as saddr' do |
293 |
let(:params) do |
294 |
{ |
295 |
saddr: '@my6_set', |
296 |
set_type: 'ip6', |
297 |
} |
298 |
end
|
299 |
|
300 |
it { is_expected.to compile } |
301 |
|
302 |
it { |
303 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
304 |
content: 'ip6 saddr @my6_set accept' |
305 |
) |
306 |
} |
307 |
end
|
308 |
|
309 |
describe 'with counter enabled' do |
310 |
let(:params) do |
311 |
{ |
312 |
counter: true, |
313 |
} |
314 |
end
|
315 |
|
316 |
it { is_expected.to compile } |
317 |
|
318 |
it { |
319 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
320 |
content: 'counter accept' |
321 |
) |
322 |
} |
323 |
end
|
324 |
|
325 |
describe 'counter and continue sport' do |
326 |
let(:params) do |
327 |
{ |
328 |
proto: 'tcp', |
329 |
sport: 80, |
330 |
counter: true, |
331 |
action: 'continue', |
332 |
} |
333 |
end
|
334 |
|
335 |
it { is_expected.to compile } |
336 |
|
337 |
it { |
338 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
339 |
content: 'tcp sport {80} counter continue' |
340 |
) |
341 |
} |
342 |
end
|
343 |
end
|
344 |
end
|
345 |
end
|