Projet

Général

Profil

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

root / spec / defines / rule_spec.rb @ 3016d428

Historique | Voir | Annoter | Télécharger (5,75 ko)

1 c82b960a Steve Traylen
# frozen_string_literal: true
2
3 e53053ce Steve Traylen
require 'spec_helper'
4
5
describe 'nftables::rule' do
6
  let(:title) { 'out-foo' }
7
8
  on_supported_os.each do |os, facts|
9
    context "on #{os}" do
10
      let(:facts) do
11
        facts
12
      end
13
14
      context 'with title set to <CHAIN_NAME>-<RULE>' do
15
        let(:title) { 'CHAIN_NAME-RULE' }
16
17
        context 'with source and content both unset' do
18
          it { is_expected.not_to compile }
19
        end
20 c82b960a Steve Traylen
21 e53053ce Steve Traylen
        context 'with source and content both set' do
22
          let(:params) do
23
            {
24
              source: 'foo',
25
              content: 'puppet:///modules/foo/bar',
26
            }
27
          end
28
29
          it {
30
            pending('Setting source and content should be made to fail')
31 c82b960a Steve Traylen
            expect(subject).not_to compile
32 e53053ce Steve Traylen
          }
33
        end
34
35
        context 'with content parameter set' do
36
          let(:params) do
37 61f03b47 Steve Traylen
            { content: 'port 22 allow' }
38 e53053ce Steve Traylen
          end
39
40
          it { is_expected.to compile.with_all_deps }
41
          it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE') }
42 c82b960a Steve Traylen
43 e53053ce Steve Traylen
          it {
44 c82b960a Steve Traylen
            expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE_header').with(
45 61f03b47 Steve Traylen
              order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-a',
46 e53053ce Steve Traylen
              target: 'nftables-inet-filter-chain-CHAIN_NAME',
47 fa92e118 Romain Tartière
              content: %r{^#.*$}
48 61f03b47 Steve Traylen
            )
49 e53053ce Steve Traylen
          }
50 c82b960a Steve Traylen
51 e53053ce Steve Traylen
          it {
52 c82b960a Steve Traylen
            expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE').with(
53 61f03b47 Steve Traylen
              order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-b',
54 e53053ce Steve Traylen
              target: 'nftables-inet-filter-chain-CHAIN_NAME',
55 fa92e118 Romain Tartière
              content: '  port 22 allow'
56 61f03b47 Steve Traylen
            )
57 e53053ce Steve Traylen
          }
58 c82b960a Steve Traylen
59 e53053ce Steve Traylen
          context 'with optional parameters set' do
60
            let(:params) do
61
              super().merge(order: '85',
62
                            table: 'TABLE')
63
            end
64
65
            it {
66 c82b960a Steve Traylen
              expect(subject).to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE_header').with(
67 61f03b47 Steve Traylen
                order: '85-nftables-TABLE-chain-CHAIN_NAME-rule-RULE-a',
68 e53053ce Steve Traylen
                target: 'nftables-TABLE-chain-CHAIN_NAME',
69 fa92e118 Romain Tartière
                content: %r{^#.*$}
70 61f03b47 Steve Traylen
              )
71 e53053ce Steve Traylen
            }
72 c82b960a Steve Traylen
73 e53053ce Steve Traylen
            it { is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE') }
74 c82b960a Steve Traylen
75 e53053ce Steve Traylen
            it {
76 c82b960a Steve Traylen
              expect(subject).to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE').with(
77 61f03b47 Steve Traylen
                order: '85-nftables-TABLE-chain-CHAIN_NAME-rule-RULE-b',
78 e53053ce Steve Traylen
                target: 'nftables-TABLE-chain-CHAIN_NAME',
79 fa92e118 Romain Tartière
                content: '  port 22 allow'
80 61f03b47 Steve Traylen
              )
81 e53053ce Steve Traylen
            }
82
          end
83
        end
84
85
        context 'with source parameter set' do
86
          let(:params) do
87
            {
88
              source: 'puppet:///modules/foo/bar',
89
            }
90
          end
91
92
          it { is_expected.to compile.with_all_deps }
93
          it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE') }
94 c82b960a Steve Traylen
95 e53053ce Steve Traylen
          it {
96 c82b960a Steve Traylen
            expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE_header').with(
97 61f03b47 Steve Traylen
              order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-a',
98 e53053ce Steve Traylen
              target: 'nftables-inet-filter-chain-CHAIN_NAME',
99 fa92e118 Romain Tartière
              content: %r{^#.*$}
100 61f03b47 Steve Traylen
            )
101 e53053ce Steve Traylen
          }
102 c82b960a Steve Traylen
103 e53053ce Steve Traylen
          it {
104 c82b960a Steve Traylen
            expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE').with(
105 61f03b47 Steve Traylen
              order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-b',
106 e53053ce Steve Traylen
              target: 'nftables-inet-filter-chain-CHAIN_NAME',
107 fa92e118 Romain Tartière
              source: 'puppet:///modules/foo/bar'
108 61f03b47 Steve Traylen
            )
109 e53053ce Steve Traylen
          }
110 c82b960a Steve Traylen
111 e53053ce Steve Traylen
          context 'with optional parameters set' do
112
            let(:params) do
113
              super().merge(order: '85',
114
                            table: 'TABLE')
115
            end
116
117
            it {
118 c82b960a Steve Traylen
              expect(subject).to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE_header').with(
119 61f03b47 Steve Traylen
                order: '85-nftables-TABLE-chain-CHAIN_NAME-rule-RULE-a',
120 e53053ce Steve Traylen
                target: 'nftables-TABLE-chain-CHAIN_NAME',
121 fa92e118 Romain Tartière
                content: %r{^#.*$}
122 61f03b47 Steve Traylen
              )
123 e53053ce Steve Traylen
            }
124 c82b960a Steve Traylen
125 e53053ce Steve Traylen
            it { is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE') }
126 c82b960a Steve Traylen
127 e53053ce Steve Traylen
            it {
128 c82b960a Steve Traylen
              expect(subject).to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE').with(
129 61f03b47 Steve Traylen
                order: '85-nftables-TABLE-chain-CHAIN_NAME-rule-RULE-b',
130 e53053ce Steve Traylen
                target: 'nftables-TABLE-chain-CHAIN_NAME',
131 fa92e118 Romain Tartière
                source: 'puppet:///modules/foo/bar'
132 61f03b47 Steve Traylen
              )
133 e53053ce Steve Traylen
            }
134
          end
135
        end
136
      end
137
138
      context 'with title set to <CHAIN_NAME>-<RULE>-22' do
139
        let(:title) { 'CHAIN_NAME-RULE-22' }
140
141
        context 'with content parameter set' do
142
          let(:params) do
143
            {
144
              content: 'port 22 allow',
145
            }
146
          end
147
148
          it { is_expected.to compile.with_all_deps }
149
          it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22') }
150 c82b960a Steve Traylen
151 e53053ce Steve Traylen
          it {
152 c82b960a Steve Traylen
            expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22_header').with(
153 61f03b47 Steve Traylen
              order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22-a',
154 e53053ce Steve Traylen
              target: 'nftables-inet-filter-chain-CHAIN_NAME',
155 fa92e118 Romain Tartière
              content: %r{^#.*$}
156 61f03b47 Steve Traylen
            )
157 e53053ce Steve Traylen
          }
158 c82b960a Steve Traylen
159 e53053ce Steve Traylen
          it {
160 c82b960a Steve Traylen
            expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22').with(
161 61f03b47 Steve Traylen
              order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22-b',
162 e53053ce Steve Traylen
              target: 'nftables-inet-filter-chain-CHAIN_NAME',
163 fa92e118 Romain Tartière
              content: '  port 22 allow'
164 61f03b47 Steve Traylen
            )
165 e53053ce Steve Traylen
          }
166
        end
167
      end
168
    end
169
  end
170
end