Projet

Général

Profil

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

root / spec / classes / ip_nat_spec.rb @ 7b9d6ffc

Historique | Voir | Annoter | Télécharger (8,88 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
          content: %r{^\s+include "ip-nat-chain-\*\.nft"$},
34
          order:   '98',
35
        )
36
      }
37

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

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

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

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

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

    
80
      context 'table ip nat chain prerouting' do
81
        it {
82
          is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
83
            path:           '/etc/nftables/puppet-preflight/ip-nat-chain-PREROUTING.nft',
84
            owner:          'root',
85
            group:          'root',
86
            mode:           '0640',
87
            ensure_newline: true,
88
          )
89
        }
90
        it {
91
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
92
            target:  'nftables-ip-nat-chain-PREROUTING',
93
            content: %r{^chain PREROUTING \{$},
94
            order:   '00',
95
          )
96
        }
97
        it {
98
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
99
            target:  'nftables-ip-nat-chain-PREROUTING',
100
            content: %r{^  type nat hook prerouting priority -100$},
101
            order:   '01-nftables-ip-nat-chain-PREROUTING-rule-type-b',
102
          )
103
        }
104
        it {
105
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
106
            target:  'nftables-ip-nat-chain-PREROUTING',
107
            content: %r{^  policy accept$},
108
            order:   '02-nftables-ip-nat-chain-PREROUTING-rule-policy-b',
109
          )
110
        }
111
        it {
112
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
113
            target:  'nftables-ip-nat-chain-PREROUTING',
114
            content: %r{^\}$},
115
            order:   '99',
116
          )
117
        }
118
      end
119

    
120
      context 'table ip nat chain postrouting' do
121
        it {
122
          is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
123
            path:           '/etc/nftables/puppet-preflight/ip-nat-chain-POSTROUTING.nft',
124
            owner:          'root',
125
            group:          'root',
126
            mode:           '0640',
127
            ensure_newline: true,
128
          )
129
        }
130
        it {
131
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
132
            target:  'nftables-ip-nat-chain-POSTROUTING',
133
            content: %r{^chain POSTROUTING \{$},
134
            order:   '00',
135
          )
136
        }
137
        it {
138
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
139
            target:  'nftables-ip-nat-chain-POSTROUTING',
140
            content: %r{^  type nat hook postrouting priority 100$},
141
            order:   '01-nftables-ip-nat-chain-POSTROUTING-rule-type-b',
142
          )
143
        }
144
        it {
145
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
146
            target:  'nftables-ip-nat-chain-POSTROUTING',
147
            content: %r{^  policy accept$},
148
            order:   '02-nftables-ip-nat-chain-POSTROUTING-rule-policy-b',
149
          )
150
        }
151
        it {
152
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
153
            target:  'nftables-ip-nat-chain-POSTROUTING',
154
            content: %r{^\}$},
155
            order:   '99',
156
          )
157
        }
158
      end
159

    
160
      context 'table ip6 nat chain prerouting' do
161
        it {
162
          is_expected.to contain_concat('nftables-ip6-nat-chain-PREROUTING6').with(
163
            path:           '/etc/nftables/puppet-preflight/ip6-nat-chain-PREROUTING6.nft',
164
            owner:          'root',
165
            group:          'root',
166
            mode:           '0640',
167
            ensure_newline: true,
168
          )
169
        }
170
        it {
171
          is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-header').with(
172
            target:  'nftables-ip6-nat-chain-PREROUTING6',
173
            content: %r{^chain PREROUTING6 \{$},
174
            order:   '00',
175
          )
176
        }
177
        it {
178
          is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-rule-type').with(
179
            target:  'nftables-ip6-nat-chain-PREROUTING6',
180
            content: %r{^  type nat hook prerouting priority -100$},
181
            order:   '01-nftables-ip6-nat-chain-PREROUTING6-rule-type-b',
182
          )
183
        }
184
        it {
185
          is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-rule-policy').with(
186
            target:  'nftables-ip6-nat-chain-PREROUTING6',
187
            content: %r{^  policy accept$},
188
            order:   '02-nftables-ip6-nat-chain-PREROUTING6-rule-policy-b',
189
          )
190
        }
191
        it {
192
          is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-PREROUTING6-footer').with(
193
            target:  'nftables-ip6-nat-chain-PREROUTING6',
194
            content: %r{^\}$},
195
            order:   '99',
196
          )
197
        }
198
      end
199

    
200
      context 'table ip nat chain postrouting' do
201
        it {
202
          is_expected.to contain_concat('nftables-ip6-nat-chain-POSTROUTING6').with(
203
            path:           '/etc/nftables/puppet-preflight/ip6-nat-chain-POSTROUTING6.nft',
204
            owner:          'root',
205
            group:          'root',
206
            mode:           '0640',
207
            ensure_newline: true,
208
          )
209
        }
210
        it {
211
          is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-header').with(
212
            target:  'nftables-ip6-nat-chain-POSTROUTING6',
213
            content: %r{^chain POSTROUTING6 \{$},
214
            order:   '00',
215
          )
216
        }
217
        it {
218
          is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-rule-type').with(
219
            target:  'nftables-ip6-nat-chain-POSTROUTING6',
220
            content: %r{^  type nat hook postrouting priority 100$},
221
            order:   '01-nftables-ip6-nat-chain-POSTROUTING6-rule-type-b',
222
          )
223
        }
224
        it {
225
          is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-rule-policy').with(
226
            target:  'nftables-ip6-nat-chain-POSTROUTING6',
227
            content: %r{^  policy accept$},
228
            order:   '02-nftables-ip6-nat-chain-POSTROUTING6-rule-policy-b',
229
          )
230
        }
231
        it {
232
          is_expected.to contain_concat__fragment('nftables-ip6-nat-chain-POSTROUTING6-footer').with(
233
            target:  'nftables-ip6-nat-chain-POSTROUTING6',
234
            content: %r{^\}$},
235
            order:   '99',
236
          )
237
        }
238
      end
239

    
240
      context 'all nat tables disabled' do
241
        let(:params) do
242
          {
243
            'nat' => false,
244
          }
245
        end
246

    
247
        it { is_expected.not_to contain_class('nftables::ip_nat') }
248
        it { is_expected.not_to contain_nftables__config('ip-nat') }
249
        it { is_expected.not_to contain_nftables__config('ip6-nat') }
250
        it { is_expected.not_to contain_nftables__chain('PREROUTING') }
251
        it { is_expected.not_to contain_nftables__chain('POSTROUTING') }
252
        it { is_expected.not_to contain_nftables__chain('PREROUTING6') }
253
        it { is_expected.not_to contain_nftables__chain('POSTROUTING6') }
254
      end
255
    end
256
  end
257
end