Projet

Général

Profil

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

root / spec / classes / router_spec.rb @ 8842a597

Historique | Voir | Annoter | Télécharger (5,59 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 'as router' do
13
        let(:pre_condition) do
14
          '
15
          # inet-filter-chain-default_fwd
16
          nftables::rule{
17
            \'default_fwd-out\':
18
              order   => \'20\',
19
              content => \'iifname eth1 oifname eth0 accept\';
20
            \'default_fwd-drop\':
21
              order   => \'90\',
22
              content => \'iifname eth0 drop\';
23
          }
24

25
          nftables::rules::masquerade{
26
            \'masquerade\':
27
              order => \'20\',
28
              oif   => \'eth0\';
29
          }
30
          '
31
        end
32

    
33
        it { is_expected.to compile }
34

    
35
        it {
36
          expect(subject).to contain_concat('nftables-inet-filter-chain-default_fwd').with(
37
            path: '/etc/nftables/puppet-preflight/inet-filter-chain-default_fwd.nft',
38
            owner: 'root',
39
            group: 'root',
40
            mode: '0640',
41
            ensure_newline: true
42
          )
43
        }
44

    
45
        it {
46
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
47
            target: 'nftables-inet-filter-chain-default_fwd',
48
            content: %r{^chain default_fwd \{$},
49
            order: '00'
50
          )
51
        }
52

    
53
        it {
54
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-out').with(
55
            target: 'nftables-inet-filter-chain-default_fwd',
56
            content: %r{^  iifname eth1 oifname eth0 accept$},
57
            order: '20-nftables-inet-filter-chain-default_fwd-rule-out-b'
58
          )
59
        }
60

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

    
69
        it {
70
          expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
71
            target: 'nftables-inet-filter-chain-default_fwd',
72
            content: %r{^\}$},
73
            order: '99'
74
          )
75
        }
76

    
77
        it {
78
          expect(subject).to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
79
            path: '/etc/nftables/puppet-preflight/ip-nat-chain-PREROUTING.nft',
80
            owner: 'root',
81
            group: 'root',
82
            mode: '0640',
83
            ensure_newline: true
84
          )
85
        }
86

    
87
        it {
88
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
89
            target: 'nftables-ip-nat-chain-PREROUTING',
90
            content: %r{^chain PREROUTING \{$},
91
            order: '00'
92
          )
93
        }
94

    
95
        it {
96
          expect(subject).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

    
103
        it {
104
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
105
            target: 'nftables-ip-nat-chain-PREROUTING',
106
            content: %r{^  policy accept$},
107
            order: '02-nftables-ip-nat-chain-PREROUTING-rule-policy-b'
108
          )
109
        }
110

    
111
        it {
112
          expect(subject).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

    
119
        it {
120
          expect(subject).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

    
129
        it {
130
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
131
            target: 'nftables-ip-nat-chain-POSTROUTING',
132
            content: %r{^chain POSTROUTING \{$},
133
            order: '00'
134
          )
135
        }
136

    
137
        it {
138
          expect(subject).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

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

    
153
        it {
154
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade').with(
155
            target: 'nftables-ip-nat-chain-POSTROUTING',
156
            content: %r{^  oifname eth0 masquerade$},
157
            order: '20-nftables-ip-nat-chain-POSTROUTING-rule-masquerade-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
    end
170
  end
171
end