Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / spec / classes / ip_nat_spec.rb @ 435a5db2

Historique | Voir | Annoter | Télécharger (9,29 ko)

1
# frozen_string_literal: true
2

    
3
require 'spec_helper'
4

    
5
describe 'nftables' do
6
  let(:pre_condition) { 'Exec{path => "/bin"}' }
7

    
8
  on_supported_os.each do |os, os_facts|
9
    context "on #{os}" do
10
      let(:facts) { os_facts }
11

    
12
      it { is_expected.to compile }
13

    
14
      it {
15
        expect(subject).to contain_concat('nftables-ip-nat').with(
16
          path: '/etc/nftables/puppet-preflight/ip-nat.nft',
17
          ensure: 'present',
18
          owner: 'root',
19
          group: 'root',
20
          mode: '0640'
21
        )
22
      }
23

    
24
      it {
25
        expect(subject).to contain_concat__fragment('nftables-ip-nat-header').with(
26
          target: 'nftables-ip-nat',
27
          content: %r{^table ip nat \{$},
28
          order: '00'
29
        )
30
      }
31

    
32
      it {
33
        expect(subject).to contain_concat__fragment('nftables-ip-nat-body').with(
34
          target: 'nftables-ip-nat',
35
          content: %r{^\s+include "ip-nat-chain-\*\.nft"$},
36
          order: '98'
37
        )
38
      }
39

    
40
      it {
41
        expect(subject).to contain_concat__fragment('nftables-ip-nat-footer').with(
42
          target: 'nftables-ip-nat',
43
          content: %r{^\}$},
44
          order: '99'
45
        )
46
      }
47

    
48
      it {
49
        expect(subject).to contain_concat('nftables-ip6-nat').with(
50
          path: '/etc/nftables/puppet-preflight/ip6-nat.nft',
51
          ensure: 'present',
52
          owner: 'root',
53
          group: 'root',
54
          mode: '0640'
55
        )
56
      }
57

    
58
      it {
59
        expect(subject).to contain_concat__fragment('nftables-ip6-nat-header').with(
60
          target: 'nftables-ip6-nat',
61
          content: %r{^table ip6 nat \{$},
62
          order: '00'
63
        )
64
      }
65

    
66
      it {
67
        expect(subject).to contain_concat__fragment('nftables-ip6-nat-body').with(
68
          target: 'nftables-ip6-nat',
69
          content: %r{^\s+include "ip6-nat-chain-\*\.nft"$},
70
          order: '98'
71
        )
72
      }
73

    
74
      it {
75
        expect(subject).to contain_concat__fragment('nftables-ip6-nat-footer').with(
76
          target: 'nftables-ip6-nat',
77
          content: %r{^\}$},
78
          order: '99'
79
        )
80
      }
81

    
82
      context 'table ip nat chain prerouting' do
83
        it {
84
          expect(subject).to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
85
            path: '/etc/nftables/puppet-preflight/ip-nat-chain-PREROUTING.nft',
86
            owner: 'root',
87
            group: 'root',
88
            mode: '0640',
89
            ensure_newline: true
90
          )
91
        }
92

    
93
        it {
94
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
95
            target: 'nftables-ip-nat-chain-PREROUTING',
96
            content: %r{^chain PREROUTING \{$},
97
            order: '00'
98
          )
99
        }
100

    
101
        it {
102
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
103
            target: 'nftables-ip-nat-chain-PREROUTING',
104
            content: %r{^  type nat hook prerouting priority -100$},
105
            order: '01-nftables-ip-nat-chain-PREROUTING-rule-type-b'
106
          )
107
        }
108

    
109
        it {
110
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
111
            target: 'nftables-ip-nat-chain-PREROUTING',
112
            content: %r{^  policy accept$},
113
            order: '02-nftables-ip-nat-chain-PREROUTING-rule-policy-b'
114
          )
115
        }
116

    
117
        it {
118
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
119
            target: 'nftables-ip-nat-chain-PREROUTING',
120
            content: %r{^\}$},
121
            order: '99'
122
          )
123
        }
124
      end
125

    
126
      context 'table ipv4 nat chain postrouting' do
127
        it {
128
          expect(subject).to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
129
            path: '/etc/nftables/puppet-preflight/ip-nat-chain-POSTROUTING.nft',
130
            owner: 'root',
131
            group: 'root',
132
            mode: '0640',
133
            ensure_newline: true
134
          )
135
        }
136

    
137
        it {
138
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
139
            target: 'nftables-ip-nat-chain-POSTROUTING',
140
            content: %r{^chain POSTROUTING \{$},
141
            order: '00'
142
          )
143
        }
144

    
145
        it {
146
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
147
            target: 'nftables-ip-nat-chain-POSTROUTING',
148
            content: %r{^  type nat hook postrouting priority 100$},
149
            order: '01-nftables-ip-nat-chain-POSTROUTING-rule-type-b'
150
          )
151
        }
152

    
153
        it {
154
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
155
            target: 'nftables-ip-nat-chain-POSTROUTING',
156
            content: %r{^  policy accept$},
157
            order: '02-nftables-ip-nat-chain-POSTROUTING-rule-policy-b'
158
          )
159
        }
160

    
161
        it {
162
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
163
            target: 'nftables-ip-nat-chain-POSTROUTING',
164
            content: %r{^\}$},
165
            order: '99'
166
          )
167
        }
168
      end
169

    
170
      context 'table ip6 nat chain prerouting' do
171
        it {
172
          expect(subject).to contain_concat('nftables-ip6-nat-chain-PREROUTING6').with(
173
            path: '/etc/nftables/puppet-preflight/ip6-nat-chain-PREROUTING6.nft',
174
            owner: 'root',
175
            group: 'root',
176
            mode: '0640',
177
            ensure_newline: true
178
          )
179
        }
180

    
181
        it {
182
          expect(subject).to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-header').with(
183
            target: 'nftables-ip6-nat-chain-PREROUTING6',
184
            content: %r{^chain PREROUTING6 \{$},
185
            order: '00'
186
          )
187
        }
188

    
189
        it {
190
          expect(subject).to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-rule-type').with(
191
            target: 'nftables-ip6-nat-chain-PREROUTING6',
192
            content: %r{^  type nat hook prerouting priority -100$},
193
            order: '01-nftables-ip6-nat-chain-PREROUTING6-rule-type-b'
194
          )
195
        }
196

    
197
        it {
198
          expect(subject).to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-rule-policy').with(
199
            target: 'nftables-ip6-nat-chain-PREROUTING6',
200
            content: %r{^  policy accept$},
201
            order: '02-nftables-ip6-nat-chain-PREROUTING6-rule-policy-b'
202
          )
203
        }
204

    
205
        it {
206
          expect(subject).to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-footer').with(
207
            target: 'nftables-ip6-nat-chain-PREROUTING6',
208
            content: %r{^\}$},
209
            order: '99'
210
          )
211
        }
212
      end
213

    
214
      context 'table ipv6 nat chain postrouting' do
215
        it {
216
          expect(subject).to contain_concat('nftables-ip6-nat-chain-POSTROUTING6').with(
217
            path: '/etc/nftables/puppet-preflight/ip6-nat-chain-POSTROUTING6.nft',
218
            owner: 'root',
219
            group: 'root',
220
            mode: '0640',
221
            ensure_newline: true
222
          )
223
        }
224

    
225
        it {
226
          expect(subject).to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-header').with(
227
            target: 'nftables-ip6-nat-chain-POSTROUTING6',
228
            content: %r{^chain POSTROUTING6 \{$},
229
            order: '00'
230
          )
231
        }
232

    
233
        it {
234
          expect(subject).to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-rule-type').with(
235
            target: 'nftables-ip6-nat-chain-POSTROUTING6',
236
            content: %r{^  type nat hook postrouting priority 100$},
237
            order: '01-nftables-ip6-nat-chain-POSTROUTING6-rule-type-b'
238
          )
239
        }
240

    
241
        it {
242
          expect(subject).to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-rule-policy').with(
243
            target: 'nftables-ip6-nat-chain-POSTROUTING6',
244
            content: %r{^  policy accept$},
245
            order: '02-nftables-ip6-nat-chain-POSTROUTING6-rule-policy-b'
246
          )
247
        }
248

    
249
        it {
250
          expect(subject).to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-footer').with(
251
            target: 'nftables-ip6-nat-chain-POSTROUTING6',
252
            content: %r{^\}$},
253
            order: '99'
254
          )
255
        }
256
      end
257

    
258
      context 'custom ip nat table name' do
259
        let(:params) do
260
          {
261
            'nat_table_name' => 'mycustomtablename',
262
          }
263
        end
264

    
265
        it { is_expected.to compile }
266

    
267
        it {
268
          expect(subject).to contain_concat('nftables-ip-mycustomtablename').with(
269
            path: '/etc/nftables/puppet-preflight/ip-mycustomtablename.nft',
270
            ensure: 'present',
271
            owner: 'root',
272
            group: 'root',
273
            mode: '0640'
274
          )
275
        }
276
      end
277

    
278
      context 'all nat tables disabled' do
279
        let(:params) do
280
          {
281
            'nat' => false,
282
          }
283
        end
284

    
285
        it { is_expected.not_to contain_class('nftables::ip_nat') }
286
        it { is_expected.not_to contain_nftables__config('ip-nat') }
287
        it { is_expected.not_to contain_nftables__config('ip6-nat') }
288
        it { is_expected.not_to contain_nftables__chain('PREROUTING') }
289
        it { is_expected.not_to contain_nftables__chain('POSTROUTING') }
290
        it { is_expected.not_to contain_nftables__chain('PREROUTING6') }
291
        it { is_expected.not_to contain_nftables__chain('POSTROUTING6') }
292
      end
293
    end
294
  end
295
end