Projet

Général

Profil

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

root / spec / classes / masquerade_spec.rb @ a1f09048

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

    
37
        it { is_expected.to compile }
38

    
39
        it {
40
          expect(subject).to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
41
            path: '/etc/nftables/puppet-preflight/ip-nat-chain-POSTROUTING.nft',
42
            owner: 'root',
43
            group: 'root',
44
            mode: '0640',
45
            ensure_newline: true
46
          )
47
        }
48

    
49
        it {
50
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
51
            target: 'nftables-ip-nat-chain-POSTROUTING',
52
            content: %r{^chain POSTROUTING \{$},
53
            order: '00'
54
          )
55
        }
56

    
57
        it {
58
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
59
            target: 'nftables-ip-nat-chain-POSTROUTING',
60
            content: %r{^  type nat hook postrouting priority 100$},
61
            order: '01-nftables-ip-nat-chain-POSTROUTING-rule-type-b'
62
          )
63
        }
64

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

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

    
81
        it {
82
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth1_vpn').with(
83
            target: 'nftables-ip-nat-chain-POSTROUTING',
84
            content: %r{^  oifname eth1 ip saddr 192\.0\.2\.0/24 masquerade$},
85
            order: '70-nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth1_vpn-b'
86
          )
87
        }
88

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

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

    
105
        it {
106
          expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_wireguard').with(
107
            target: 'nftables-ip-nat-chain-POSTROUTING',
108
            content: %r{^  udp dport 51820 masquerade$},
109
            order: '70-nftables-ip-nat-chain-POSTROUTING-rule-masquerade_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