PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/test/cookbooks/iptables_ng_test/files/default/tests/minitest/recipe_install_test.rb

https://github.com/sewer2/cb-iptables-ng
Ruby | 111 lines | 84 code | 25 blank | 2 comment | 5 complexity | 23d441275669c77e7ad2544f869b40e0 MD5 | raw file
  1. require File.expand_path('../support/helpers', __FILE__)
  2. describe 'iptables-ng::install' do
  3. include Helpers::TestHelpers
  4. it 'should set all default policies to ACCEPT' do
  5. file('/etc/iptables.d/filter/INPUT/default').must_include('ACCEPT [0:0]')
  6. file('/etc/iptables.d/filter/OUTPUT/default').must_include('ACCEPT [0:0]')
  7. file('/etc/iptables.d/filter/FORWARD/default').must_include('ACCEPT [0:0]')
  8. file('/etc/iptables.d/nat/OUTPUT/default').must_include('ACCEPT [0:0]')
  9. file('/etc/iptables.d/nat/PREROUTING/default').must_include('ACCEPT [0:0]')
  10. file('/etc/iptables.d/nat/POSTROUTING/default').must_include('ACCEPT [0:0]')
  11. file('/etc/iptables.d/mangle/INPUT/default').must_include('ACCEPT [0:0]')
  12. file('/etc/iptables.d/mangle/OUTPUT/default').must_include('ACCEPT [0:0]')
  13. file('/etc/iptables.d/mangle/FORWARD/default').must_include('ACCEPT [0:0]')
  14. file('/etc/iptables.d/mangle/PREROUTING/default').must_include('ACCEPT [0:0]')
  15. file('/etc/iptables.d/mangle/POSTROUTING/default').must_include('ACCEPT [0:0]')
  16. file('/etc/iptables.d/raw/OUTPUT/default').must_include('ACCEPT [0:0]')
  17. file('/etc/iptables.d/raw/PREROUTING/default').must_include('ACCEPT [0:0]')
  18. end
  19. it 'should not apply other iptables rules' do
  20. ipv4 = shell_out('iptables -L -n |wc -l')
  21. ipv4.stdout.must_include('8')
  22. # RHEL uses a kernel <= 2.6.35, which doesn't have the INPUT chain in nat table
  23. ipv4 = shell_out('iptables -L -n -t nat |wc -l')
  24. if node['platform_family'] == 'rhel'
  25. ipv4.stdout.must_include('8')
  26. else
  27. ipv4.stdout.must_include('11')
  28. end
  29. ipv4 = shell_out('iptables -L -n -t mangle |wc -l')
  30. ipv4.stdout.must_include('14')
  31. ipv4 = shell_out('iptables -L -n -t raw |wc -l')
  32. ipv4.stdout.must_include('5')
  33. end
  34. it 'should not apply other ip6tables rules' do
  35. ipv6 = shell_out('ip6tables -L -n |wc -l')
  36. ipv6.stdout.must_include('8')
  37. ipv6 = shell_out('ip6tables -L -n -t mangle |wc -l')
  38. ipv6.stdout.must_include('14')
  39. ipv6 = shell_out('ip6tables -L -n -t raw |wc -l')
  40. ipv6.stdout.must_include('5')
  41. end
  42. it 'should apply default policies in filter table' do
  43. ipv4 = shell_out('iptables -L -n')
  44. ipv4.stdout.must_include('Chain INPUT (policy ACCEPT)')
  45. ipv4.stdout.must_include('Chain OUTPUT (policy ACCEPT)')
  46. ipv4.stdout.must_include('Chain FORWARD (policy ACCEPT)')
  47. ipv6 = shell_out('ip6tables -L -n')
  48. ipv6.stdout.must_include('Chain INPUT (policy ACCEPT)')
  49. ipv6.stdout.must_include('Chain OUTPUT (policy ACCEPT)')
  50. ipv6.stdout.must_include('Chain FORWARD (policy ACCEPT)')
  51. end
  52. it 'should apply default policies in nat table' do
  53. ipv4 = shell_out('iptables -L -n -t nat')
  54. # RHEL uses a kernel <= 2.6.35, which doesn't have the INPUT chain in nat table
  55. ipv4.stdout.must_include('Chain INPUT (policy ACCEPT)') unless node['platform_family'] == 'rhel'
  56. ipv4.stdout.must_include('Chain OUTPUT (policy ACCEPT)')
  57. ipv4.stdout.must_include('Chain PREROUTING (policy ACCEPT)')
  58. ipv4.stdout.must_include('Chain POSTROUTING (policy ACCEPT)')
  59. end
  60. it 'should apply default policies in mangle table' do
  61. ipv4 = shell_out('iptables -L -n -t mangle')
  62. ipv4.stdout.must_include('Chain INPUT (policy ACCEPT)')
  63. ipv4.stdout.must_include('Chain OUTPUT (policy ACCEPT)')
  64. ipv4.stdout.must_include('Chain FORWARD (policy ACCEPT)')
  65. ipv4.stdout.must_include('Chain PREROUTING (policy ACCEPT)')
  66. ipv4.stdout.must_include('Chain POSTROUTING (policy ACCEPT)')
  67. ipv6 = shell_out('ip6tables -L -n -t mangle')
  68. ipv6.stdout.must_include('Chain INPUT (policy ACCEPT)')
  69. ipv6.stdout.must_include('Chain OUTPUT (policy ACCEPT)')
  70. ipv6.stdout.must_include('Chain FORWARD (policy ACCEPT)')
  71. ipv6.stdout.must_include('Chain PREROUTING (policy ACCEPT)')
  72. ipv6.stdout.must_include('Chain POSTROUTING (policy ACCEPT)')
  73. end
  74. it 'should apply default policies in raw table' do
  75. ipv4 = shell_out('iptables -L -n -t raw')
  76. ipv4.stdout.must_include('Chain OUTPUT (policy ACCEPT)')
  77. ipv4.stdout.must_include('Chain PREROUTING (policy ACCEPT)')
  78. ipv6 = shell_out('ip6tables -L -n -t raw')
  79. ipv6.stdout.must_include('Chain OUTPUT (policy ACCEPT)')
  80. ipv6.stdout.must_include('Chain PREROUTING (policy ACCEPT)')
  81. end
  82. it 'should enable iptables serices' do
  83. service(node['iptables-ng']['service_ipv4']).must_be_enabled if node['iptables-ng']['service_ipv4']
  84. service(node['iptables-ng']['service_ipv6']).must_be_enabled if node['iptables-ng']['service_ipv6']
  85. end
  86. end