root / spec / defines / rule_spec.rb @ a1f09048
Historique | Voir | Annoter | Télécharger (5,75 ko)
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
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 |
|
21 |
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 |
expect(subject).not_to compile |
32 |
} |
33 |
end
|
34 |
|
35 |
context 'with content parameter set' do |
36 |
let(:params) do |
37 |
{ content: 'port 22 allow' } |
38 |
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 |
|
43 |
it { |
44 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE_header').with(
|
45 |
order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-a', |
46 |
target: 'nftables-inet-filter-chain-CHAIN_NAME', |
47 |
content: %r{^#.*$} |
48 |
) |
49 |
} |
50 |
|
51 |
it { |
52 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE').with(
|
53 |
order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-b', |
54 |
target: 'nftables-inet-filter-chain-CHAIN_NAME', |
55 |
content: ' port 22 allow' |
56 |
) |
57 |
} |
58 |
|
59 |
context 'with optional parameters set' do |
60 |
let(:params) do |
61 |
super().merge(order: '85', |
62 |
table: 'TABLE') |
63 |
end
|
64 |
|
65 |
it { |
66 |
expect(subject).to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE_header').with(
|
67 |
order: '85-nftables-TABLE-chain-CHAIN_NAME-rule-RULE-a', |
68 |
target: 'nftables-TABLE-chain-CHAIN_NAME', |
69 |
content: %r{^#.*$} |
70 |
) |
71 |
} |
72 |
|
73 |
it { is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE') }
|
74 |
|
75 |
it { |
76 |
expect(subject).to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE').with(
|
77 |
order: '85-nftables-TABLE-chain-CHAIN_NAME-rule-RULE-b', |
78 |
target: 'nftables-TABLE-chain-CHAIN_NAME', |
79 |
content: ' port 22 allow' |
80 |
) |
81 |
} |
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 |
|
95 |
it { |
96 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE_header').with(
|
97 |
order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-a', |
98 |
target: 'nftables-inet-filter-chain-CHAIN_NAME', |
99 |
content: %r{^#.*$} |
100 |
) |
101 |
} |
102 |
|
103 |
it { |
104 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE').with(
|
105 |
order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-b', |
106 |
target: 'nftables-inet-filter-chain-CHAIN_NAME', |
107 |
source: 'puppet:///modules/foo/bar' |
108 |
) |
109 |
} |
110 |
|
111 |
context 'with optional parameters set' do |
112 |
let(:params) do |
113 |
super().merge(order: '85', |
114 |
table: 'TABLE') |
115 |
end
|
116 |
|
117 |
it { |
118 |
expect(subject).to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE_header').with(
|
119 |
order: '85-nftables-TABLE-chain-CHAIN_NAME-rule-RULE-a', |
120 |
target: 'nftables-TABLE-chain-CHAIN_NAME', |
121 |
content: %r{^#.*$} |
122 |
) |
123 |
} |
124 |
|
125 |
it { is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE') }
|
126 |
|
127 |
it { |
128 |
expect(subject).to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE').with(
|
129 |
order: '85-nftables-TABLE-chain-CHAIN_NAME-rule-RULE-b', |
130 |
target: 'nftables-TABLE-chain-CHAIN_NAME', |
131 |
source: 'puppet:///modules/foo/bar' |
132 |
) |
133 |
} |
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 |
|
151 |
it { |
152 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22_header').with(
|
153 |
order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22-a', |
154 |
target: 'nftables-inet-filter-chain-CHAIN_NAME', |
155 |
content: %r{^#.*$} |
156 |
) |
157 |
} |
158 |
|
159 |
it { |
160 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22').with(
|
161 |
order: '50-nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22-b', |
162 |
target: 'nftables-inet-filter-chain-CHAIN_NAME', |
163 |
content: ' port 22 allow' |
164 |
) |
165 |
} |
166 |
end
|
167 |
end
|
168 |
end
|
169 |
end
|
170 |
end
|