Projet

Général

Profil

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

root / spec / classes / masquerade_spec.rb @ 020842af

Historique | Voir | Annoter | Télécharger (4,5 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 masquerade' do
20
        let(:pre_condition) do
21
          '
22
          nftables::rules::masquerade{
23
            \'masquerade_eth0\':
24
              oif => \'eth0\';
25
            \'masquerade_eth1_vpn\':
26
              oif   => \'eth1\',
27
              saddr => \'192.0.2.0/24\';
28
            \'masquerade_ssh\':
29
              saddr => \'192.0.2.0/24\',
30
              daddr => \'198.51.100.2\',
31
              proto => \'tcp\',
32
              dport => \'22\';
33
            \'masquerade_ssh_gitlab\':
34
              saddr => \'192.0.2.0/24\',
35
              daddr => \'198.51.100.2\',
36
              dport => \'22\';
37
            \'masquerade_wireguard\':
38
              proto => \'udp\',
39
              dport => \'51820\';
40
          }
41
          '
42
        end
43

    
44
        it { is_expected.to compile }
45

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

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

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

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

    
80
        it {
81
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth0').with(
82
            target: 'nftables-ip-nat-chain-POSTROUTING',
83
            content: %r{^  oifname eth0 masquerade$},
84
            order: '70-nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth0-b'
85
          )
86
        }
87

    
88
        it {
89
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth1_vpn').with(
90
            target: 'nftables-ip-nat-chain-POSTROUTING',
91
            content: %r{^  oifname eth1 ip saddr 192\.0\.2\.0/24 masquerade$},
92
            order: '70-nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth1_vpn-b'
93
          )
94
        }
95

    
96
        it {
97
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh').with(
98
            target: 'nftables-ip-nat-chain-POSTROUTING',
99
            content: %r{^  ip saddr 192\.0\.2\.0/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$},
100
            order: '70-nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh-b'
101
          )
102
        }
103

    
104
        it {
105
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh_gitlab').with(
106
            target: 'nftables-ip-nat-chain-POSTROUTING',
107
            content: %r{^  ip saddr 192\.0\.2\.0/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$},
108
            order: '70-nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh_gitlab-b'
109
          )
110
        }
111

    
112
        it {
113
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_wireguard').with(
114
            target: 'nftables-ip-nat-chain-POSTROUTING',
115
            content: %r{^  udp dport 51820 masquerade$},
116
            order: '70-nftables-ip-nat-chain-POSTROUTING-rule-masquerade_wireguard-b'
117
          )
118
        }
119

    
120
        it {
121
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
122
            target: 'nftables-ip-nat-chain-POSTROUTING',
123
            content: %r{^\}$},
124
            order: '99'
125
          )
126
        }
127
      end
128
    end
129
  end
130
end