Projet

Général

Profil

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

root / spec / classes / router_spec.rb @ 0b7bcb5d

Historique | Voir | Annoter | Télécharger (5,76 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
      nft_mode = case os_facts[:os]['family']
13
                 when 'RedHat'
14
                   '0600'
15
                 else
16
                   '0640'
17
                 end
18

    
19
      context 'as router' do
20
        let(:pre_condition) do
21
          '
22
          # inet-filter-chain-default_fwd
23
          nftables::rule{
24
            \'default_fwd-out\':
25
              order   => \'20\',
26
              content => \'iifname eth1 oifname eth0 accept\';
27
            \'default_fwd-drop\':
28
              order   => \'90\',
29
              content => \'iifname eth0 drop\';
30
          }
31

32
          nftables::rules::masquerade{
33
            \'masquerade\':
34
              order => \'20\',
35
              oif   => \'eth0\';
36
          }
37
          '
38
        end
39

    
40
        it { is_expected.to compile }
41

    
42
        it {
43
          expect(subject).to contain_concat('nftables-inet-filter-chain-default_fwd').with(
44
            path: '/etc/nftables/puppet-preflight/inet-filter-chain-default_fwd.nft',
45
            owner: 'root',
46
            group: 'root',
47
            mode: nft_mode,
48
            ensure_newline: true
49
          )
50
        }
51

    
52
        it {
53
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
54
            target: 'nftables-inet-filter-chain-default_fwd',
55
            content: %r{^chain default_fwd \{$},
56
            order: '00'
57
          )
58
        }
59

    
60
        it {
61
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-out').with(
62
            target: 'nftables-inet-filter-chain-default_fwd',
63
            content: %r{^  iifname eth1 oifname eth0 accept$},
64
            order: '20-nftables-inet-filter-chain-default_fwd-rule-out-b'
65
          )
66
        }
67

    
68
        it {
69
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-drop').with(
70
            target: 'nftables-inet-filter-chain-default_fwd',
71
            content: %r{^  iifname eth0 drop$},
72
            order: '90-nftables-inet-filter-chain-default_fwd-rule-drop-b'
73
          )
74
        }
75

    
76
        it {
77
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
78
            target: 'nftables-inet-filter-chain-default_fwd',
79
            content: %r{^\}$},
80
            order: '99'
81
          )
82
        }
83

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

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

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

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

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

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

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

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

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

    
160
        it {
161
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade').with(
162
            target: 'nftables-ip-nat-chain-POSTROUTING',
163
            content: %r{^  oifname eth0 masquerade$},
164
            order: '20-nftables-ip-nat-chain-POSTROUTING-rule-masquerade-b'
165
          )
166
        }
167

    
168
        it {
169
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
170
            target: 'nftables-ip-nat-chain-POSTROUTING',
171
            content: %r{^\}$},
172
            order: '99'
173
          )
174
        }
175
      end
176
    end
177
  end
178
end