Projet

Général

Profil

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

root / spec / classes / dnat4_spec.rb @ cc9fc807

Historique | Voir | Annoter | Télécharger (7,36 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
      context 'with dnat' do
13
        let(:pre_condition) do
14
          '
15
          # inet-filter-chain-ingoing
16
          nftables::chain{ \'ingoing\':
17
            inject     => \'20-default_fwd\',
18
            inject_iif => \'eth0\',
19
            inject_oif => \'eth1\';
20
          }
21

22
          # inet-filter-chain-default_fwd
23
          nftables::rules::dnat4{
24
            \'http\':
25
              order => \'10\',
26
              chain => \'ingoing\',
27
              daddr => \'192.0.2.2\',
28
              port  => \'http\';
29
            \'https\':
30
              order => \'10\',
31
              chain => \'ingoing\',
32
              daddr => \'192.0.2.2\',
33
              port  => \'https\';
34
            \'http_alt\':
35
              order => \'10\',
36
              chain => \'ingoing\',
37
              iif   => \'eth0\',
38
              daddr => \'192.0.2.2\',
39
              proto => \'tcp\',
40
              port  => 8080,
41
              dport => 8000;
42
            \'wireguard\':
43
              order => \'10\',
44
              chain => \'ingoing\',
45
              iif   => \'eth0\',
46
              daddr => \'192.0.2.3\',
47
              proto => \'udp\',
48
              port  => \'51820\';
49
          }
50
          '
51
        end
52

    
53
        it { is_expected.to compile }
54

    
55
        it {
56
          expect(subject).to contain_concat('nftables-inet-filter-chain-default_fwd').with(
57
            path: '/etc/nftables/puppet-preflight/inet-filter-chain-default_fwd.nft',
58
            owner: 'root',
59
            group: 'root',
60
            mode: '0640',
61
            ensure_newline: true
62
          )
63
        }
64

    
65
        it {
66
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
67
            target: 'nftables-inet-filter-chain-default_fwd',
68
            content: %r{^chain default_fwd \{$},
69
            order: '00'
70
          )
71
        }
72

    
73
        it {
74
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-jump_ingoing').with(
75
            target: 'nftables-inet-filter-chain-default_fwd',
76
            content: %r{^  iifname eth0 oifname eth1 jump ingoing$},
77
            order: '20-nftables-inet-filter-chain-default_fwd-rule-jump_ingoing-b'
78
          )
79
        }
80

    
81
        it {
82
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
83
            target: 'nftables-inet-filter-chain-default_fwd',
84
            content: %r{^\}$},
85
            order: '99'
86
          )
87
        }
88

    
89
        it {
90
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-header').with(
91
            target: 'nftables-inet-filter-chain-ingoing',
92
            content: %r{^chain ingoing \{$},
93
            order: '00'
94
          )
95
        }
96

    
97
        it {
98
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http').with(
99
            target: 'nftables-inet-filter-chain-ingoing',
100
            content: %r{^  ip daddr 192.0.2.2 tcp dport http accept$},
101
            order: '10-nftables-inet-filter-chain-ingoing-rule-http-b'
102
          )
103
        }
104

    
105
        it {
106
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-https').with(
107
            target: 'nftables-inet-filter-chain-ingoing',
108
            content: %r{^  ip daddr 192.0.2.2 tcp dport https accept$},
109
            order: '10-nftables-inet-filter-chain-ingoing-rule-https-b'
110
          )
111
        }
112

    
113
        it {
114
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http_alt').with(
115
            target: 'nftables-inet-filter-chain-ingoing',
116
            content: %r{^  iifname eth0 ip daddr 192.0.2.2 tcp dport 8000 accept$},
117
            order: '10-nftables-inet-filter-chain-ingoing-rule-http_alt-b'
118
          )
119
        }
120

    
121
        it {
122
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-wireguard').with(
123
            target: 'nftables-inet-filter-chain-ingoing',
124
            content: %r{^  iifname eth0 ip daddr 192.0.2.3 udp dport 51820 accept$},
125
            order: '10-nftables-inet-filter-chain-ingoing-rule-wireguard-b'
126
          )
127
        }
128

    
129
        it {
130
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-footer').with(
131
            target: 'nftables-inet-filter-chain-ingoing',
132
            content: %r{^\}$},
133
            order: '99'
134
          )
135
        }
136

    
137
        it {
138
          expect(subject).to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
139
            path: '/etc/nftables/puppet-preflight/ip-nat-chain-PREROUTING.nft',
140
            owner: 'root',
141
            group: 'root',
142
            mode: '0640',
143
            ensure_newline: true
144
          )
145
        }
146

    
147
        it {
148
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
149
            target: 'nftables-ip-nat-chain-PREROUTING',
150
            content: %r{^chain PREROUTING \{$},
151
            order: '00'
152
          )
153
        }
154

    
155
        it {
156
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
157
            target: 'nftables-ip-nat-chain-PREROUTING',
158
            content: %r{^  type nat hook prerouting priority -100$},
159
            order: '01-nftables-ip-nat-chain-PREROUTING-rule-type-b'
160
          )
161
        }
162

    
163
        it {
164
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
165
            target: 'nftables-ip-nat-chain-PREROUTING',
166
            content: %r{^  policy accept$},
167
            order: '02-nftables-ip-nat-chain-PREROUTING-rule-policy-b'
168
          )
169
        }
170

    
171
        it {
172
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http').with(
173
            target: 'nftables-ip-nat-chain-PREROUTING',
174
            content: %r{^  tcp dport http dnat to 192.0.2.2$},
175
            order: '10-nftables-ip-nat-chain-PREROUTING-rule-http-b'
176
          )
177
        }
178

    
179
        it {
180
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-https').with(
181
            target: 'nftables-ip-nat-chain-PREROUTING',
182
            content: %r{^  tcp dport https dnat to 192.0.2.2$},
183
            order: '10-nftables-ip-nat-chain-PREROUTING-rule-https-b'
184
          )
185
        }
186

    
187
        it {
188
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http_alt').with(
189
            target: 'nftables-ip-nat-chain-PREROUTING',
190
            content: %r{^  iifname eth0 tcp dport 8080 dnat to 192.0.2.2:8000$},
191
            order: '10-nftables-ip-nat-chain-PREROUTING-rule-http_alt-b'
192
          )
193
        }
194

    
195
        it {
196
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-wireguard').with(
197
            target: 'nftables-ip-nat-chain-PREROUTING',
198
            content: %r{^  iifname eth0 udp dport 51820 dnat to 192.0.2.3$},
199
            order: '10-nftables-ip-nat-chain-PREROUTING-rule-wireguard-b'
200
          )
201
        }
202

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