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