Projet

Général

Profil

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

root / spec / defines / set_spec.rb @ 8f4434ed

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

1
# frozen_string_literal: true
2

    
3
require 'spec_helper'
4

    
5
describe 'nftables::set' do
6
  let(:pre_condition) { 'include nftables' }
7

    
8
  let(:title) { 'my_set' }
9

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

    
14
      describe 'minimum instantiation' do
15
        let(:params) do
16
          {
17
            type: 'ipv4_addr',
18
          }
19
        end
20

    
21
        it { is_expected.to compile }
22

    
23
        it {
24
          expect(subject).to contain_concat__fragment('nftables-inet-filter-set-my_set').with(
25
            target: 'nftables-inet-filter',
26
            content: %r{^  set my_set \{\n    type ipv4_addr\n  \}$}m,
27
            order: '10'
28
          )
29
        }
30
      end
31

    
32
      describe 'max size exceeding the prepopulated elements' do
33
        let(:params) do
34
          {
35
            type: 'ipv6_addr',
36
            elements: ['2001:1458::/32', '2001:1458:1::/48'],
37
            size: 1,
38
          }
39
        end
40

    
41
        it { is_expected.not_to compile }
42
      end
43

    
44
      describe 'invalid type' do
45
        let(:params) do
46
          {
47
            type: 'foo',
48
          }
49
        end
50

    
51
        it { is_expected.not_to compile }
52
      end
53

    
54
      describe 'invalid flags' do
55
        let(:params) do
56
          {
57
            type: 'ipv4_addr',
58
            flags: ['foo'],
59
          }
60
        end
61

    
62
        it { is_expected.not_to compile }
63
      end
64

    
65
      describe 'ipv6 prepopulated' do
66
        let(:params) do
67
          {
68
            type: 'ipv6_addr',
69
            elements: ['2001:1458::/32', '2001:1458:1::/48'],
70
          }
71
        end
72

    
73
        it { is_expected.to compile }
74

    
75
        it {
76
          expect(subject).to contain_concat__fragment('nftables-inet-filter-set-my_set').with(
77
            target: 'nftables-inet-filter',
78
            content: %r{^  set my_set \{\n    type ipv6_addr\n    elements = \{ 2001:1458::/32, 2001:1458:1::/48 \}\n  \}$}m,
79
            order: '10'
80
          )
81
        }
82
      end
83

    
84
      describe 'using flags and auto-merge' do
85
        let(:params) do
86
          {
87
            type: 'ipv4_addr',
88
            flags: %w[interval timeout],
89
            elements: ['192.168.0.1/24'],
90
            auto_merge: true,
91
          }
92
        end
93

    
94
        it { is_expected.to compile }
95

    
96
        it {
97
          expect(subject).to contain_concat__fragment('nftables-inet-filter-set-my_set').with(
98
            target: 'nftables-inet-filter',
99
            content: %r{^  set my_set \{\n    type ipv4_addr\n    flags interval, timeout\n    elements = \{ 192.168.0.1/24 \}\n    auto-merge\n  \}$}m,
100
            order: '10'
101
          )
102
        }
103
      end
104

    
105
      describe 'using ether_addr as type and custom policy' do
106
        let(:params) do
107
          {
108
            type: 'ether_addr',
109
            elements: ['aa:bb:cc:dd:ee:ff'],
110
            policy: 'memory',
111
          }
112
        end
113

    
114
        it { is_expected.to compile }
115

    
116
        it {
117
          expect(subject).to contain_concat__fragment('nftables-inet-filter-set-my_set').with(
118
            target: 'nftables-inet-filter',
119
            content: %r{^  set my_set \{\n    type ether_addr\n    elements = \{ aa:bb:cc:dd:ee:ff \}\n    policy memory\n  \}$}m,
120
            order: '10'
121
          )
122
        }
123
      end
124

    
125
      describe 'using raw content' do
126
        let(:params) do
127
          {
128
            content: 'set my_set { }',
129
          }
130
        end
131

    
132
        it { is_expected.to compile }
133

    
134
        it {
135
          expect(subject).to contain_concat__fragment('nftables-inet-filter-set-my_set').with(
136
            target: 'nftables-inet-filter',
137
            content: '  set my_set { }',
138
            order: '10'
139
          )
140
        }
141
      end
142

    
143
      describe 'fails without a type and not source/content' do
144
        it { is_expected.not_to compile }
145
      end
146

    
147
      describe 'set names with dashes are allowed' do
148
        let(:title) { 'my-set' }
149
        let(:params) do
150
          {
151
            type: 'ether_addr',
152
          }
153
        end
154

    
155
        it { is_expected.to compile }
156

    
157
        it {
158
          expect(subject).to contain_concat__fragment('nftables-inet-filter-set-my-set').with(
159
            target: 'nftables-inet-filter',
160
            content: %r{^  set my-set \{\n    type ether_addr\n  \}$}m,
161
            order: '10'
162
          )
163
        }
164
      end
165

    
166
      describe 'default table can be changed' do
167
        let(:params) do
168
          {
169
            type: 'ipv6_addr',
170
            elements: ['2001:1458::1', '2001:1458:1::2'],
171
            table: 'ip-nat'
172
          }
173
        end
174

    
175
        it { is_expected.to compile }
176

    
177
        it {
178
          expect(subject).to contain_concat__fragment('nftables-ip-nat-set-my_set').with(
179
            target: 'nftables-ip-nat',
180
            content: %r{^  set my_set \{\n    type ipv6_addr\n    elements = \{ 2001:1458::1, 2001:1458:1::2 \}\n  \}$}m,
181
            order: '10'
182
          )
183
        }
184
      end
185

    
186
      describe 'multiple tables no tables' do
187
        let(:params) do
188
          {
189
            type: 'ipv6_addr',
190
            elements: ['2001:1458::1', '2001:1458:1::2'],
191
            table: []
192
          }
193
        end
194

    
195
        it { is_expected.not_to compile }
196
      end
197

    
198
      describe 'multiple tables' do
199
        let(:params) do
200
          {
201
            type: 'ipv6_addr',
202
            elements: ['2001:1458::1', '2001:1458:1::2'],
203
            table: %w[inet-filter ip-nat]
204
          }
205
        end
206

    
207
        it { is_expected.to compile }
208

    
209
        it {
210
          expect(subject).to contain_concat__fragment('nftables-inet-filter-set-my_set').with(
211
            target: 'nftables-inet-filter',
212
            content: %r{^  set my_set \{\n    type ipv6_addr\n    elements = \{ 2001:1458::1, 2001:1458:1::2 \}\n  \}$}m,
213
            order: '10'
214
          )
215
          expect(subject).to contain_concat__fragment('nftables-ip-nat-set-my_set').with(
216
            target: 'nftables-ip-nat',
217
            content: %r{^  set my_set \{\n    type ipv6_addr\n    elements = \{ 2001:1458::1, 2001:1458:1::2 \}\n  \}$}m,
218
            order: '10'
219
          )
220
        }
221
      end
222
    end
223
  end
224
end