| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "puppetlabs/firewall", | ||
| "version": "0.4.2", | ||
| "summary": "Firewall resources (iptables)", | ||
| "source": "git@github.com/puppetlabs/puppetlabs-firewall.git", | ||
| "project_page": "http://github.com/puppetlabs/puppetlabs-firewall", | ||
| "author": "Puppet Labs", | ||
| "license": "Apache-2.0", | ||
| "operatingsystem_support": [ | ||
| "RedHat", | ||
| "Debian", | ||
| "Ubuntu", | ||
| "SuSE", | ||
| "SLED" | ||
| ], | ||
| "puppet_version": [ | ||
| 2.7, | ||
| 3.0, | ||
| 3.1, | ||
| 3.2, | ||
| 3.3 | ||
| ], | ||
| "dependencies": [ | ||
| { | ||
| "name": "puppetlabs/stdlib", | ||
| "version_requirement": ">= 2.2.1" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| # Here we put the more basic fundamental tests, ultra obvious stuff. | ||
| describe "basic tests:" do | ||
| it 'make sure we have copied the module across' do | ||
| shell('ls /etc/puppet/modules/firewall/Modulefile', {:acceptable_exit_codes => 0}) | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| describe 'firewall type' do | ||
| describe 'reset' do | ||
| it 'deletes all rules' do | ||
| shell('iptables --flush; iptables -t nat --flush; iptables -t mangle --flush') | ||
| end | ||
| end | ||
|
|
||
| describe 'when unmanaged rules exist' do | ||
| it 'applies with 8.0.0.1 first' do | ||
| pp = <<-EOS | ||
| class { '::firewall': } | ||
| firewall { '101 test source changes': | ||
| proto => tcp, | ||
| port => '101', | ||
| action => accept, | ||
| source => '8.0.0.1', | ||
| } | ||
| firewall { '100 test source static': | ||
| proto => tcp, | ||
| port => '100', | ||
| action => accept, | ||
| source => '8.0.0.2', | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_failures => true) | ||
| end | ||
|
|
||
| it 'adds a unmanaged rule without a comment' do | ||
| shell('/sbin/iptables -A INPUT -t filter -s 8.0.0.3/32 -p tcp -m multiport --ports 102 -j ACCEPT') | ||
| expect(shell('iptables -S').stdout).to match(/-A INPUT -s 8\.0\.0\.3\/32 -p tcp -m multiport --ports 102 -j ACCEPT/) | ||
| end | ||
|
|
||
| it 'contains the changable 8.0.0.1 rule' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to match(/-A INPUT -s 8\.0\.0\.1\/32 -p tcp -m multiport --ports 101 -m comment --comment "101 test source changes" -j ACCEPT/) | ||
| end | ||
| end | ||
| it 'contains the static 8.0.0.2 rule' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to match(/-A INPUT -s 8\.0\.0\.2\/32 -p tcp -m multiport --ports 100 -m comment --comment "100 test source static" -j ACCEPT/) | ||
| end | ||
| end | ||
|
|
||
| it 'changes to 8.0.0.4 second' do | ||
| pp = <<-EOS | ||
| class { '::firewall': } | ||
| firewall { '101 test source changes': | ||
| proto => tcp, | ||
| port => '101', | ||
| action => accept, | ||
| source => '8.0.0.4', | ||
| } | ||
| EOS | ||
|
|
||
| expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/Notice: \/Stage\[main\]\/Main\/Firewall\[101 test source changes\]\/source: source changed '8\.0\.0\.1\/32' to '8\.0\.0\.4\/32'/) | ||
| end | ||
|
|
||
| it 'does not contain the old changing 8.0.0.1 rule' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to_not match(/8\.0\.0\.1/) | ||
| end | ||
| end | ||
| it 'contains the staic 8.0.0.2 rule' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to match(/-A INPUT -s 8\.0\.0\.2\/32 -p tcp -m multiport --ports 100 -m comment --comment "100 test source static" -j ACCEPT/) | ||
| end | ||
| end | ||
| it 'contains the changing new 8.0.0.4 rule' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to match(/-A INPUT -s 8\.0\.0\.4\/32 -p tcp -m multiport --ports 101 -m comment --comment "101 test source changes" -j ACCEPT/) | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| describe "firewall class:" do | ||
| it 'should run successfully' do | ||
| pp = "class { 'firewall': }" | ||
|
|
||
| # Run it twice and test for idempotency | ||
| apply_manifest(pp, :catch_failures => true) | ||
| expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero | ||
| end | ||
|
|
||
| it 'ensure => stopped:' do | ||
| pp = "class { 'firewall': ensure => stopped }" | ||
|
|
||
| # Run it twice and test for idempotency | ||
| apply_manifest(pp, :catch_failures => true) | ||
| expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero | ||
| end | ||
|
|
||
| it 'ensure => running:' do | ||
| pp = "class { 'firewall': ensure => running }" | ||
|
|
||
| # Run it twice and test for idempotency | ||
| apply_manifest(pp, :catch_failures => true) | ||
| expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| describe 'puppet resource firewallchain command:' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
| describe 'ensure' do | ||
| context 'present' do | ||
| it 'applies cleanly' do | ||
| pp = <<-EOS | ||
| firewallchain { 'MY_CHAIN:filter:IPv4': | ||
| ensure => present, | ||
| } | ||
| EOS | ||
| # Run it twice and test for idempotency | ||
| apply_manifest(pp, :catch_failures => true) | ||
| apply_manifest(pp, :catch_changes => true) | ||
| end | ||
|
|
||
| it 'finds the chain' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to match(/-N MY_CHAIN/) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'absent' do | ||
| it 'applies cleanly' do | ||
| pp = <<-EOS | ||
| firewallchain { 'MY_CHAIN:filter:IPv4': | ||
| ensure => absent, | ||
| } | ||
| EOS | ||
| # Run it twice and test for idempotency | ||
| apply_manifest(pp, :catch_failures => true) | ||
| apply_manifest(pp, :catch_changes => true) | ||
| end | ||
|
|
||
| it 'fails to find the chain' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to_not match(/-N MY_CHAIN/) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # XXX purge => false is not yet implemented | ||
| #context 'adding a firewall rule to a chain:' do | ||
| # it 'applies cleanly' do | ||
| # pp = <<-EOS | ||
| # firewallchain { 'MY_CHAIN:filter:IPv4': | ||
| # ensure => present, | ||
| # } | ||
| # firewall { '100 my rule': | ||
| # chain => 'MY_CHAIN', | ||
| # action => 'accept', | ||
| # proto => 'tcp', | ||
| # dport => 5000, | ||
| # } | ||
| # EOS | ||
| # # Run it twice and test for idempotency | ||
| # apply_manifest(pp, :catch_failures => true) | ||
| # apply_manifest(pp, :catch_changes => true) | ||
| # end | ||
| #end | ||
|
|
||
| #context 'not purge firewallchain chains:' do | ||
| # it 'does not purge the rule' do | ||
| # pp = <<-EOS | ||
| # firewallchain { 'MY_CHAIN:filter:IPv4': | ||
| # ensure => present, | ||
| # purge => false, | ||
| # before => Resources['firewall'], | ||
| # } | ||
| # resources { 'firewall': | ||
| # purge => true, | ||
| # } | ||
| # EOS | ||
| # # Run it twice and test for idempotency | ||
| # apply_manifest(pp, :catch_failures => true) do |r| | ||
| # expect(r.stdout).to_not match(/removed/) | ||
| # expect(r.stderr).to eq('') | ||
| # end | ||
| # apply_manifest(pp, :catch_changes => true) | ||
| # end | ||
|
|
||
| # it 'still has the rule' do | ||
| # pp = <<-EOS | ||
| # firewall { '100 my rule': | ||
| # chain => 'MY_CHAIN', | ||
| # action => 'accept', | ||
| # proto => 'tcp', | ||
| # dport => 5000, | ||
| # } | ||
| # EOS | ||
| # # Run it twice and test for idempotency | ||
| # apply_manifest(pp, :catch_changes => true) | ||
| # end | ||
| #end | ||
|
|
||
| describe 'policy' do | ||
| after :all do | ||
| shell('iptables -t filter -P FORWARD ACCEPT') | ||
| end | ||
|
|
||
| context 'DROP' do | ||
| it 'applies cleanly' do | ||
| pp = <<-EOS | ||
| firewallchain { 'FORWARD:filter:IPv4': | ||
| policy => 'drop', | ||
| } | ||
| EOS | ||
| # Run it twice and test for idempotency | ||
| apply_manifest(pp, :catch_failures => true) | ||
| apply_manifest(pp, :catch_changes => true) | ||
| end | ||
|
|
||
| it 'finds the chain' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to match(/-P FORWARD DROP/) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| describe 'firewall ishasmorefrags/islastfrag/isfirstfrag properties' do | ||
| before :all do | ||
| ip6tables_flush_all_tables | ||
| end | ||
|
|
||
| shared_examples "is idempotent" do |values, line_match| | ||
| it "changes the values to #{values}" do | ||
| pp = <<-EOS | ||
| class { '::firewall': } | ||
| firewall { '599 - test': | ||
| ensure => present, | ||
| proto => 'tcp', | ||
| provider => 'ip6tables', | ||
| #{values} | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_failures => true) | ||
| apply_manifest(pp, :catch_changes => true) | ||
|
|
||
| shell('ip6tables -S') do |r| | ||
| expect(r.stdout).to match(/#{line_match}/) | ||
| end | ||
| end | ||
| end | ||
| shared_examples "doesn't change" do |values, line_match| | ||
| it "doesn't change the values to #{values}" do | ||
| pp = <<-EOS | ||
| class { '::firewall': } | ||
| firewall { '599 - test': | ||
| ensure => present, | ||
| proto => 'tcp', | ||
| provider => 'ip6tables', | ||
| #{values} | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_changes => true) | ||
|
|
||
| shell('ip6tables -S') do |r| | ||
| expect(r.stdout).to match(/#{line_match}/) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'adding a rule' do | ||
| context 'when unset' do | ||
| before :all do | ||
| ip6tables_flush_all_tables | ||
| end | ||
| it_behaves_like 'is idempotent', '', /-A INPUT -p tcp -m comment --comment "599 - test"/ | ||
| end | ||
| context 'when set to true' do | ||
| before :all do | ||
| ip6tables_flush_all_tables | ||
| end | ||
| it_behaves_like "is idempotent", 'ishasmorefrags => true, islastfrag => true, isfirstfrag => true', /-A INPUT -p tcp -m frag --fragid 0 --fragmore -m frag --fragid 0 --fraglast -m frag --fragid 0 --fragfirst -m comment --comment "599 - test"/ | ||
| end | ||
| context 'when set to false' do | ||
| before :all do | ||
| ip6tables_flush_all_tables | ||
| end | ||
| it_behaves_like "is idempotent", 'ishasmorefrags => false, islastfrag => false, isfirstfrag => false', /-A INPUT -p tcp -m comment --comment "599 - test"/ | ||
| end | ||
| end | ||
| describe 'editing a rule' do | ||
| context 'when unset or false' do | ||
| before :each do | ||
| ip6tables_flush_all_tables | ||
| shell('/sbin/ip6tables -A INPUT -p tcp -m comment --comment "599 - test"') | ||
| end | ||
| context 'and current value is false' do | ||
| it_behaves_like "doesn't change", 'ishasmorefrags => false, islastfrag => false, isfirstfrag => false', /-A INPUT -p tcp -m comment --comment "599 - test"/ | ||
| end | ||
| context 'and current value is true' do | ||
| it_behaves_like "is idempotent", 'ishasmorefrags => true, islastfrag => true, isfirstfrag => true', /-A INPUT -p tcp -m frag --fragid 0 --fragmore -m frag --fragid 0 --fraglast -m frag --fragid 0 --fragfirst -m comment --comment "599 - test"/ | ||
| end | ||
| end | ||
| context 'when set to true' do | ||
| before :each do | ||
| ip6tables_flush_all_tables | ||
| shell('/sbin/ip6tables -A INPUT -p tcp -m frag --fragid 0 --fragmore -m frag --fragid 0 --fraglast -m frag --fragid 0 --fragfirst -m comment --comment "599 - test"') | ||
| end | ||
| context 'and current value is false' do | ||
| it_behaves_like "is idempotent", 'ishasmorefrags => false, islastfrag => false, isfirstfrag => false', /-A INPUT -p tcp -m comment --comment "599 - test"/ | ||
| end | ||
| context 'and current value is true' do | ||
| it_behaves_like "doesn't change", 'ishasmorefrags => true, islastfrag => true, isfirstfrag => true', /-A INPUT -p tcp -m frag --fragid 0 --fragmore -m frag --fragid 0 --fraglast -m frag --fragid 0 --fragfirst -m comment --comment "599 - test"/ | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| describe 'firewall isfragment property' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
|
|
||
| shared_examples "is idempotent" do |value, line_match| | ||
| it "changes the value to #{value}" do | ||
| pp = <<-EOS | ||
| class { '::firewall': } | ||
| firewall { '597 - test': | ||
| ensure => present, | ||
| proto => 'tcp', | ||
| #{value} | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_failures => true) | ||
| apply_manifest(pp, :catch_changes => true) | ||
|
|
||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to match(/#{line_match}/) | ||
| end | ||
| end | ||
| end | ||
| shared_examples "doesn't change" do |value, line_match| | ||
| it "doesn't change the value to #{value}" do | ||
| pp = <<-EOS | ||
| class { '::firewall': } | ||
| firewall { '597 - test': | ||
| ensure => present, | ||
| proto => 'tcp', | ||
| #{value} | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_changes => true) | ||
|
|
||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to match(/#{line_match}/) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'adding a rule' do | ||
| context 'when unset' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
| it_behaves_like 'is idempotent', '', /-A INPUT -p tcp -m comment --comment "597 - test"/ | ||
| end | ||
| context 'when set to true' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
| it_behaves_like 'is idempotent', 'isfragment => true,', /-A INPUT -p tcp -f -m comment --comment "597 - test"/ | ||
| end | ||
| context 'when set to false' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
| it_behaves_like "is idempotent", 'isfragment => false,', /-A INPUT -p tcp -m comment --comment "597 - test"/ | ||
| end | ||
| end | ||
| describe 'editing a rule' do | ||
| context 'when unset or false' do | ||
| before :each do | ||
| iptables_flush_all_tables | ||
| shell('/sbin/iptables -A INPUT -p tcp -m comment --comment "597 - test"') | ||
| end | ||
| context 'and current value is false' do | ||
| it_behaves_like "doesn't change", 'isfragment => false,', /-A INPUT -p tcp -m comment --comment "597 - test"/ | ||
| end | ||
| context 'and current value is true' do | ||
| it_behaves_like "is idempotent", 'isfragment => true,', /-A INPUT -p tcp -f -m comment --comment "597 - test"/ | ||
| end | ||
| end | ||
| context 'when set to true' do | ||
| before :each do | ||
| iptables_flush_all_tables | ||
| shell('/sbin/iptables -A INPUT -p tcp -f -m comment --comment "597 - test"') | ||
| end | ||
| context 'and current value is false' do | ||
| it_behaves_like "is idempotent", 'isfragment => false,', /-A INPUT -p tcp -m comment --comment "597 - test"/ | ||
| end | ||
| context 'and current value is true' do | ||
| it_behaves_like "doesn't change", 'isfragment => true,', /-A INPUT -p tcp -f -m comment --comment "597 - test"/ | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| HOSTS: | ||
| centos-59-x64: | ||
| roles: | ||
| - master | ||
| platform: el-5-x86_64 | ||
| box : centos-59-x64-vbox4210-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box | ||
| hypervisor : vagrant | ||
| CONFIG: | ||
| type: foss |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| HOSTS: | ||
| centos-64-x64: | ||
| roles: | ||
| - master | ||
| platform: el-6-x86_64 | ||
| box : centos-64-x64-fusion503-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-fusion503-nocm.box | ||
| hypervisor : fusion | ||
| CONFIG: | ||
| type: foss |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| HOSTS: | ||
| centos-64-x64: | ||
| roles: | ||
| - master | ||
| - database | ||
| - dashboard | ||
| platform: el-6-x86_64 | ||
| box : centos-64-x64-vbox4210-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box | ||
| hypervisor : vagrant | ||
| CONFIG: | ||
| type: pe |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| HOSTS: | ||
| centos-64-x64: | ||
| roles: | ||
| - master | ||
| platform: el-6-x86_64 | ||
| box : centos-64-x64-vbox4210-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box | ||
| hypervisor : vagrant | ||
| CONFIG: | ||
| type: foss |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| HOSTS: | ||
| debian-607-x64: | ||
| roles: | ||
| - master | ||
| platform: debian-6-amd64 | ||
| box : debian-607-x64-vbox4210-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-607-x64-vbox4210-nocm.box | ||
| hypervisor : vagrant | ||
| CONFIG: | ||
| type: git |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| HOSTS: | ||
| debian-70rc1-x64: | ||
| roles: | ||
| - master | ||
| platform: debian-7-amd64 | ||
| box : debian-70rc1-x64-vbox4210-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box | ||
| hypervisor : vagrant | ||
| CONFIG: | ||
| type: git |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| centos-64-x64.yml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| HOSTS: | ||
| fedora-18-x64: | ||
| roles: | ||
| - master | ||
| platform: fedora-18-x86_64 | ||
| box : fedora-18-x64-vbox4210-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box | ||
| hypervisor : vagrant | ||
| CONFIG: | ||
| type: git |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| HOSTS: | ||
| sles-11sp1-x64: | ||
| roles: | ||
| - master | ||
| platform: sles-11-x86_64 | ||
| box : sles-11sp1-x64-vbox4210-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/sles-11sp1-x64-vbox4210-nocm.box | ||
| hypervisor : vagrant | ||
| CONFIG: | ||
| type: git |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| HOSTS: | ||
| ubuntu-server-10044-x64: | ||
| roles: | ||
| - master | ||
| platform: ubuntu-10.04-amd64 | ||
| box : ubuntu-server-10044-x64-vbox4210-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box | ||
| hypervisor : vagrant | ||
| CONFIG: | ||
| type: git |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| HOSTS: | ||
| ubuntu-server-12042-x64: | ||
| roles: | ||
| - master | ||
| platform: ubuntu-12.04-amd64 | ||
| box : ubuntu-server-12042-x64-vbox4210-nocm | ||
| box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box | ||
| hypervisor : vagrant | ||
| CONFIG: | ||
| type: foss |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| describe "purge tests:" do | ||
| context('resources purge') do | ||
| before(:all) do | ||
| iptables_flush_all_tables | ||
|
|
||
| shell('/sbin/iptables -A INPUT -s 1.2.1.2') | ||
| shell('/sbin/iptables -A INPUT -s 1.2.1.2') | ||
| end | ||
|
|
||
| it 'make sure duplicate existing rules get purged' do | ||
|
|
||
| pp = <<-EOS | ||
| class { 'firewall': } | ||
| resources { 'firewall': | ||
| purge => true, | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :expect_changes => true) | ||
| end | ||
|
|
||
| it 'saves' do | ||
| shell('/sbin/iptables-save') do |r| | ||
| expect(r.stdout).to_not match(/1\.2\.1\.2/) | ||
| expect(r.stderr).to eq("") | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context('chain purge') do | ||
| before(:each) do | ||
| iptables_flush_all_tables | ||
|
|
||
| shell('/sbin/iptables -A INPUT -p tcp -s 1.2.1.1') | ||
| shell('/sbin/iptables -A INPUT -p udp -s 1.2.1.1') | ||
| shell('/sbin/iptables -A OUTPUT -s 1.2.1.2 -m comment --comment "010 output-1.2.1.2"') | ||
| end | ||
|
|
||
| it 'purges only the specified chain' do | ||
| pp = <<-EOS | ||
| class { 'firewall': } | ||
| firewallchain { 'INPUT:filter:IPv4': | ||
| purge => true, | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :expect_changes => true) | ||
|
|
||
| shell('/sbin/iptables-save') do |r| | ||
| expect(r.stdout).to match(/010 output-1\.2\.1\.2/) | ||
| expect(r.stdout).to_not match(/1\.2\.1\.1/) | ||
| expect(r.stderr).to eq("") | ||
| end | ||
| end | ||
|
|
||
| it 'ignores managed rules' do | ||
| pp = <<-EOS | ||
| class { 'firewall': } | ||
| firewallchain { 'OUTPUT:filter:IPv4': | ||
| purge => true, | ||
| } | ||
| firewall { '010 output-1.2.1.2': | ||
| chain => 'OUTPUT', | ||
| proto => 'all', | ||
| source => '1.2.1.2', | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_changes => true) | ||
| end | ||
|
|
||
| it 'ignores specified rules' do | ||
| pp = <<-EOS | ||
| class { 'firewall': } | ||
| firewallchain { 'INPUT:filter:IPv4': | ||
| purge => true, | ||
| ignore => [ | ||
| '-s 1\.2\.1\.1', | ||
| ], | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_changes => true) | ||
| end | ||
|
|
||
| it 'adds managed rules with ignored rules' do | ||
| pp = <<-EOS | ||
| class { 'firewall': } | ||
| firewallchain { 'INPUT:filter:IPv4': | ||
| purge => true, | ||
| ignore => [ | ||
| '-s 1\.2\.1\.1', | ||
| ], | ||
| } | ||
| firewall { '014 input-1.2.1.6': | ||
| chain => 'INPUT', | ||
| proto => 'all', | ||
| source => '1.2.1.6', | ||
| } | ||
| -> firewall { '013 input-1.2.1.5': | ||
| chain => 'INPUT', | ||
| proto => 'all', | ||
| source => '1.2.1.5', | ||
| } | ||
| -> firewall { '012 input-1.2.1.4': | ||
| chain => 'INPUT', | ||
| proto => 'all', | ||
| source => '1.2.1.4', | ||
| } | ||
| -> firewall { '011 input-1.2.1.3': | ||
| chain => 'INPUT', | ||
| proto => 'all', | ||
| source => '1.2.1.3', | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_failures => true) | ||
|
|
||
| expect(shell('/sbin/iptables-save').stdout).to match(/-A INPUT -s 1\.2\.1\.1\/32 -p tcp \n-A INPUT -s 1\.2\.1\.1\/32 -p udp/) | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| # Here we want to test the the resource commands ability to work with different | ||
| # existing ruleset scenarios. This will give the parsing capabilities of the | ||
| # code a good work out. | ||
| describe 'puppet resource firewall command:' do | ||
| context 'make sure it returns no errors when executed on a clean machine' do | ||
| it do | ||
| shell('puppet resource firewall') do |r| | ||
| r.exit_code.should be_zero | ||
| # don't check stdout, some boxes come with rules, that is normal | ||
| r.stderr.should be_empty | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'flush iptables and make sure it returns nothing afterwards' do | ||
| before(:all) do | ||
| iptables_flush_all_tables | ||
| end | ||
|
|
||
| # No rules, means no output thanks. And no errors as well. | ||
| it do | ||
| shell('puppet resource firewall') do |r| | ||
| r.exit_code.should be_zero | ||
| r.stderr.should be_empty | ||
| r.stdout.should == "\n" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'accepts rules without comments' do | ||
| before(:all) do | ||
| iptables_flush_all_tables | ||
| shell('/sbin/iptables -A INPUT -j ACCEPT -p tcp --dport 80') | ||
| end | ||
|
|
||
| it do | ||
| shell('puppet resource firewall') do |r| | ||
| r.exit_code.should be_zero | ||
| # don't check stdout, testing preexisting rules, output is normal | ||
| r.stderr.should be_empty | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'accepts rules with invalid comments' do | ||
| before(:all) do | ||
| iptables_flush_all_tables | ||
| shell('/sbin/iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m comment --comment "http"') | ||
| end | ||
|
|
||
| it do | ||
| shell('puppet resource firewall') do |r| | ||
| r.exit_code.should be_zero | ||
| # don't check stdout, testing preexisting rules, output is normal | ||
| r.stderr.should be_empty | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'accepts rules with negation' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| shell('/sbin/iptables -t nat -A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p tcp -j MASQUERADE --to-ports 1024-65535') | ||
| shell('/sbin/iptables -t nat -A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p udp -j MASQUERADE --to-ports 1024-65535') | ||
| shell('/sbin/iptables -t nat -A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -j MASQUERADE') | ||
| end | ||
|
|
||
| it do | ||
| shell('puppet resource firewall') do |r| | ||
| r.exit_code.should be_zero | ||
| # don't check stdout, testing preexisting rules, output is normal | ||
| r.stderr.should be_empty | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'accepts rules with match extension tcp flag' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| shell('/sbin/iptables -t mangle -A PREROUTING -d 1.2.3.4 -p tcp -m tcp -m multiport --dports 80,443,8140 -j MARK --set-mark 42') | ||
| end | ||
|
|
||
| it do | ||
| shell('puppet resource firewall') do |r| | ||
| r.exit_code.should be_zero | ||
| # don't check stdout, testing preexisting rules, output is normal | ||
| r.stderr.should be_empty | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,248 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| describe 'complex ruleset 1' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
|
|
||
| after :all do | ||
| shell('iptables -t filter -P INPUT ACCEPT') | ||
| shell('iptables -t filter -P FORWARD ACCEPT') | ||
| shell('iptables -t filter -P OUTPUT ACCEPT') | ||
| shell('iptables -t filter --flush') | ||
| end | ||
|
|
||
| it 'applies cleanly' do | ||
| pp = <<-EOS | ||
| firewall { '090 forward allow local': | ||
| chain => 'FORWARD', | ||
| proto => 'all', | ||
| source => '10.0.0.0/8', | ||
| destination => '10.0.0.0/8', | ||
| action => 'accept', | ||
| } | ||
| firewall { '100 forward standard allow tcp': | ||
| chain => 'FORWARD', | ||
| source => '10.0.0.0/8', | ||
| destination => '!10.0.0.0/8', | ||
| proto => 'tcp', | ||
| state => 'NEW', | ||
| port => [80,443,21,20,22,53,123,43,873,25,465], | ||
| action => 'accept', | ||
| } | ||
| firewall { '100 forward standard allow udp': | ||
| chain => 'FORWARD', | ||
| source => '10.0.0.0/8', | ||
| destination => '!10.0.0.0/8', | ||
| proto => 'udp', | ||
| port => [53,123], | ||
| action => 'accept', | ||
| } | ||
| firewall { '100 forward standard allow icmp': | ||
| chain => 'FORWARD', | ||
| source => '10.0.0.0/8', | ||
| destination => '!10.0.0.0/8', | ||
| proto => 'icmp', | ||
| action => 'accept', | ||
| } | ||
| firewall { '090 ignore ipsec': | ||
| table => 'nat', | ||
| chain => 'POSTROUTING', | ||
| outiface => 'eth0', | ||
| ipsec_policy => 'ipsec', | ||
| ipsec_dir => 'out', | ||
| action => 'accept', | ||
| } | ||
| firewall { '093 ignore 10.0.0.0/8': | ||
| table => 'nat', | ||
| chain => 'POSTROUTING', | ||
| outiface => 'eth0', | ||
| destination => '10.0.0.0/8', | ||
| action => 'accept', | ||
| } | ||
| firewall { '093 ignore 172.16.0.0/12': | ||
| table => 'nat', | ||
| chain => 'POSTROUTING', | ||
| outiface => 'eth0', | ||
| destination => '172.16.0.0/12', | ||
| action => 'accept', | ||
| } | ||
| firewall { '093 ignore 192.168.0.0/16': | ||
| table => 'nat', | ||
| chain => 'POSTROUTING', | ||
| outiface => 'eth0', | ||
| destination => '192.168.0.0/16', | ||
| action => 'accept', | ||
| } | ||
| firewall { '100 masq outbound': | ||
| table => 'nat', | ||
| chain => 'POSTROUTING', | ||
| outiface => 'eth0', | ||
| jump => 'MASQUERADE', | ||
| } | ||
| firewall { '101 redirect port 1': | ||
| table => 'nat', | ||
| chain => 'PREROUTING', | ||
| iniface => 'eth0', | ||
| proto => 'tcp', | ||
| dport => '1', | ||
| toports => '22', | ||
| jump => 'REDIRECT', | ||
| } | ||
| EOS | ||
|
|
||
| # Run it twice and test for idempotency | ||
| apply_manifest(pp, :catch_failures => true) | ||
| expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero | ||
| end | ||
|
|
||
| it 'contains appropriate rules' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to eq( | ||
| "-P INPUT ACCEPT\n" + | ||
| "-P FORWARD ACCEPT\n" + | ||
| "-P OUTPUT ACCEPT\n" + | ||
| "-A FORWARD -s 10.0.0.0/8 -d 10.0.0.0/8 -m comment --comment \"090 forward allow local\" -j ACCEPT \n" + | ||
| "-A FORWARD -s 10.0.0.0/8 ! -d 10.0.0.0/8 -p icmp -m comment --comment \"100 forward standard allow icmp\" -j ACCEPT \n" + | ||
| "-A FORWARD -s 10.0.0.0/8 ! -d 10.0.0.0/8 -p tcp -m multiport --ports 80,443,21,20,22,53,123,43,873,25,465 -m comment --comment \"100 forward standard allow tcp\" -m state --state NEW -j ACCEPT \n" + | ||
| "-A FORWARD -s 10.0.0.0/8 ! -d 10.0.0.0/8 -p udp -m multiport --ports 53,123 -m comment --comment \"100 forward standard allow udp\" -j ACCEPT \n" | ||
| ) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'complex ruleset 2' do | ||
| after :all do | ||
| shell('iptables -t filter -P INPUT ACCEPT') | ||
| shell('iptables -t filter -P FORWARD ACCEPT') | ||
| shell('iptables -t filter -P OUTPUT ACCEPT') | ||
| shell('iptables -t filter --flush') | ||
| expect(shell('iptables -t filter -X LOCAL_INPUT').stderr).to eq("") | ||
| expect(shell('iptables -t filter -X LOCAL_INPUT_PRE').stderr).to eq("") | ||
| end | ||
|
|
||
| it 'applies cleanly' do | ||
| pp = <<-EOS | ||
| class { '::firewall': } | ||
| Firewall { | ||
| proto => 'all', | ||
| stage => 'pre', | ||
| } | ||
| Firewallchain { | ||
| stage => 'pre', | ||
| purge => 'true', | ||
| ignore => [ | ||
| '--comment "[^"]*(?i:ignore)[^"]*"', | ||
| ], | ||
| } | ||
| firewall { '010 INPUT allow established and related': | ||
| proto => 'all', | ||
| state => ['ESTABLISHED', 'RELATED'], | ||
| action => 'accept', | ||
| before => Firewallchain['INPUT:filter:IPv4'], | ||
| } | ||
| firewall { '012 accept loopback': | ||
| iniface => 'lo', | ||
| action => 'accept', | ||
| before => Firewallchain['INPUT:filter:IPv4'], | ||
| } | ||
| firewall { '020 ssh': | ||
| proto => 'tcp', | ||
| dport => '22', | ||
| state => 'NEW', | ||
| action => 'accept', | ||
| before => Firewallchain['INPUT:filter:IPv4'], | ||
| } | ||
| firewall { '013 icmp echo-request': | ||
| proto => 'icmp', | ||
| icmp => 'echo-request', | ||
| action => 'accept', | ||
| source => '10.0.0.0/8', | ||
| } | ||
| firewall { '013 icmp destination-unreachable': | ||
| proto => 'icmp', | ||
| icmp => 'destination-unreachable', | ||
| action => 'accept', | ||
| } | ||
| firewall { '013 icmp time-exceeded': | ||
| proto => 'icmp', | ||
| icmp => 'time-exceeded', | ||
| action => 'accept', | ||
| } | ||
| firewall { '999 reject': | ||
| action => 'reject', | ||
| reject => 'icmp-host-prohibited', | ||
| } | ||
| firewallchain { 'LOCAL_INPUT_PRE:filter:IPv4': } | ||
| firewall { '001 LOCAL_INPUT_PRE': | ||
| jump => 'LOCAL_INPUT_PRE', | ||
| require => Firewallchain['LOCAL_INPUT_PRE:filter:IPv4'], | ||
| } | ||
| firewallchain { 'LOCAL_INPUT:filter:IPv4': } | ||
| firewall { '900 LOCAL_INPUT': | ||
| jump => 'LOCAL_INPUT', | ||
| require => Firewallchain['LOCAL_INPUT:filter:IPv4'], | ||
| } | ||
| firewallchain { 'INPUT:filter:IPv4': | ||
| policy => 'drop', | ||
| ignore => [ | ||
| '-j fail2ban-ssh', | ||
| '--comment "[^"]*(?i:ignore)[^"]*"', | ||
| ], | ||
| } | ||
| firewall { '010 allow established and related': | ||
| chain => 'FORWARD', | ||
| proto => 'all', | ||
| state => ['ESTABLISHED','RELATED'], | ||
| action => 'accept', | ||
| before => Firewallchain['FORWARD:filter:IPv4'], | ||
| } | ||
| firewallchain { 'FORWARD:filter:IPv4': | ||
| policy => 'drop', | ||
| } | ||
| firewallchain { 'OUTPUT:filter:IPv4': } | ||
| # purge unknown rules from mangle table | ||
| firewallchain { ['PREROUTING:mangle:IPv4', 'INPUT:mangle:IPv4', 'FORWARD:mangle:IPv4', 'OUTPUT:mangle:IPv4', 'POSTROUTING:mangle:IPv4']: } | ||
| # and the nat table | ||
| firewallchain { ['PREROUTING:nat:IPv4', 'INPUT:nat:IPv4', 'OUTPUT:nat:IPv4', 'POSTROUTING:nat:IPv4']: } | ||
| EOS | ||
|
|
||
| # Run it twice and test for idempotency | ||
| apply_manifest(pp, :catch_failures => true) | ||
| apply_manifest(pp, :catch_changes => true) | ||
| end | ||
|
|
||
| it 'contains appropriate rules' do | ||
| shell('iptables -S') do |r| | ||
| expect(r.stdout).to eq( | ||
| "-P INPUT DROP\n" + | ||
| "-P FORWARD DROP\n" + | ||
| "-P OUTPUT ACCEPT\n" + | ||
| "-N LOCAL_INPUT\n" + | ||
| "-N LOCAL_INPUT_PRE\n" + | ||
| "-A INPUT -m comment --comment \"001 LOCAL_INPUT_PRE\" -j LOCAL_INPUT_PRE \n" + | ||
| "-A INPUT -m comment --comment \"010 INPUT allow established and related\" -m state --state RELATED,ESTABLISHED -j ACCEPT \n" + | ||
| "-A INPUT -i lo -m comment --comment \"012 accept loopback\" -j ACCEPT \n" + | ||
| "-A INPUT -p icmp -m comment --comment \"013 icmp destination-unreachable\" -m icmp --icmp-type 3 -j ACCEPT \n" + | ||
| "-A INPUT -s 10.0.0.0/8 -p icmp -m comment --comment \"013 icmp echo-request\" -m icmp --icmp-type 8 -j ACCEPT \n" + | ||
| "-A INPUT -p icmp -m comment --comment \"013 icmp time-exceeded\" -m icmp --icmp-type 11 -j ACCEPT \n" + | ||
| "-A INPUT -p tcp -m multiport --dports 22 -m comment --comment \"020 ssh\" -m state --state NEW -j ACCEPT \n" + | ||
| "-A INPUT -m comment --comment \"900 LOCAL_INPUT\" -j LOCAL_INPUT \n" + | ||
| "-A INPUT -m comment --comment \"999 reject\" -j REJECT --reject-with icmp-host-prohibited \n" + | ||
| "-A FORWARD -m comment --comment \"010 allow established and related\" -m state --state RELATED,ESTABLISHED -j ACCEPT \n" | ||
| ) | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| describe 'firewall socket property' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
|
|
||
| shared_examples "is idempotent" do |value, line_match| | ||
| it "changes the value to #{value}" do | ||
| pp = <<-EOS | ||
| class { '::firewall': } | ||
| firewall { '598 - test': | ||
| ensure => present, | ||
| proto => 'tcp', | ||
| chain => 'PREROUTING', | ||
| table => 'raw', | ||
| #{value} | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_failures => true) | ||
| apply_manifest(pp, :catch_changes => true) | ||
|
|
||
| shell('iptables -t raw -S') do |r| | ||
| expect(r.stdout).to match(/#{line_match}/) | ||
| end | ||
| end | ||
| end | ||
| shared_examples "doesn't change" do |value, line_match| | ||
| it "doesn't change the value to #{value}" do | ||
| pp = <<-EOS | ||
| class { '::firewall': } | ||
| firewall { '598 - test': | ||
| ensure => present, | ||
| proto => 'tcp', | ||
| chain => 'PREROUTING', | ||
| table => 'raw', | ||
| #{value} | ||
| } | ||
| EOS | ||
|
|
||
| apply_manifest(pp, :catch_changes => true) | ||
|
|
||
| shell('iptables -t raw -S') do |r| | ||
| expect(r.stdout).to match(/#{line_match}/) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'adding a rule' do | ||
| context 'when unset' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
| it_behaves_like 'is idempotent', '', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ | ||
| end | ||
| context 'when set to true' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
| it_behaves_like 'is idempotent', 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/ | ||
| end | ||
| context 'when set to false' do | ||
| before :all do | ||
| iptables_flush_all_tables | ||
| end | ||
| it_behaves_like "is idempotent", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ | ||
| end | ||
| end | ||
| describe 'editing a rule' do | ||
| context 'when unset or false' do | ||
| before :each do | ||
| iptables_flush_all_tables | ||
| shell('/sbin/iptables -t raw -A PREROUTING -p tcp -m comment --comment "598 - test"') | ||
| end | ||
| context 'and current value is false' do | ||
| it_behaves_like "doesn't change", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ | ||
| end | ||
| context 'and current value is true' do | ||
| it_behaves_like "is idempotent", 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/ | ||
| end | ||
| end | ||
| context 'when set to true' do | ||
| before :each do | ||
| iptables_flush_all_tables | ||
| shell('/sbin/iptables -t raw -A PREROUTING -p tcp -m socket -m comment --comment "598 - test"') | ||
| end | ||
| context 'and current value is false' do | ||
| it_behaves_like "is idempotent", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/ | ||
| end | ||
| context 'and current value is true' do | ||
| it_behaves_like "doesn't change", 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/ | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # These hashes allow us to iterate across a series of test data | ||
| # creating rspec examples for each parameter to ensure the input :line | ||
| # extrapolates to the desired value for the parameter in question. And | ||
| # vice-versa | ||
|
|
||
| # This hash is for testing a line conversion to a hash of parameters | ||
| # which will be used to create a resource. | ||
| ARGS_TO_HASH6 = { | ||
| 'source_destination_ipv6_no_cidr' => { | ||
| :line => '-A INPUT -s 2001:db8:85a3::8a2e:370:7334 -d 2001:db8:85a3::8a2e:370:7334 -m comment --comment "000 source destination ipv6 no cidr"', | ||
| :table => 'filter', | ||
| :provider => 'ip6tables', | ||
| :params => { | ||
| :source => '2001:db8:85a3::8a2e:370:7334/128', | ||
| :destination => '2001:db8:85a3::8a2e:370:7334/128', | ||
| }, | ||
| }, | ||
| 'source_destination_ipv6_netmask' => { | ||
| :line => '-A INPUT -s 2001:db8:1234::/ffff:ffff:ffff:0000:0000:0000:0000:0000 -d 2001:db8:4321::/ffff:ffff:ffff:0000:0000:0000:0000:0000 -m comment --comment "000 source destination ipv6 netmask"', | ||
| :table => 'filter', | ||
| :provider => 'ip6tables', | ||
| :params => { | ||
| :source => '2001:db8:1234::/48', | ||
| :destination => '2001:db8:4321::/48', | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| # This hash is for testing converting a hash to an argument line. | ||
| HASH_TO_ARGS6 = { | ||
| 'zero_prefixlen_ipv6' => { | ||
| :params => { | ||
| :name => '100 zero prefix length ipv6', | ||
| :table => 'filter', | ||
| :provider => 'ip6tables', | ||
| :source => '::/0', | ||
| :destination => '::/0', | ||
| }, | ||
| :args => ['-t', :filter, '-p', :tcp, '-m', 'comment', '--comment', '100 zero prefix length ipv6'], | ||
| }, | ||
| 'source_destination_ipv4_no_cidr' => { | ||
| :params => { | ||
| :name => '000 source destination ipv4 no cidr', | ||
| :table => 'filter', | ||
| :provider => 'ip6tables', | ||
| :source => '1.1.1.1', | ||
| :destination => '2.2.2.2', | ||
| }, | ||
| :args => ['-t', :filter, '-s', '1.1.1.1/32', '-d', '2.2.2.2/32', '-p', :tcp, '-m', 'comment', '--comment', '000 source destination ipv4 no cidr'], | ||
| }, | ||
| 'source_destination_ipv6_no_cidr' => { | ||
| :params => { | ||
| :name => '000 source destination ipv6 no cidr', | ||
| :table => 'filter', | ||
| :provider => 'ip6tables', | ||
| :source => '2001:db8:1234::', | ||
| :destination => '2001:db8:4321::', | ||
| }, | ||
| :args => ['-t', :filter, '-s', '2001:db8:1234::/128', '-d', '2001:db8:4321::/128', '-p', :tcp, '-m', 'comment', '--comment', '000 source destination ipv6 no cidr'], | ||
| }, | ||
| 'source_destination_ipv6_netmask' => { | ||
| :params => { | ||
| :name => '000 source destination ipv6 netmask', | ||
| :table => 'filter', | ||
| :provider => 'ip6tables', | ||
| :source => '2001:db8:1234::/ffff:ffff:ffff:0000:0000:0000:0000:0000', | ||
| :destination => '2001:db8:4321::/ffff:ffff:ffff:0000:0000:0000:0000:0000', | ||
| }, | ||
| :args => ['-t', :filter, '-s', '2001:db8:1234::/48', '-d', '2001:db8:4321::/48', '-p', :tcp, '-m', 'comment', '--comment', '000 source destination ipv6 netmask'], | ||
| }, | ||
| 'frag_ishasmorefrags' => { | ||
| :params => { | ||
| :name => "100 has more fragments", | ||
| :ishasmorefrags => true, | ||
| :provider => 'ip6tables', | ||
| :table => "filter", | ||
| }, | ||
| :args => ["-t", :filter, "-p", :tcp, "-m", "frag", "--fragid", "0", "--fragmore", "-m", "comment", "--comment", "100 has more fragments"], | ||
| }, | ||
| 'frag_islastfrag' => { | ||
| :params => { | ||
| :name => "100 last fragment", | ||
| :islastfrag => true, | ||
| :provider => 'ip6tables', | ||
| :table => "filter", | ||
| }, | ||
| :args => ["-t", :filter, "-p", :tcp, "-m", "frag", "--fragid", "0", "--fraglast", "-m", "comment", "--comment", "100 last fragment"], | ||
| }, | ||
| 'frag_isfirstfrags' => { | ||
| :params => { | ||
| :name => "100 first fragment", | ||
| :isfirstfrag => true, | ||
| :provider => 'ip6tables', | ||
| :table => "filter", | ||
| }, | ||
| :args => ["-t", :filter, "-p", :tcp, "-m", "frag", "--fragid", "0", "--fragfirst", "-m", "comment", "--comment", "100 first fragment"], | ||
| }, | ||
| 'hop_limit' => { | ||
| :params => { | ||
| :name => "100 hop limit", | ||
| :hop_limit => 255, | ||
| :provider => 'ip6tables', | ||
| :table => "filter", | ||
| }, | ||
| :args => ["-t", :filter, "-p", :tcp, "-m", "comment", "--comment", "100 hop limit", "-m", "hl", "--hl-eq", 255], | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| require 'beaker-rspec' | ||
|
|
||
| def iptables_flush_all_tables | ||
| ['filter', 'nat', 'mangle', 'raw'].each do |t| | ||
| expect(shell("/sbin/iptables -t #{t} -F").stderr).to eq("") | ||
| end | ||
| end | ||
|
|
||
| def ip6tables_flush_all_tables | ||
| ['filter'].each do |t| | ||
| expect(shell("/sbin/ip6tables -t #{t} -F").stderr).to eq("") | ||
| end | ||
| end | ||
|
|
||
| hosts.each do |host| | ||
| # Install Puppet | ||
| install_package host, 'rubygems' | ||
| on host, 'gem install puppet --no-ri --no-rdoc' | ||
| on host, "mkdir -p #{host['distmoduledir']}" | ||
| end | ||
|
|
||
| RSpec.configure do |c| | ||
| # Project root | ||
| proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) | ||
|
|
||
| # Readable test descriptions | ||
| c.formatter = :documentation | ||
|
|
||
| # Configure all nodes in nodeset | ||
| c.before :suite do | ||
| # Install module and dependencies | ||
| puppet_module_install(:source => proj_root, :module_name => 'firewall') | ||
| hosts.each do |host| | ||
| shell('/bin/touch /etc/puppet/hiera.yaml') | ||
| shell('puppet module install puppetlabs-stdlib --version 3.2.0', { :acceptable_exit_codes => [0,1] }) | ||
| end | ||
| end | ||
| end |