Projet

Général

Profil

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

root / spec / classes / router_spec.rb @ af544fea

Historique | Voir | Annoter | Télécharger (6,81 ko)

1 d78c1613 tr
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 8f5d09ec tr
      context 'as router' do
11
        let(:pre_condition) do
12 d78c1613 tr
          """
13 af544fea tr
          # inet-filter-chain-ingoing
14
          nftables::chain{ 'ingoing':
15
            inject     => '20-default_fwd',
16
            inject_iif => 'eth0',
17
            inject_oif => 'eth1';
18
          }
19

20 d78c1613 tr
          # inet-filter-chain-default_fwd
21
          nftables::rule{
22
            'default_fwd-out':
23
              order   => '20',
24
              content => 'iifname eth1 oifname eth0 accept';
25
            'default_fwd-drop':
26
              order   => '90',
27
              content => 'iifname eth0 drop';
28 af544fea tr

29
            'ingoing-web':
30
              order   => '10',
31
              content => 'ip daddr 192.0.2.2 tcp dport { http, https } accept';
32
            'PREROUTING-web':
33 9ae64df9 tr
              table   => 'ip-nat',
34
              order   => '30',
35
              content => 'iifname eth0 tcp dport { http, https } dnat to 192.0.2.2';
36 d78c1613 tr
            'POSTROUTING-masquerade':
37
              table   => 'ip-nat',
38
              order   => '20',
39
              content => 'oifname eth0 masquerade';
40
          }
41
          """
42 8f5d09ec tr
        end
43 d78c1613 tr
44
        it { is_expected.to compile }
45
46
        it { is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
47
          :path           => '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft',
48
          :owner          => 'root',
49
          :group          => 'root',
50
          :mode           => '0640',
51
          :ensure_newline => true,
52
        )}
53
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
54
          :target  => 'nftables-inet-filter-chain-default_fwd',
55
          :content => /^chain default_fwd {$/,
56
          :order   => '00',
57
        )}
58
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-out').with(
59
          :target  => 'nftables-inet-filter-chain-default_fwd',
60
          :content => /^  iifname eth1 oifname eth0 accept$/,
61
          :order   => '20',
62
        )}
63 af544fea tr
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-jump_ingoing').with(
64 9ae64df9 tr
          :target  => 'nftables-inet-filter-chain-default_fwd',
65 af544fea tr
          :content => /^  iifname eth0 oifname eth1 jump ingoing$/,
66
          :order   => '20',
67 9ae64df9 tr
        )}
68 d78c1613 tr
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-drop').with(
69
          :target  => 'nftables-inet-filter-chain-default_fwd',
70
          :content => /^  iifname eth0 drop$/,
71
          :order   => '90',
72
        )}
73
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
74
          :target  => 'nftables-inet-filter-chain-default_fwd',
75
          :content => /^}$/,
76
          :order   => '99',
77
        )}
78
79 af544fea tr
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-header').with(
80
          :target  => 'nftables-inet-filter-chain-ingoing',
81
          :content => /^chain ingoing {$/,
82
          :order   => '00',
83
        )}
84
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-web').with(
85
          :target  => 'nftables-inet-filter-chain-ingoing',
86
          :content => /^  ip daddr 192.0.2.2 tcp dport \{ http, https \} accept$/,
87
          :order   => '10',
88
        )}
89
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-footer').with(
90
          :target  => 'nftables-inet-filter-chain-ingoing',
91
          :content => /^}$/,
92
          :order   => '99',
93
        )}
94
95 95b1259b tr
        it { is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
96
          :path           => '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft',
97
          :owner          => 'root',
98
          :group          => 'root',
99
          :mode           => '0640',
100
          :ensure_newline => true,
101
        )}
102
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
103
          :target  => 'nftables-ip-nat-chain-PREROUTING',
104
          :content => /^chain PREROUTING {$/,
105
          :order   => '00',
106
        )}
107
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
108
          :target  => 'nftables-ip-nat-chain-PREROUTING',
109
          :content => /^  type nat hook prerouting priority -100$/,
110
          :order   => '01',
111
        )}
112
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
113
          :target  => 'nftables-ip-nat-chain-PREROUTING',
114
          :content => /^  policy accept$/,
115
          :order   => '02',
116
        )}
117 af544fea tr
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-web').with(
118 9ae64df9 tr
          :target  => 'nftables-ip-nat-chain-PREROUTING',
119
          :content => /^  iifname eth0 tcp dport \{ http, https \} dnat to 192.0.2.2$/,
120
          :order   => '30',
121
        )}
122 95b1259b tr
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
123
          :target  => 'nftables-ip-nat-chain-PREROUTING',
124
          :content => /^}$/,
125
          :order   => '99',
126
        )}
127
128 d78c1613 tr
        it { is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
129
          :path           => '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft',
130
          :owner          => 'root',
131
          :group          => 'root',
132
          :mode           => '0640',
133
          :ensure_newline => true,
134
        )}
135
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
136
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
137
          :content => /^chain POSTROUTING {$/,
138
          :order   => '00',
139
        )}
140
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
141
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
142
          :content => /^  type nat hook postrouting priority 100$/,
143
          :order   => '01',
144
        )}
145
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
146
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
147
          :content => /^  policy accept$/,
148
          :order   => '02',
149
        )}
150
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade').with(
151
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
152
          :content => /^  oifname eth0 masquerade$/,
153
          :order   => '20',
154
        )}
155
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
156
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
157
          :content => /^}$/,
158
          :order   => '99',
159
        )}
160
      end
161
    end
162
  end
163
end