root / spec / defines / simplerule_spec.rb @ 3e2b5119
Historique | Voir | Annoter | Télécharger (7,96 ko)
1 | c82b960a | Steve Traylen | # frozen_string_literal: true
|
---|---|---|---|
2 | |||
3 | 83382bb5 | Nacho Barrientos | 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 | c82b960a | Steve Traylen | |
17 | 83382bb5 | Nacho Barrientos | it { |
18 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
19 | 83382bb5 | Nacho Barrientos | content: 'accept', |
20 | fa92e118 | Romain Tartière | order: '50' |
21 | 83382bb5 | Nacho Barrientos | ) |
22 | } |
||
23 | end
|
||
24 | |||
25 | 77abc10b | Nacho Barrientos | describe 'dport without protocol' do |
26 | d38aab5b | Nacho Barrientos | let(:params) do |
27 | { |
||
28 | dport: 333, |
||
29 | } |
||
30 | end
|
||
31 | |||
32 | it { is_expected.not_to compile } |
||
33 | end
|
||
34 | |||
35 | 77abc10b | Nacho Barrientos | 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 | 83382bb5 | Nacho Barrientos | 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 | d43ced4d | Nacho Barrientos | counter: true, |
52 | 83382bb5 | Nacho Barrientos | dport: 333, |
53 | 77abc10b | Nacho Barrientos | sport: 444, |
54 | 83382bb5 | Nacho Barrientos | proto: 'udp', |
55 | chain: 'default_out', |
||
56 | aaa37172 | Nacho Barrientos | daddr: '2001:1458::/32', |
57 | 3a469f2b | Nacho Barrientos | saddr: '2001:145c::/32', |
58 | 83382bb5 | Nacho Barrientos | } |
59 | end
|
||
60 | |||
61 | it { is_expected.to compile } |
||
62 | c82b960a | Steve Traylen | |
63 | 83382bb5 | Nacho Barrientos | it { |
64 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_out-my_big_rule').with(
|
65 | 3a469f2b | Nacho Barrientos | 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 | fa92e118 | Romain Tartière | order: '50' |
67 | 3a52fb41 | Nacho Barrientos | ) |
68 | } |
||
69 | end
|
||
70 | |||
71 | describe 'port range' do |
||
72 | let(:params) do |
||
73 | { |
||
74 | dport: '333-334', |
||
75 | 77abc10b | Nacho Barrientos | sport: '1-2', |
76 | 3a52fb41 | Nacho Barrientos | proto: 'tcp', |
77 | } |
||
78 | end
|
||
79 | |||
80 | it { is_expected.to compile } |
||
81 | c82b960a | Steve Traylen | |
82 | 3a52fb41 | Nacho Barrientos | it { |
83 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
84 | fa92e118 | Romain Tartière | content: 'tcp sport {1-2} tcp dport {333-334} accept' |
85 | 3a52fb41 | Nacho Barrientos | ) |
86 | } |
||
87 | end
|
||
88 | |||
89 | describe 'port array' do |
||
90 | let(:params) do |
||
91 | { |
||
92 | dport: [333, 335], |
||
93 | 77abc10b | Nacho Barrientos | sport: [433, 435], |
94 | proto: 'tcp', |
||
95 | } |
||
96 | end
|
||
97 | |||
98 | it { is_expected.to compile } |
||
99 | c82b960a | Steve Traylen | |
100 | 77abc10b | Nacho Barrientos | it { |
101 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
102 | fa92e118 | Romain Tartière | content: 'tcp sport {433, 435} tcp dport {333, 335} accept' |
103 | 77abc10b | Nacho Barrientos | ) |
104 | } |
||
105 | end
|
||
106 | |||
107 | 825f4eb1 | Tim Skirvin | 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 | 77abc10b | Nacho Barrientos | describe 'only sport TCP traffic' do |
126 | let(:params) do |
||
127 | { |
||
128 | sport: 555, |
||
129 | 3a52fb41 | Nacho Barrientos | proto: 'tcp', |
130 | } |
||
131 | end
|
||
132 | |||
133 | it { is_expected.to compile } |
||
134 | c82b960a | Steve Traylen | |
135 | 3a52fb41 | Nacho Barrientos | it { |
136 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
137 | fa92e118 | Romain Tartière | content: 'tcp sport {555} accept' |
138 | 83382bb5 | Nacho Barrientos | ) |
139 | } |
||
140 | end
|
||
141 | 316bc3f8 | Nacho Barrientos | |
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 | c82b960a | Steve Traylen | |
152 | 316bc3f8 | Nacho Barrientos | it { |
153 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
154 | fa92e118 | Romain Tartière | content: 'ip version 4 tcp dport {333} accept' |
155 | 316bc3f8 | Nacho Barrientos | ) |
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 | c82b960a | Steve Traylen | |
169 | 316bc3f8 | Nacho Barrientos | it { |
170 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
171 | fa92e118 | Romain Tartière | content: 'ip6 version 6 udp dport {33} accept' |
172 | 316bc3f8 | Nacho Barrientos | ) |
173 | } |
||
174 | end
|
||
175 | aaa37172 | Nacho Barrientos | |
176 | 14156fb6 | Nacho Barrientos | 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 | c82b960a | Steve Traylen | |
186 | 14156fb6 | Nacho Barrientos | it { |
187 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
188 | fa92e118 | Romain Tartière | content: 'ip6 version 6 tcp dport {35} accept' |
189 | 14156fb6 | Nacho Barrientos | ) |
190 | } |
||
191 | end
|
||
192 | |||
193 | aaa37172 | Nacho Barrientos | 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 | c82b960a | Steve Traylen | |
204 | aaa37172 | Nacho Barrientos | it { |
205 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
206 | fa92e118 | Romain Tartière | content: 'tcp dport {33} ip daddr 192.168.0.1/24 accept' |
207 | aaa37172 | Nacho Barrientos | ) |
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 | c82b960a | Steve Traylen | |
220 | aaa37172 | Nacho Barrientos | it { |
221 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
222 | fa92e118 | Romain Tartière | content: 'ip6 daddr 2001:1458::1 accept' |
223 | aaa37172 | Nacho Barrientos | ) |
224 | } |
||
225 | end
|
||
226 | |||
227 | 3a469f2b | Nacho Barrientos | 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 | c82b960a | Steve Traylen | |
236 | 3a469f2b | Nacho Barrientos | it { |
237 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
238 | fa92e118 | Romain Tartière | content: 'ip6 saddr 2001:1458:0000:0000:0000:0000:0000:0003 accept' |
239 | 3a469f2b | Nacho Barrientos | ) |
240 | } |
||
241 | end
|
||
242 | |||
243 | bd8baa0f | Nacho Barrientos | 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 | c82b960a | Steve Traylen | |
252 | bd8baa0f | Nacho Barrientos | it { |
253 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
254 | fa92e118 | Romain Tartière | content: 'ip saddr 172.16.1.5 accept' |
255 | bd8baa0f | Nacho Barrientos | ) |
256 | } |
||
257 | end
|
||
258 | |||
259 | aaa37172 | Nacho Barrientos | 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 | c82b960a | Steve Traylen | |
268 | aaa37172 | Nacho Barrientos | it { |
269 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
270 | fa92e118 | Romain Tartière | content: 'ip6 daddr @my6_set accept' |
271 | aaa37172 | Nacho Barrientos | ) |
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 | c82b960a | Steve Traylen | |
285 | aaa37172 | Nacho Barrientos | it { |
286 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
287 | fa92e118 | Romain Tartière | content: 'ip daddr @my4_set accept' |
288 | aaa37172 | Nacho Barrientos | ) |
289 | } |
||
290 | end
|
||
291 | |||
292 | 3a469f2b | Nacho Barrientos | 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 | c82b960a | Steve Traylen | |
302 | 3a469f2b | Nacho Barrientos | it { |
303 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
304 | fa92e118 | Romain Tartière | content: 'ip6 saddr @my6_set accept' |
305 | 3a469f2b | Nacho Barrientos | ) |
306 | } |
||
307 | end
|
||
308 | |||
309 | d43ced4d | Nacho Barrientos | describe 'with counter enabled' do |
310 | let(:params) do |
||
311 | { |
||
312 | counter: true, |
||
313 | } |
||
314 | end
|
||
315 | |||
316 | it { is_expected.to compile } |
||
317 | c82b960a | Steve Traylen | |
318 | d43ced4d | Nacho Barrientos | it { |
319 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
320 | fa92e118 | Romain Tartière | content: 'counter accept' |
321 | d43ced4d | Nacho Barrientos | ) |
322 | } |
||
323 | end
|
||
324 | 5944b9cb | Nacho Barrientos | |
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 | c82b960a | Steve Traylen | |
337 | 5944b9cb | Nacho Barrientos | it { |
338 | c82b960a | Steve Traylen | expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
339 | fa92e118 | Romain Tartière | content: 'tcp sport {80} counter continue' |
340 | 5944b9cb | Nacho Barrientos | ) |
341 | } |
||
342 | end
|
||
343 | 83382bb5 | Nacho Barrientos | end
|
344 | end
|
||
345 | end |