Projet

Général

Profil

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

root / spec / classes / nftables_spec.rb @ 30462da1

Historique | Voir | Annoter | Télécharger (4,05 ko)

1 64134e4e 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
      it { is_expected.to compile }
11 5acb554a tr
12
      it { is_expected.to contain_package('nftables') }
13
14 01d8a819 tr
      it {
15
        is_expected.to contain_file('/etc/nftables/puppet.nft').with(
16
          ensure: 'file',
17
          owner:  'root',
18
          group:  'root',
19
          mode:   '0640',
20
          source: 'puppet:///modules/nftables/config/puppet.nft',
21
        )
22
      }
23
24
      it {
25
        is_expected.to contain_file('/etc/nftables/puppet').with(
26
          ensure:  'directory',
27
          owner:   'root',
28
          group:   'root',
29
          mode:    '0750',
30
          purge:   true,
31
          force:   true,
32
          recurse: true,
33
        )
34
      }
35
36
      it {
37 30462da1 Steve Traylen
        is_expected.to contain_file('/etc/nftables/puppet-preflight.nft').with(
38
          ensure: 'file',
39
          owner:  'root',
40
          group:  'root',
41
          mode:   '0640',
42
          source: 'puppet:///modules/nftables/config/puppet.nft',
43
        )
44
      }
45
46
      it {
47
        is_expected.to contain_file('/etc/nftables/puppet-preflight').with(
48
          ensure:  'directory',
49
          owner:   'root',
50
          group:   'root',
51
          mode:    '0750',
52
          purge:   true,
53
          force:   true,
54
          recurse: true,
55
        )
56
      }
57
58
      it {
59
        is_expected.to contain_exec('nft validate').with(
60
          refreshonly: true,
61
          command: %r{^/usr/sbin/nft -I /etc/nftables/puppet-preflight -c -f /etc/nftables/puppet-preflight.nft.*},
62
        )
63
      }
64
65
      it {
66 01d8a819 tr
        is_expected.to contain_service('nftables').with(
67
          ensure: 'running',
68
          enable: true,
69 30462da1 Steve Traylen
          hasrestart: true,
70
          restart: %r{/usr/bin/systemctl reload nft.*},
71 01d8a819 tr
        )
72
      }
73
74
      it {
75
        is_expected.to contain_service('firewalld').with(
76
          ensure: 'stopped',
77
          enable: 'mask',
78
        )
79
      }
80 e17693e3 Steve Traylen
      it { is_expected.to contain_class('nftables::rules::out::http') }
81
      it { is_expected.to contain_class('nftables::rules::out::https') }
82
      it { is_expected.to contain_class('nftables::rules::out::dns') }
83
      it { is_expected.to contain_class('nftables::rules::out::chrony') }
84
      it { is_expected.not_to contain_class('nftables::rules::out::all') }
85
      it { is_expected.not_to contain_nftables__rule('default_out-all') }
86
87
      context 'with out_all set true' do
88 b171ac7f mh
        let(:params) do
89
          {
90
            out_all: true,
91
          }
92 e17693e3 Steve Traylen
        end
93
94
        it { is_expected.to contain_class('nftables::rules::out::all') }
95
        it { is_expected.not_to contain_class('nftables::rules::out::http') }
96
        it { is_expected.not_to contain_class('nftables::rules::out::https') }
97
        it { is_expected.not_to contain_class('nftables::rules::out::dns') }
98
        it { is_expected.not_to contain_class('nftables::rules::out::chrony') }
99
        it { is_expected.to contain_nftables__rule('default_out-all').with_content('accept') }
100
        it { is_expected.to contain_nftables__rule('default_out-all').with_order('90') }
101
      end
102 b3a7a6dd tr
103
      context 'with custom rules' do
104
        let(:params) do
105
          {
106
            rules: {
107
              'INPUT-web_accept' => {
108
                order: '50',
109
                content: 'iifname eth0 tcp dport { 80, 443 } accept',
110
              },
111
            },
112
          }
113
        end
114
115
        it {
116
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-web_accept').with(
117
            target:  'nftables-inet-filter-chain-INPUT',
118
            content: %r{^  iifname eth0 tcp dport \{ 80, 443 \} accept$},
119 61f03b47 Steve Traylen
            order:   '50-nftables-inet-filter-chain-INPUT-rule-web_accept-b',
120 b3a7a6dd tr
          )
121
        }
122
      end
123 ae9872e2 Nacho Barrientos
124
      context 'without masking firewalld' do
125
        let(:params) do
126
          {
127
            'firewalld_enable' => false,
128
          }
129
        end
130
131
        it {
132
          is_expected.to contain_service('firewalld').with(
133
            ensure: 'stopped',
134
            enable: false,
135
          )
136
        }
137
      end
138 64134e4e tr
    end
139
  end
140
end