|
1 | 1 | require 'spec_helper_acceptance'
|
2 | 2 |
|
3 | 3 | # RHEL5 does not support -m socket
|
4 |
| -if default['platform'] !~ /el-5/ |
5 |
| - describe 'firewall socket property' do |
6 |
| - before :all do |
7 |
| - iptables_flush_all_tables |
8 |
| - end |
| 4 | +describe 'firewall socket property', :unless => (default['platform'] =~ /el-5/ || fact('operatingsystem') == 'SLES') do |
| 5 | + before :all do |
| 6 | + iptables_flush_all_tables |
| 7 | + end |
9 | 8 |
|
10 |
| - shared_examples "is idempotent" do |value, line_match| |
11 |
| - it "changes the value to #{value}" do |
12 |
| - pp = <<-EOS |
13 |
| - class { '::firewall': } |
14 |
| - firewall { '598 - test': |
15 |
| - ensure => present, |
16 |
| - proto => 'tcp', |
17 |
| - chain => 'PREROUTING', |
18 |
| - table => 'raw', |
19 |
| - #{value} |
20 |
| - } |
21 |
| - EOS |
| 9 | + shared_examples "is idempotent" do |value, line_match| |
| 10 | + it "changes the value to #{value}" do |
| 11 | + pp = <<-EOS |
| 12 | + class { '::firewall': } |
| 13 | + firewall { '598 - test': |
| 14 | + ensure => present, |
| 15 | + proto => 'tcp', |
| 16 | + chain => 'PREROUTING', |
| 17 | + table => 'raw', |
| 18 | + #{value} |
| 19 | + } |
| 20 | + EOS |
22 | 21 |
|
23 |
| - apply_manifest(pp, :catch_failures => true) |
24 |
| - apply_manifest(pp, :catch_changes => true) |
| 22 | + apply_manifest(pp, :catch_failures => true) |
| 23 | + apply_manifest(pp, :catch_changes => true) |
25 | 24 |
|
26 |
| - shell('iptables-save -t raw') do |r| |
27 |
| - expect(r.stdout).to match(/#{line_match}/) |
28 |
| - end |
| 25 | + shell('iptables-save -t raw') do |r| |
| 26 | + expect(r.stdout).to match(/#{line_match}/) |
29 | 27 | end
|
30 | 28 | end
|
31 |
| - shared_examples "doesn't change" do |value, line_match| |
32 |
| - it "doesn't change the value to #{value}" do |
33 |
| - pp = <<-EOS |
34 |
| - class { '::firewall': } |
35 |
| - firewall { '598 - test': |
36 |
| - ensure => present, |
37 |
| - proto => 'tcp', |
38 |
| - chain => 'PREROUTING', |
39 |
| - table => 'raw', |
40 |
| - #{value} |
41 |
| - } |
42 |
| - EOS |
| 29 | + end |
| 30 | + shared_examples "doesn't change" do |value, line_match| |
| 31 | + it "doesn't change the value to #{value}" do |
| 32 | + pp = <<-EOS |
| 33 | + class { '::firewall': } |
| 34 | + firewall { '598 - test': |
| 35 | + ensure => present, |
| 36 | + proto => 'tcp', |
| 37 | + chain => 'PREROUTING', |
| 38 | + table => 'raw', |
| 39 | + #{value} |
| 40 | + } |
| 41 | + EOS |
43 | 42 |
|
44 |
| - apply_manifest(pp, :catch_changes => true) |
| 43 | + apply_manifest(pp, :catch_changes => true) |
45 | 44 |
|
46 |
| - shell('iptables-save -t raw') do |r| |
47 |
| - expect(r.stdout).to match(/#{line_match}/) |
48 |
| - end |
| 45 | + shell('iptables-save -t raw') do |r| |
| 46 | + expect(r.stdout).to match(/#{line_match}/) |
49 | 47 | end
|
50 | 48 | end
|
| 49 | + end |
51 | 50 |
|
52 |
| - describe 'adding a rule' do |
53 |
| - context 'when unset' do |
54 |
| - before :all do |
55 |
| - iptables_flush_all_tables |
56 |
| - end |
57 |
| - it_behaves_like 'is idempotent', '', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ |
| 51 | + describe 'adding a rule' do |
| 52 | + context 'when unset' do |
| 53 | + before :all do |
| 54 | + iptables_flush_all_tables |
58 | 55 | end
|
59 |
| - context 'when set to true' do |
60 |
| - before :all do |
61 |
| - iptables_flush_all_tables |
62 |
| - end |
63 |
| - it_behaves_like 'is idempotent', 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/ |
| 56 | + it_behaves_like 'is idempotent', '', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ |
| 57 | + end |
| 58 | + context 'when set to true' do |
| 59 | + before :all do |
| 60 | + iptables_flush_all_tables |
64 | 61 | end
|
65 |
| - context 'when set to false' do |
66 |
| - before :all do |
67 |
| - iptables_flush_all_tables |
68 |
| - end |
69 |
| - it_behaves_like "is idempotent", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ |
| 62 | + it_behaves_like 'is idempotent', 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/ |
| 63 | + end |
| 64 | + context 'when set to false' do |
| 65 | + before :all do |
| 66 | + iptables_flush_all_tables |
70 | 67 | end
|
| 68 | + it_behaves_like "is idempotent", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ |
71 | 69 | end
|
72 |
| - describe 'editing a rule' do |
73 |
| - context 'when unset or false' do |
74 |
| - before :each do |
75 |
| - iptables_flush_all_tables |
76 |
| - shell('iptables -t raw -A PREROUTING -p tcp -m comment --comment "598 - test"') |
77 |
| - end |
78 |
| - context 'and current value is false' do |
79 |
| - it_behaves_like "doesn't change", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ |
80 |
| - end |
81 |
| - context 'and current value is true' do |
82 |
| - it_behaves_like "is idempotent", 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/ |
83 |
| - end |
| 70 | + end |
| 71 | + describe 'editing a rule' do |
| 72 | + context 'when unset or false' do |
| 73 | + before :each do |
| 74 | + iptables_flush_all_tables |
| 75 | + shell('iptables -t raw -A PREROUTING -p tcp -m comment --comment "598 - test"') |
| 76 | + end |
| 77 | + context 'and current value is false' do |
| 78 | + it_behaves_like "doesn't change", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ |
| 79 | + end |
| 80 | + context 'and current value is true' do |
| 81 | + it_behaves_like "is idempotent", 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/ |
| 82 | + end |
| 83 | + end |
| 84 | + context 'when set to true' do |
| 85 | + before :each do |
| 86 | + iptables_flush_all_tables |
| 87 | + shell('iptables -t raw -A PREROUTING -p tcp -m socket -m comment --comment "598 - test"') |
| 88 | + end |
| 89 | + context 'and current value is false' do |
| 90 | + it_behaves_like "is idempotent", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ |
84 | 91 | end
|
85 |
| - context 'when set to true' do |
86 |
| - before :each do |
87 |
| - iptables_flush_all_tables |
88 |
| - shell('iptables -t raw -A PREROUTING -p tcp -m socket -m comment --comment "598 - test"') |
89 |
| - end |
90 |
| - context 'and current value is false' do |
91 |
| - it_behaves_like "is idempotent", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ |
92 |
| - end |
93 |
| - context 'and current value is true' do |
94 |
| - it_behaves_like "doesn't change", 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/ |
95 |
| - end |
| 92 | + context 'and current value is true' do |
| 93 | + it_behaves_like "doesn't change", 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/ |
96 | 94 | end
|
97 | 95 | end
|
98 | 96 | end
|
|
0 commit comments