Projet

Général

Profil

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

root / spec / classes / snat4_spec.rb @ 3016d428

Historique | Voir | Annoter | Télécharger (4,05 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 'with snat4' do
20
        let(:pre_condition) do
21
          '
22
          nftables::rules::snat4{
23
            \'static\':
24
              order => \'60\',
25
              snat  => \'198.51.100.1\',
26
              oif   => \'eth0\';
27
            \'1_1\':
28
              order => \'61\',
29
              saddr => \'192.0.2.2\',
30
              snat  => \'198.51.100.3\',
31
              oif   => \'eth0\';
32
            \'1_1_smtp\':
33
              saddr => \'192.0.2.2\',
34
              snat  => \'198.51.100.2\',
35
              dport => \'25\';
36
            \'1_1_wireguard\':
37
              saddr => \'192.0.2.2\',
38
              snat  => \'198.51.100.2\',
39
              proto => \'udp\',
40
              dport => \'51820\';
41
          }
42
          '
43
        end
44

    
45
        it { is_expected.to compile }
46

    
47
        it {
48
          expect(subject).to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
49
            path: '/etc/nftables/puppet-preflight/ip-nat-chain-POSTROUTING.nft',
50
            owner: 'root',
51
            group: 'root',
52
            mode: nft_mode,
53
            ensure_newline: true
54
          )
55
        }
56

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

    
65
        it {
66
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
67
            target: 'nftables-ip-nat-chain-POSTROUTING',
68
            content: %r{^  type nat hook postrouting priority 100$},
69
            order: '01-nftables-ip-nat-chain-POSTROUTING-rule-type-b'
70
          )
71
        }
72

    
73
        it {
74
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
75
            target: 'nftables-ip-nat-chain-POSTROUTING',
76
            content: %r{^  policy accept$},
77
            order: '02-nftables-ip-nat-chain-POSTROUTING-rule-policy-b'
78
          )
79
        }
80

    
81
        it {
82
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-static').with(
83
            target: 'nftables-ip-nat-chain-POSTROUTING',
84
            content: %r{^  oifname eth0 snat 198\.51\.100\.1$},
85
            order: '60-nftables-ip-nat-chain-POSTROUTING-rule-static-b'
86
          )
87
        }
88

    
89
        it {
90
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-1_1').with(
91
            target: 'nftables-ip-nat-chain-POSTROUTING',
92
            content: %r{^  oifname eth0 ip saddr 192\.0\.2\.2 snat 198\.51\.100\.3$},
93
            order: '61-nftables-ip-nat-chain-POSTROUTING-rule-1_1-b'
94
          )
95
        }
96

    
97
        it {
98
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-1_1_smtp').with(
99
            target: 'nftables-ip-nat-chain-POSTROUTING',
100
            content: %r{^  ip saddr 192\.0\.2\.2 tcp dport 25 snat 198\.51\.100\.2$},
101
            order: '70-nftables-ip-nat-chain-POSTROUTING-rule-1_1_smtp-b'
102
          )
103
        }
104

    
105
        it {
106
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-1_1_wireguard').with(
107
            target: 'nftables-ip-nat-chain-POSTROUTING',
108
            content: %r{^  ip saddr 192\.0\.2\.2 udp dport 51820 snat 198\.51\.100\.2$},
109
            order: '70-nftables-ip-nat-chain-POSTROUTING-rule-1_1_wireguard-b'
110
          )
111
        }
112

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