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