aboutsummaryrefslogtreecommitdiff
path: root/spec/defines/chain_spec.rb
blob: 5e84ea5f23c43cac8b5d0c43aba145a1a37eec2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# frozen_string_literal: true

require 'spec_helper'

describe 'ferm::chain', type: :define do
  on_supported_os.each do |os, facts|
    context "on #{os}" do
      let :facts do
        facts
      end
      let(:title) { 'INPUT2' }

      let :pre_condition do
        'include ferm'
      end

      context 'default params creates INPUT2 chain' do
        let :params do
          {
            disable_conntrack: false,
            log_dropped_packets: true
          }
        end

        it { is_expected.to compile.with_all_deps }
        it { is_expected.to contain_concat__fragment('filter-INPUT2-config-include') }

        it do
          expect(subject).to contain_concat__fragment('filter-INPUT2-policy'). \
            with_content(%r{ESTABLISHED RELATED})
        end

        it do
          expect(subject).to contain_concat__fragment('filter-INPUT2-footer'). \
            with_content(%r{LOG log-prefix 'INPUT2: ';})
        end

        if facts[:os]['name'] == 'Debian'
          it { is_expected.to contain_concat('/etc/ferm/ferm.d/chains/filter-INPUT2.conf') }
        else
          it { is_expected.to contain_concat('/etc/ferm.d/chains/filter-INPUT2.conf') }
        end
        it { is_expected.to contain_ferm__chain('INPUT2') }
      end

      context 'without conntrack' do
        let :params do
          {
            disable_conntrack: true,
            log_dropped_packets: false
          }
        end

        it { is_expected.to compile.with_all_deps }

        it do
          expect(subject).to contain_concat__fragment('filter-INPUT2-policy')
          expect(subject).not_to contain_concat__fragment('filter-INPUT2-policy'). \
            with_content(%r{ESTABLISHED RELATED})
        end

        it do
          expect(subject).not_to contain_concat__fragment('filter-INPUT2-footer'). \
            with_content(%r{LOG log-prefix 'INPUT2: ';})
        end
      end

      context 'with policy setting for custom chain' do
        let :params do
          {
            chain: 'INPUT2',
            policy: 'DROP',
            disable_conntrack: true,
            log_dropped_packets: false
          }
        end

        it { is_expected.to compile.and_raise_error(%r{Can only set a default policy for builtin chains}) }
      end

      context 'with custom chain FERM-DSL using content parameter' do
        let(:title) { 'FERM-DSL' }
        let :params do
          {
            content: 'mod rpfilter invert DROP;'
          }
        end

        it { is_expected.to compile.with_all_deps }
        it { is_expected.to contain_concat__fragment('filter-FERM-DSL-config-include') }

        it do
          expect(subject).to contain_concat__fragment('filter-FERM-DSL-custom-content'). \
            with_content(%r{mod rpfilter invert DROP;})
        end

        it do
          expect(subject).not_to contain_concat__fragment('filter-FERM-DSL-policy')
        end

        it do
          expect(subject).not_to contain_concat__fragment('filter-FERM-DSL-footer')
        end

        if facts[:os]['name'] == 'Debian'
          it { is_expected.to contain_concat('/etc/ferm/ferm.d/chains/filter-FERM-DSL.conf') }
        else
          it { is_expected.to contain_concat('/etc/ferm.d/chains/filter-FERM-DSL.conf') }
        end
        it { is_expected.to contain_ferm__chain('FERM-DSL') }
      end
    end
  end
end