root / spec / defines / simplerule_spec.rb @ 5944b9cb
Historique | Voir | Annoter | Télécharger (5,8 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 |
} |
55 |
end
|
56 |
|
57 |
it { is_expected.to compile } |
58 |
it { |
59 |
is_expected.to contain_nftables__rule('default_out-my_big_rule').with(
|
60 |
content: 'udp sport {444} udp dport {333} ip6 daddr 2001:1458::/32 counter accept comment "this is my rule"', |
61 |
order: '50', |
62 |
) |
63 |
} |
64 |
end
|
65 |
|
66 |
describe 'port range' do |
67 |
let(:params) do |
68 |
{ |
69 |
dport: '333-334', |
70 |
sport: '1-2', |
71 |
proto: 'tcp', |
72 |
} |
73 |
end
|
74 |
|
75 |
it { is_expected.to compile } |
76 |
it { |
77 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
78 |
content: 'tcp sport {1-2} tcp dport {333-334} accept', |
79 |
) |
80 |
} |
81 |
end
|
82 |
|
83 |
describe 'port array' do |
84 |
let(:params) do |
85 |
{ |
86 |
dport: [333, 335], |
87 |
sport: [433, 435], |
88 |
proto: 'tcp', |
89 |
} |
90 |
end
|
91 |
|
92 |
it { is_expected.to compile } |
93 |
it { |
94 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
95 |
content: 'tcp sport {433, 435} tcp dport {333, 335} accept', |
96 |
) |
97 |
} |
98 |
end
|
99 |
|
100 |
describe 'only sport TCP traffic' do |
101 |
let(:params) do |
102 |
{ |
103 |
sport: 555, |
104 |
proto: 'tcp', |
105 |
} |
106 |
end
|
107 |
|
108 |
it { is_expected.to compile } |
109 |
it { |
110 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
111 |
content: 'tcp sport {555} accept', |
112 |
) |
113 |
} |
114 |
end
|
115 |
|
116 |
describe 'only IPv4 TCP traffic' do |
117 |
let(:params) do |
118 |
{ |
119 |
dport: 333, |
120 |
proto: 'tcp4', |
121 |
} |
122 |
end
|
123 |
|
124 |
it { is_expected.to compile } |
125 |
it { |
126 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
127 |
content: 'ip version 4 tcp dport {333} accept', |
128 |
) |
129 |
} |
130 |
end
|
131 |
|
132 |
describe 'only IPv6 UDP traffic' do |
133 |
let(:params) do |
134 |
{ |
135 |
dport: 33, |
136 |
proto: 'udp6', |
137 |
} |
138 |
end
|
139 |
|
140 |
it { is_expected.to compile } |
141 |
it { |
142 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
143 |
content: 'ip version 6 udp dport {33} accept', |
144 |
) |
145 |
} |
146 |
end
|
147 |
|
148 |
describe 'with an IPv4 CIDR as daddr' do |
149 |
let(:params) do |
150 |
{ |
151 |
daddr: '192.168.0.1/24', |
152 |
dport: 33, |
153 |
proto: 'tcp', |
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: 'tcp dport {33} ip daddr 192.168.0.1/24 accept', |
161 |
) |
162 |
} |
163 |
end
|
164 |
|
165 |
describe 'with an IPv6 address as daddr' do |
166 |
let(:params) do |
167 |
{ |
168 |
daddr: '2001:1458::1', |
169 |
} |
170 |
end
|
171 |
|
172 |
it { is_expected.to compile } |
173 |
it { |
174 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
175 |
content: 'ip6 daddr 2001:1458::1 accept', |
176 |
) |
177 |
} |
178 |
end
|
179 |
|
180 |
describe 'with an IPv6 set as daddr, default set_type' do |
181 |
let(:params) do |
182 |
{ |
183 |
daddr: '@my6_set', |
184 |
} |
185 |
end
|
186 |
|
187 |
it { is_expected.to compile } |
188 |
it { |
189 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
190 |
content: 'ip6 daddr @my6_set accept', |
191 |
) |
192 |
} |
193 |
end
|
194 |
|
195 |
describe 'with a IPv4 set as daddr' do |
196 |
let(:params) do |
197 |
{ |
198 |
daddr: '@my4_set', |
199 |
set_type: 'ip', |
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: 'ip daddr @my4_set accept', |
207 |
) |
208 |
} |
209 |
end
|
210 |
|
211 |
describe 'with counter enabled' do |
212 |
let(:params) do |
213 |
{ |
214 |
counter: true, |
215 |
} |
216 |
end
|
217 |
|
218 |
it { is_expected.to compile } |
219 |
it { |
220 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
221 |
content: 'counter accept', |
222 |
) |
223 |
} |
224 |
end
|
225 |
|
226 |
describe 'counter and continue sport' do |
227 |
let(:params) do |
228 |
{ |
229 |
proto: 'tcp', |
230 |
sport: 80, |
231 |
counter: true, |
232 |
action: 'continue', |
233 |
} |
234 |
end
|
235 |
|
236 |
it { is_expected.to compile } |
237 |
it { |
238 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
239 |
content: 'tcp sport {80} counter continue', |
240 |
) |
241 |
} |
242 |
end
|
243 |
end
|
244 |
end
|
245 |
end
|