root / spec / defines / simplerule_spec.rb @ 3a469f2b
Historique | Voir | Annoter | Télécharger (6,66 ko)
1 | 83382bb5 | Nacho Barrientos | 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 | 3a52fb41 | Nacho Barrientos | order: '50', |
18 | 83382bb5 | Nacho Barrientos | ) |
19 | } |
||
20 | end
|
||
21 | |||
22 | 77abc10b | Nacho Barrientos | describe 'dport without protocol' do |
23 | d38aab5b | Nacho Barrientos | let(:params) do |
24 | { |
||
25 | dport: 333, |
||
26 | } |
||
27 | end
|
||
28 | |||
29 | it { is_expected.not_to compile } |
||
30 | end
|
||
31 | |||
32 | 77abc10b | Nacho Barrientos | 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 | 83382bb5 | Nacho Barrientos | 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 | d43ced4d | Nacho Barrientos | counter: true, |
49 | 83382bb5 | Nacho Barrientos | dport: 333, |
50 | 77abc10b | Nacho Barrientos | sport: 444, |
51 | 83382bb5 | Nacho Barrientos | proto: 'udp', |
52 | chain: 'default_out', |
||
53 | aaa37172 | Nacho Barrientos | daddr: '2001:1458::/32', |
54 | 3a469f2b | Nacho Barrientos | saddr: '2001:145c::/32', |
55 | 83382bb5 | Nacho Barrientos | } |
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 | 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"', |
62 | 3a52fb41 | Nacho Barrientos | order: '50', |
63 | ) |
||
64 | } |
||
65 | end
|
||
66 | |||
67 | describe 'port range' do |
||
68 | let(:params) do |
||
69 | { |
||
70 | dport: '333-334', |
||
71 | 77abc10b | Nacho Barrientos | sport: '1-2', |
72 | 3a52fb41 | Nacho Barrientos | 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 | 77abc10b | Nacho Barrientos | content: 'tcp sport {1-2} tcp dport {333-334} accept', |
80 | 3a52fb41 | Nacho Barrientos | ) |
81 | } |
||
82 | end
|
||
83 | |||
84 | describe 'port array' do |
||
85 | let(:params) do |
||
86 | { |
||
87 | dport: [333, 335], |
||
88 | 77abc10b | Nacho Barrientos | 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 | 3a52fb41 | Nacho Barrientos | 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 | 77abc10b | Nacho Barrientos | content: 'tcp sport {555} accept', |
113 | 83382bb5 | Nacho Barrientos | ) |
114 | } |
||
115 | end
|
||
116 | 316bc3f8 | Nacho Barrientos | |
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 | 6793d286 | Nacho Barrientos | content: 'ip version 4 tcp dport {333} accept', |
129 | 316bc3f8 | Nacho Barrientos | ) |
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 | 6793d286 | Nacho Barrientos | content: 'ip version 6 udp dport {33} accept', |
145 | 316bc3f8 | Nacho Barrientos | ) |
146 | } |
||
147 | end
|
||
148 | aaa37172 | Nacho Barrientos | |
149 | describe 'with an IPv4 CIDR as daddr' do |
||
150 | let(:params) do |
||
151 | { |
||
152 | daddr: '192.168.0.1/24', |
||
153 | dport: 33, |
||
154 | proto: 'tcp', |
||
155 | } |
||
156 | end
|
||
157 | |||
158 | it { is_expected.to compile } |
||
159 | it { |
||
160 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
161 | 6793d286 | Nacho Barrientos | content: 'tcp dport {33} ip daddr 192.168.0.1/24 accept', |
162 | aaa37172 | Nacho Barrientos | ) |
163 | } |
||
164 | end
|
||
165 | |||
166 | describe 'with an IPv6 address as daddr' do |
||
167 | let(:params) do |
||
168 | { |
||
169 | daddr: '2001:1458::1', |
||
170 | } |
||
171 | end
|
||
172 | |||
173 | it { is_expected.to compile } |
||
174 | it { |
||
175 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
176 | content: 'ip6 daddr 2001:1458::1 accept', |
||
177 | ) |
||
178 | } |
||
179 | end
|
||
180 | |||
181 | 3a469f2b | Nacho Barrientos | describe 'with an IPv6 address as saddr' do |
182 | let(:params) do |
||
183 | { |
||
184 | saddr: '2001:1458:0000:0000:0000:0000:0000:0003', |
||
185 | } |
||
186 | end
|
||
187 | |||
188 | it { is_expected.to compile } |
||
189 | it { |
||
190 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
191 | content: 'ip6 saddr 2001:1458:0000:0000:0000:0000:0000:0003 accept', |
||
192 | ) |
||
193 | } |
||
194 | end
|
||
195 | |||
196 | aaa37172 | Nacho Barrientos | describe 'with an IPv6 set as daddr, default set_type' do |
197 | let(:params) do |
||
198 | { |
||
199 | daddr: '@my6_set', |
||
200 | } |
||
201 | end
|
||
202 | |||
203 | it { is_expected.to compile } |
||
204 | it { |
||
205 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
206 | content: 'ip6 daddr @my6_set accept', |
||
207 | ) |
||
208 | } |
||
209 | end
|
||
210 | |||
211 | describe 'with a IPv4 set as daddr' do |
||
212 | let(:params) do |
||
213 | { |
||
214 | daddr: '@my4_set', |
||
215 | set_type: 'ip', |
||
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 daddr @my4_set accept', |
||
223 | ) |
||
224 | } |
||
225 | end
|
||
226 | |||
227 | 3a469f2b | Nacho Barrientos | describe 'with a IPv6 set as saddr' do |
228 | let(:params) do |
||
229 | { |
||
230 | saddr: '@my6_set', |
||
231 | set_type: 'ip6', |
||
232 | } |
||
233 | end
|
||
234 | |||
235 | it { is_expected.to compile } |
||
236 | it { |
||
237 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
238 | content: 'ip6 saddr @my6_set accept', |
||
239 | ) |
||
240 | } |
||
241 | end
|
||
242 | |||
243 | d43ced4d | Nacho Barrientos | describe 'with counter enabled' do |
244 | let(:params) do |
||
245 | { |
||
246 | counter: true, |
||
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: 'counter accept', |
||
254 | ) |
||
255 | } |
||
256 | end
|
||
257 | 5944b9cb | Nacho Barrientos | |
258 | describe 'counter and continue sport' do |
||
259 | let(:params) do |
||
260 | { |
||
261 | proto: 'tcp', |
||
262 | sport: 80, |
||
263 | counter: true, |
||
264 | action: 'continue', |
||
265 | } |
||
266 | end
|
||
267 | |||
268 | it { is_expected.to compile } |
||
269 | it { |
||
270 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
271 | content: 'tcp sport {80} counter continue', |
||
272 | ) |
||
273 | } |
||
274 | end
|
||
275 | 83382bb5 | Nacho Barrientos | end
|
276 | end
|
||
277 | end |