Projet

Général

Profil

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

root / spec / defines / chain_spec.rb @ c82b960a

Historique | Voir | Annoter | Télécharger (3,99 ko)

1
# frozen_string_literal: true
2

    
3
require 'spec_helper'
4

    
5
describe 'nftables::chain' do
6
  let(:title) { 'MYCHAIN' }
7
  let(:pre_condition) { 'include nftables' }
8

    
9
  on_supported_os.each do |os, facts|
10
    context "on #{os}" do
11
      let(:facts) do
12
        facts
13
      end
14

    
15
      it { is_expected.to compile }
16

    
17
      it { is_expected.to contain_concat('nftables-inet-filter-chain-MYCHAIN').that_notifies('Exec[nft validate]') }
18
      it { is_expected.to contain_exec('nft validate').that_comes_before('File[/etc/nftables/puppet/inet-filter-chain-MYCHAIN.nft]') }
19
      it { is_expected.to contain_file('/etc/nftables/puppet/inet-filter-chain-MYCHAIN.nft').that_comes_before('Service[nftables]') }
20

    
21
      it {
22
        expect(subject).to contain_concat('nftables-inet-filter-chain-MYCHAIN').with(
23
          path: '/etc/nftables/puppet-preflight/inet-filter-chain-MYCHAIN.nft',
24
          owner: 'root',
25
          group: 'root',
26
          mode: '0640',
27
          ensure_newline: true
28
        )
29
      }
30

    
31
      it {
32
        expect(subject).to contain_file('/etc/nftables/puppet/inet-filter-chain-MYCHAIN.nft').with(
33
          ensure: 'file',
34
          source: '/etc/nftables/puppet-preflight/inet-filter-chain-MYCHAIN.nft',
35
          mode: '0640',
36
          owner: 'root',
37
          group: 'root'
38
        )
39
      }
40

    
41
      it {
42
        expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-MYCHAIN-header').with(
43
          order: '00',
44
          content: "# Start of fragment order:00 MYCHAIN header\nchain MYCHAIN {",
45
          target: 'nftables-inet-filter-chain-MYCHAIN'
46
        )
47
      }
48

    
49
      it {
50
        expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-MYCHAIN-footer').with(
51
          order: '99',
52
          content: "# Start of fragment order:99 MYCHAIN footer\n}",
53
          target: 'nftables-inet-filter-chain-MYCHAIN'
54
        )
55
      }
56

    
57
      context('with table set to ip6-foo') do
58
        let(:params) do
59
          {
60
            table: 'ip6-foo',
61
          }
62
        end
63

    
64
        it {
65
          expect(subject).to contain_concat('nftables-ip6-foo-chain-MYCHAIN').with(
66
            path: '/etc/nftables/puppet-preflight/ip6-foo-chain-MYCHAIN.nft',
67
            owner: 'root',
68
            group: 'root',
69
            mode: '0640',
70
            ensure_newline: true
71
          )
72
        }
73

    
74
        it {
75
          expect(subject).to contain_file('/etc/nftables/puppet/ip6-foo-chain-MYCHAIN.nft').with(
76
            ensure: 'file',
77
            source: '/etc/nftables/puppet-preflight/ip6-foo-chain-MYCHAIN.nft',
78
            mode: '0640',
79
            owner: 'root',
80
            group: 'root'
81
          )
82
        }
83

    
84
        it {
85
          expect(subject).to contain_concat__fragment('nftables-ip6-foo-chain-MYCHAIN-header').with(
86
            order: '00',
87
            content: "# Start of fragment order:00 MYCHAIN header\nchain MYCHAIN {",
88
            target: 'nftables-ip6-foo-chain-MYCHAIN'
89
          )
90
        }
91

    
92
        it {
93
          expect(subject).to contain_concat__fragment('nftables-ip6-foo-chain-MYCHAIN-footer').with(
94
            order: '99',
95
            content: "# Start of fragment order:99 MYCHAIN footer\n}",
96
            target: 'nftables-ip6-foo-chain-MYCHAIN'
97
          )
98
        }
99
      end
100

    
101
      context 'with inject set to 22-foobar' do
102
        let(:params) do
103
          {
104
            inject: '22-foobar',
105
          }
106
        end
107

    
108
        it { is_expected.to contain_nftables__rule('foobar-jump_MYCHAIN') }
109

    
110
        it {
111
          expect(subject).to contain_nftables__rule('foobar-jump_MYCHAIN').with(
112
            order: '22',
113
            content: 'jump MYCHAIN'
114
          )
115
        }
116

    
117
        context 'with inject_oif set to alpha and inject_oif set to beta' do
118
          let(:params) do
119
            super().merge(inject_iif: 'alpha', inject_oif: 'beta')
120
          end
121

    
122
          it {
123
            expect(subject).to contain_nftables__rule('foobar-jump_MYCHAIN').with(
124
              order: '22',
125
              content: 'iifname alpha oifname beta jump MYCHAIN'
126
            )
127
          }
128
        end
129
      end
130
    end
131
  end
132
end