root / spec / defines / rule_spec.rb @ e53053ce
Historique | Voir | Annoter | Télécharger (5,82 ko)
1 | e53053ce | Steve Traylen | 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 | { |
||
35 | content: 'port 22 allow', |
||
36 | } |
||
37 | end
|
||
38 | |||
39 | it { is_expected.to compile.with_all_deps } |
||
40 | it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE') }
|
||
41 | it { |
||
42 | is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE_header').with
|
||
43 | { |
||
44 | order: '50nftables-inet-filter-chain-CHAIN_NAME-rule-RULEa', |
||
45 | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
||
46 | content: %r{^#.*$}, |
||
47 | } |
||
48 | } |
||
49 | it { |
||
50 | is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE').with
|
||
51 | { |
||
52 | order: '50nftables-inet-filter-chain-CHAIN_NAME-rule-RULEb', |
||
53 | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
||
54 | content: ' port 22 allow', |
||
55 | } |
||
56 | } |
||
57 | context 'with optional parameters set' do |
||
58 | let(:params) do |
||
59 | super().merge(order: '85', |
||
60 | table: 'TABLE') |
||
61 | end
|
||
62 | |||
63 | it { |
||
64 | is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE_header').with
|
||
65 | { |
||
66 | order: '85nftables-TABLE-chain-CHAIN_NAME-rule-RULEa', |
||
67 | target: 'nftables-TABLE-chain-CHAIN_NAME', |
||
68 | content: %r{^#.*$}, |
||
69 | } |
||
70 | } |
||
71 | it { is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE') }
|
||
72 | it { |
||
73 | is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE').with
|
||
74 | { |
||
75 | order: '85nftables-TABLE-chain-CHAIN_NAME-rule-RULEb', |
||
76 | target: 'nftables-TABLE-chain-CHAIN_NAME', |
||
77 | content: ' port 22 allow', |
||
78 | } |
||
79 | } |
||
80 | end
|
||
81 | end
|
||
82 | |||
83 | context 'with source parameter set' do |
||
84 | let(:params) do |
||
85 | { |
||
86 | source: 'puppet:///modules/foo/bar', |
||
87 | } |
||
88 | end
|
||
89 | |||
90 | it { is_expected.to compile.with_all_deps } |
||
91 | it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE') }
|
||
92 | it { |
||
93 | is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE_header').with
|
||
94 | { |
||
95 | order: '50nftables-inet-filter-chain-CHAIN_NAME-rule-RULEa', |
||
96 | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
||
97 | content: %r{^#.*$}, |
||
98 | } |
||
99 | } |
||
100 | it { |
||
101 | is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE').with
|
||
102 | { |
||
103 | order: '50nftables-inet-filter-chain-CHAIN_NAME-rule-RULEb', |
||
104 | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
||
105 | source: 'puppet:///modules/foo/bar', |
||
106 | } |
||
107 | } |
||
108 | context 'with optional parameters set' do |
||
109 | let(:params) do |
||
110 | super().merge(order: '85', |
||
111 | table: 'TABLE') |
||
112 | end
|
||
113 | |||
114 | it { |
||
115 | is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE_header').with
|
||
116 | { |
||
117 | order: '85nftables-TABLE-chain-CHAIN_NAME-rule-RULEa', |
||
118 | target: 'nftables-TABLE-chain-CHAIN_NAME', |
||
119 | content: %r{^#.*$}, |
||
120 | } |
||
121 | } |
||
122 | it { is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE') }
|
||
123 | it { |
||
124 | is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE').with
|
||
125 | { |
||
126 | order: '85nftables-TABLE-chain-CHAIN_NAME-rule-RULEb', |
||
127 | target: 'nftables-TABLE-chain-CHAIN_NAME', |
||
128 | source: 'puppet:///modules/foo/bar', |
||
129 | } |
||
130 | } |
||
131 | end
|
||
132 | end
|
||
133 | end
|
||
134 | |||
135 | context 'with title set to <CHAIN_NAME>-<RULE>-22' do |
||
136 | let(:title) { 'CHAIN_NAME-RULE-22' } |
||
137 | |||
138 | context 'with content parameter set' do |
||
139 | let(:params) do |
||
140 | { |
||
141 | content: 'port 22 allow', |
||
142 | } |
||
143 | end
|
||
144 | |||
145 | it { is_expected.to compile.with_all_deps } |
||
146 | it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22') }
|
||
147 | it { |
||
148 | is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22_header').with
|
||
149 | { |
||
150 | order: '50nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22a', |
||
151 | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
||
152 | content: %r{^#.*$}, |
||
153 | } |
||
154 | } |
||
155 | it { |
||
156 | is_expected.to contain_concat__fragment('nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22').with
|
||
157 | { |
||
158 | order: '50nftables-inet-filter-chain-CHAIN_NAME-rule-RULE-22b', |
||
159 | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
||
160 | content: ' port 22 allow', |
||
161 | } |
||
162 | } |
||
163 | end
|
||
164 | end
|
||
165 | end
|
||
166 | end
|
||
167 | end |