root / spec / classes / ip_nat_spec.rb @ 7e5b657a
Historique | Voir | Annoter | Télécharger (8,76 ko)
1 |
require 'spec_helper'
|
---|---|
2 |
|
3 |
describe 'nftables' do |
4 |
let(:pre_condition) { 'Exec{path => "/bin"}' } |
5 |
|
6 |
on_supported_os.each do |os, os_facts|
|
7 |
context "on #{os}" do |
8 |
let(:facts) { os_facts }
|
9 |
|
10 |
it { is_expected.to compile } |
11 |
|
12 |
it { |
13 |
is_expected.to contain_concat('nftables-ip-nat').with(
|
14 |
path: '/etc/nftables/puppet-preflight/ip-nat.nft', |
15 |
ensure: 'present', |
16 |
owner: 'root', |
17 |
group: 'root', |
18 |
mode: '0640', |
19 |
) |
20 |
} |
21 |
|
22 |
it { |
23 |
is_expected.to contain_concat__fragment('nftables-ip-nat-header').with(
|
24 |
target: 'nftables-ip-nat', |
25 |
content: %r{^table ip nat \{$}, |
26 |
order: '00', |
27 |
) |
28 |
} |
29 |
|
30 |
it { |
31 |
is_expected.to contain_concat__fragment('nftables-ip-nat-body').with(
|
32 |
target: 'nftables-ip-nat', |
33 |
order: '98', |
34 |
) |
35 |
} |
36 |
|
37 |
it { |
38 |
is_expected.to contain_concat__fragment('nftables-ip-nat-footer').with(
|
39 |
target: 'nftables-ip-nat', |
40 |
content: %r{^\}$}, |
41 |
order: '99', |
42 |
) |
43 |
} |
44 |
|
45 |
it { |
46 |
is_expected.to contain_concat('nftables-ip6-nat').with(
|
47 |
path: '/etc/nftables/puppet-preflight/ip6-nat.nft', |
48 |
ensure: 'present', |
49 |
owner: 'root', |
50 |
group: 'root', |
51 |
mode: '0640', |
52 |
) |
53 |
} |
54 |
|
55 |
it { |
56 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-header').with(
|
57 |
target: 'nftables-ip6-nat', |
58 |
content: %r{^table ip6 nat \{$}, |
59 |
order: '00', |
60 |
) |
61 |
} |
62 |
|
63 |
it { |
64 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-body').with(
|
65 |
target: 'nftables-ip6-nat', |
66 |
order: '98', |
67 |
) |
68 |
} |
69 |
|
70 |
it { |
71 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-footer').with(
|
72 |
target: 'nftables-ip6-nat', |
73 |
content: %r{^\}$}, |
74 |
order: '99', |
75 |
) |
76 |
} |
77 |
|
78 |
context 'table ip nat chain prerouting' do |
79 |
it { |
80 |
is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
|
81 |
path: '/etc/nftables/puppet-preflight/ip-nat-chain-PREROUTING.nft', |
82 |
owner: 'root', |
83 |
group: 'root', |
84 |
mode: '0640', |
85 |
ensure_newline: true, |
86 |
) |
87 |
} |
88 |
it { |
89 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
|
90 |
target: 'nftables-ip-nat-chain-PREROUTING', |
91 |
content: %r{^chain PREROUTING \{$}, |
92 |
order: '00', |
93 |
) |
94 |
} |
95 |
it { |
96 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
|
97 |
target: 'nftables-ip-nat-chain-PREROUTING', |
98 |
content: %r{^ type nat hook prerouting priority -100$}, |
99 |
order: '01-nftables-ip-nat-chain-PREROUTING-rule-type-b', |
100 |
) |
101 |
} |
102 |
it { |
103 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
|
104 |
target: 'nftables-ip-nat-chain-PREROUTING', |
105 |
content: %r{^ policy accept$}, |
106 |
order: '02-nftables-ip-nat-chain-PREROUTING-rule-policy-b', |
107 |
) |
108 |
} |
109 |
it { |
110 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
|
111 |
target: 'nftables-ip-nat-chain-PREROUTING', |
112 |
content: %r{^\}$}, |
113 |
order: '99', |
114 |
) |
115 |
} |
116 |
end
|
117 |
|
118 |
context 'table ip nat chain postrouting' do |
119 |
it { |
120 |
is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
|
121 |
path: '/etc/nftables/puppet-preflight/ip-nat-chain-POSTROUTING.nft', |
122 |
owner: 'root', |
123 |
group: 'root', |
124 |
mode: '0640', |
125 |
ensure_newline: true, |
126 |
) |
127 |
} |
128 |
it { |
129 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
|
130 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
131 |
content: %r{^chain POSTROUTING \{$}, |
132 |
order: '00', |
133 |
) |
134 |
} |
135 |
it { |
136 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
|
137 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
138 |
content: %r{^ type nat hook postrouting priority 100$}, |
139 |
order: '01-nftables-ip-nat-chain-POSTROUTING-rule-type-b', |
140 |
) |
141 |
} |
142 |
it { |
143 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
|
144 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
145 |
content: %r{^ policy accept$}, |
146 |
order: '02-nftables-ip-nat-chain-POSTROUTING-rule-policy-b', |
147 |
) |
148 |
} |
149 |
it { |
150 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
|
151 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
152 |
content: %r{^\}$}, |
153 |
order: '99', |
154 |
) |
155 |
} |
156 |
end
|
157 |
|
158 |
context 'table ip6 nat chain prerouting' do |
159 |
it { |
160 |
is_expected.to contain_concat('nftables-ip6-nat-chain-PREROUTING6').with(
|
161 |
path: '/etc/nftables/puppet-preflight/ip6-nat-chain-PREROUTING6.nft', |
162 |
owner: 'root', |
163 |
group: 'root', |
164 |
mode: '0640', |
165 |
ensure_newline: true, |
166 |
) |
167 |
} |
168 |
it { |
169 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-header').with(
|
170 |
target: 'nftables-ip6-nat-chain-PREROUTING6', |
171 |
content: %r{^chain PREROUTING6 \{$}, |
172 |
order: '00', |
173 |
) |
174 |
} |
175 |
it { |
176 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-rule-type').with(
|
177 |
target: 'nftables-ip6-nat-chain-PREROUTING6', |
178 |
content: %r{^ type nat hook prerouting priority -100$}, |
179 |
order: '01-nftables-ip6-nat-chain-PREROUTING6-rule-type-b', |
180 |
) |
181 |
} |
182 |
it { |
183 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-rule-policy').with(
|
184 |
target: 'nftables-ip6-nat-chain-PREROUTING6', |
185 |
content: %r{^ policy accept$}, |
186 |
order: '02-nftables-ip6-nat-chain-PREROUTING6-rule-policy-b', |
187 |
) |
188 |
} |
189 |
it { |
190 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-footer').with(
|
191 |
target: 'nftables-ip6-nat-chain-PREROUTING6', |
192 |
content: %r{^\}$}, |
193 |
order: '99', |
194 |
) |
195 |
} |
196 |
end
|
197 |
|
198 |
context 'table ip nat chain postrouting' do |
199 |
it { |
200 |
is_expected.to contain_concat('nftables-ip6-nat-chain-POSTROUTING6').with(
|
201 |
path: '/etc/nftables/puppet-preflight/ip6-nat-chain-POSTROUTING6.nft', |
202 |
owner: 'root', |
203 |
group: 'root', |
204 |
mode: '0640', |
205 |
ensure_newline: true, |
206 |
) |
207 |
} |
208 |
it { |
209 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-header').with(
|
210 |
target: 'nftables-ip6-nat-chain-POSTROUTING6', |
211 |
content: %r{^chain POSTROUTING6 \{$}, |
212 |
order: '00', |
213 |
) |
214 |
} |
215 |
it { |
216 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-rule-type').with(
|
217 |
target: 'nftables-ip6-nat-chain-POSTROUTING6', |
218 |
content: %r{^ type nat hook postrouting priority 100$}, |
219 |
order: '01-nftables-ip6-nat-chain-POSTROUTING6-rule-type-b', |
220 |
) |
221 |
} |
222 |
it { |
223 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-rule-policy').with(
|
224 |
target: 'nftables-ip6-nat-chain-POSTROUTING6', |
225 |
content: %r{^ policy accept$}, |
226 |
order: '02-nftables-ip6-nat-chain-POSTROUTING6-rule-policy-b', |
227 |
) |
228 |
} |
229 |
it { |
230 |
is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-footer').with(
|
231 |
target: 'nftables-ip6-nat-chain-POSTROUTING6', |
232 |
content: %r{^\}$}, |
233 |
order: '99', |
234 |
) |
235 |
} |
236 |
end
|
237 |
|
238 |
context 'all nat tables disabled' do |
239 |
let(:params) do |
240 |
{ |
241 |
'nat' => false, |
242 |
} |
243 |
end
|
244 |
|
245 |
it { is_expected.not_to contain_class('nftables::ip_nat') }
|
246 |
it { is_expected.not_to contain_nftables__config('ip-nat') }
|
247 |
it { is_expected.not_to contain_nftables__config('ip6-nat') }
|
248 |
it { is_expected.not_to contain_nftables__chain('PREROUTING') }
|
249 |
it { is_expected.not_to contain_nftables__chain('POSTROUTING') }
|
250 |
it { is_expected.not_to contain_nftables__chain('PREROUTING6') }
|
251 |
it { is_expected.not_to contain_nftables__chain('POSTROUTING6') }
|
252 |
end
|
253 |
end
|
254 |
end
|
255 |
end
|