root / spec / defines / simplerule_spec.rb @ c82b960a
Historique | Voir | Annoter | Télécharger (7,49 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 'only sport TCP traffic' do |
108 |
let(:params) do |
109 |
{ |
110 |
sport: 555, |
111 |
proto: 'tcp', |
112 |
} |
113 |
end
|
114 |
|
115 |
it { is_expected.to compile } |
116 |
|
117 |
it { |
118 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
119 |
content: 'tcp sport {555} accept' |
120 |
) |
121 |
} |
122 |
end
|
123 |
|
124 |
describe 'only IPv4 TCP traffic' do |
125 |
let(:params) do |
126 |
{ |
127 |
dport: 333, |
128 |
proto: 'tcp4', |
129 |
} |
130 |
end
|
131 |
|
132 |
it { is_expected.to compile } |
133 |
|
134 |
it { |
135 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
136 |
content: 'ip version 4 tcp dport {333} accept' |
137 |
) |
138 |
} |
139 |
end
|
140 |
|
141 |
describe 'only IPv6 UDP traffic' do |
142 |
let(:params) do |
143 |
{ |
144 |
dport: 33, |
145 |
proto: 'udp6', |
146 |
} |
147 |
end
|
148 |
|
149 |
it { is_expected.to compile } |
150 |
|
151 |
it { |
152 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
153 |
content: 'ip6 version 6 udp dport {33} accept' |
154 |
) |
155 |
} |
156 |
end
|
157 |
|
158 |
describe 'only IPv6 TCP traffic' do |
159 |
let(:params) do |
160 |
{ |
161 |
dport: 35, |
162 |
proto: 'tcp6', |
163 |
} |
164 |
end
|
165 |
|
166 |
it { is_expected.to compile } |
167 |
|
168 |
it { |
169 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
170 |
content: 'ip6 version 6 tcp dport {35} accept' |
171 |
) |
172 |
} |
173 |
end
|
174 |
|
175 |
describe 'with an IPv4 CIDR as daddr' do |
176 |
let(:params) do |
177 |
{ |
178 |
daddr: '192.168.0.1/24', |
179 |
dport: 33, |
180 |
proto: 'tcp', |
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: 'tcp dport {33} ip daddr 192.168.0.1/24 accept' |
189 |
) |
190 |
} |
191 |
end
|
192 |
|
193 |
describe 'with an IPv6 address as daddr' do |
194 |
let(:params) do |
195 |
{ |
196 |
daddr: '2001:1458::1', |
197 |
} |
198 |
end
|
199 |
|
200 |
it { is_expected.to compile } |
201 |
|
202 |
it { |
203 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
204 |
content: 'ip6 daddr 2001:1458::1 accept' |
205 |
) |
206 |
} |
207 |
end
|
208 |
|
209 |
describe 'with an IPv6 address as saddr' do |
210 |
let(:params) do |
211 |
{ |
212 |
saddr: '2001:1458:0000:0000:0000:0000:0000:0003', |
213 |
} |
214 |
end
|
215 |
|
216 |
it { is_expected.to compile } |
217 |
|
218 |
it { |
219 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
220 |
content: 'ip6 saddr 2001:1458:0000:0000:0000:0000:0000:0003 accept' |
221 |
) |
222 |
} |
223 |
end
|
224 |
|
225 |
describe 'with an IPv4 address as saddr' do |
226 |
let(:params) do |
227 |
{ |
228 |
saddr: '172.16.1.5', |
229 |
} |
230 |
end
|
231 |
|
232 |
it { is_expected.to compile } |
233 |
|
234 |
it { |
235 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
236 |
content: 'ip saddr 172.16.1.5 accept' |
237 |
) |
238 |
} |
239 |
end
|
240 |
|
241 |
describe 'with an IPv6 set as daddr, default set_type' do |
242 |
let(:params) do |
243 |
{ |
244 |
daddr: '@my6_set', |
245 |
} |
246 |
end
|
247 |
|
248 |
it { is_expected.to compile } |
249 |
|
250 |
it { |
251 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
252 |
content: 'ip6 daddr @my6_set accept' |
253 |
) |
254 |
} |
255 |
end
|
256 |
|
257 |
describe 'with a IPv4 set as daddr' do |
258 |
let(:params) do |
259 |
{ |
260 |
daddr: '@my4_set', |
261 |
set_type: 'ip', |
262 |
} |
263 |
end
|
264 |
|
265 |
it { is_expected.to compile } |
266 |
|
267 |
it { |
268 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
269 |
content: 'ip daddr @my4_set accept' |
270 |
) |
271 |
} |
272 |
end
|
273 |
|
274 |
describe 'with a IPv6 set as saddr' do |
275 |
let(:params) do |
276 |
{ |
277 |
saddr: '@my6_set', |
278 |
set_type: 'ip6', |
279 |
} |
280 |
end
|
281 |
|
282 |
it { is_expected.to compile } |
283 |
|
284 |
it { |
285 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
286 |
content: 'ip6 saddr @my6_set accept' |
287 |
) |
288 |
} |
289 |
end
|
290 |
|
291 |
describe 'with counter enabled' do |
292 |
let(:params) do |
293 |
{ |
294 |
counter: true, |
295 |
} |
296 |
end
|
297 |
|
298 |
it { is_expected.to compile } |
299 |
|
300 |
it { |
301 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
302 |
content: 'counter accept' |
303 |
) |
304 |
} |
305 |
end
|
306 |
|
307 |
describe 'counter and continue sport' do |
308 |
let(:params) do |
309 |
{ |
310 |
proto: 'tcp', |
311 |
sport: 80, |
312 |
counter: true, |
313 |
action: 'continue', |
314 |
} |
315 |
end
|
316 |
|
317 |
it { is_expected.to compile } |
318 |
|
319 |
it { |
320 |
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
|
321 |
content: 'tcp sport {80} counter continue' |
322 |
) |
323 |
} |
324 |
end
|
325 |
end
|
326 |
end
|
327 |
end
|