root / spec / defines / rule_spec.rb @ 04f5c035
Historique | Voir | Annoter | Télécharger (5,68 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 | 61f03b47 | Steve Traylen | { content: 'port 22 allow' } |
35 | e53053ce | Steve Traylen | 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 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
43 | content: %r{^#.*$}, |
||
44 | 61f03b47 | Steve Traylen | ) |
45 | e53053ce | Steve Traylen | } |
46 | it { |
||
47 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
50 | content: ' port 22 allow', |
||
51 | 61f03b47 | Steve Traylen | ) |
52 | e53053ce | Steve Traylen | } |
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 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-TABLE-chain-CHAIN_NAME', |
63 | content: %r{^#.*$}, |
||
64 | 61f03b47 | Steve Traylen | ) |
65 | e53053ce | Steve Traylen | } |
66 | it { is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE') }
|
||
67 | it { |
||
68 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-TABLE-chain-CHAIN_NAME', |
71 | content: ' port 22 allow', |
||
72 | 61f03b47 | Steve Traylen | ) |
73 | e53053ce | Steve Traylen | } |
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 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
90 | content: %r{^#.*$}, |
||
91 | 61f03b47 | Steve Traylen | ) |
92 | e53053ce | Steve Traylen | } |
93 | it { |
||
94 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
97 | source: 'puppet:///modules/foo/bar', |
||
98 | 61f03b47 | Steve Traylen | ) |
99 | e53053ce | Steve Traylen | } |
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 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-TABLE-chain-CHAIN_NAME', |
110 | content: %r{^#.*$}, |
||
111 | 61f03b47 | Steve Traylen | ) |
112 | e53053ce | Steve Traylen | } |
113 | it { is_expected.to contain_concat__fragment('nftables-TABLE-chain-CHAIN_NAME-rule-RULE') }
|
||
114 | it { |
||
115 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-TABLE-chain-CHAIN_NAME', |
118 | source: 'puppet:///modules/foo/bar', |
||
119 | 61f03b47 | Steve Traylen | ) |
120 | e53053ce | Steve Traylen | } |
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 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
141 | content: %r{^#.*$}, |
||
142 | 61f03b47 | Steve Traylen | ) |
143 | e53053ce | Steve Traylen | } |
144 | it { |
||
145 | 61f03b47 | Steve Traylen | 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 | e53053ce | Steve Traylen | target: 'nftables-inet-filter-chain-CHAIN_NAME', |
148 | content: ' port 22 allow', |
||
149 | 61f03b47 | Steve Traylen | ) |
150 | e53053ce | Steve Traylen | } |
151 | end
|
||
152 | end
|
||
153 | end
|
||
154 | end
|
||
155 | end |