Projet

Général

Profil

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

root / spec / classes / masquerade_spec.rb @ 248ef9d5

Historique | Voir | Annoter | Télécharger (3,93 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
      context 'with masquerade' do
11
        let(:pre_condition) do
12
          '
13
          nftables::rules::masquerade{
14
            \'masquerade_eth0\':
15
              oif => \'eth0\';
16
            \'masquerade_eth1_vpn\':
17
              oif   => \'eth1\',
18
              saddr => \'192.0.2.0/24\';
19
            \'masquerade_ssh\':
20
              saddr => \'192.0.2.0/24\',
21
              daddr => \'198.51.100.2\',
22
              proto => \'tcp\',
23
              dport => \'22\';
24
            \'masquerade_ssh_gitlab\':
25
              saddr => \'192.0.2.0/24\',
26
              daddr => \'198.51.100.2\',
27
              dport => \'22\';
28
            \'masquerade_wireguard\':
29
              proto => \'udp\',
30
              dport => \'51820\';
31
          }
32
          '
33
        end
34

    
35
        it { is_expected.to compile }
36

    
37
        it {
38
          is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
39
            path:           '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft',
40
            owner:          'root',
41
            group:          'root',
42
            mode:           '0640',
43
            ensure_newline: true,
44
          )
45
        }
46
        it {
47
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
48
            target:  'nftables-ip-nat-chain-POSTROUTING',
49
            content: %r{^chain POSTROUTING \{$},
50
            order:   '00',
51
          )
52
        }
53
        it {
54
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
55
            target:  'nftables-ip-nat-chain-POSTROUTING',
56
            content: %r{^  type nat hook postrouting priority 100$},
57
            order:   '01',
58
          )
59
        }
60
        it {
61
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
62
            target:  'nftables-ip-nat-chain-POSTROUTING',
63
            content: %r{^  policy accept$},
64
            order:   '02',
65
          )
66
        }
67
        it {
68
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth0').with(
69
            target:  'nftables-ip-nat-chain-POSTROUTING',
70
            content: %r{^  oifname eth0 masquerade$},
71
            order:   '70',
72
          )
73
        }
74
        it {
75
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth1_vpn').with(
76
            target:  'nftables-ip-nat-chain-POSTROUTING',
77
            content: %r{^  oifname eth1 ip saddr 192\.0\.2\.0\/24 masquerade$},
78
            order:   '70',
79
          )
80
        }
81
        it {
82
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh').with(
83
            target:  'nftables-ip-nat-chain-POSTROUTING',
84
            content: %r{^  ip saddr 192\.0\.2\.0\/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$},
85
            order:   '70',
86
          )
87
        }
88
        it {
89
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh_gitlab').with(
90
            target:  'nftables-ip-nat-chain-POSTROUTING',
91
            content: %r{^  ip saddr 192\.0\.2\.0\/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$},
92
            order:   '70',
93
          )
94
        }
95
        it {
96
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_wireguard').with(
97
            target:  'nftables-ip-nat-chain-POSTROUTING',
98
            content: %r{^  udp dport 51820 masquerade$},
99
            order:   '70',
100
          )
101
        }
102
        it {
103
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
104
            target:  'nftables-ip-nat-chain-POSTROUTING',
105
            content: %r{^\}$},
106
            order:   '99',
107
          )
108
        }
109
      end
110
    end
111
  end
112
end