init_spec.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. require 'spec_helper'
  2. describe 'sshd' do
  3. shared_examples "a Linux OS" do
  4. it { should compile.with_all_deps }
  5. it { should contain_class('sshd') }
  6. it { should contain_class('sshd::client') }
  7. it { should contain_service('sshd').with({
  8. :ensure => 'running',
  9. :enable => true,
  10. :hasstatus => true
  11. })}
  12. it { should contain_file('sshd_config').with(
  13. {
  14. 'ensure' => 'present',
  15. 'owner' => 'root',
  16. 'group' => '0',
  17. 'mode' => '0600',
  18. }
  19. )}
  20. context 'change ssh port' do
  21. let(:params){{
  22. :ports => [ 22222],
  23. }}
  24. it { should contain_file(
  25. 'sshd_config'
  26. ).with_content(/Port 22222/)}
  27. end
  28. end
  29. context "Debian OS" do
  30. let :facts do
  31. {
  32. :operatingsystem => 'Debian',
  33. :osfamily => 'Debian',
  34. :lsbdistcodename => 'wheezy',
  35. }
  36. end
  37. it_behaves_like "a Linux OS"
  38. it { should contain_package('openssh') }
  39. it { should contain_class('sshd::debian') }
  40. it { should contain_service('sshd').with(
  41. :hasrestart => true
  42. )}
  43. context "Ubuntu" do
  44. let :facts do
  45. {
  46. :operatingsystem => 'Ubuntu',
  47. :lsbdistcodename => 'precise',
  48. }
  49. end
  50. it_behaves_like "a Linux OS"
  51. it { should contain_package('openssh') }
  52. it { should contain_service('sshd').with({
  53. :hasrestart => true
  54. })}
  55. end
  56. end
  57. # context "RedHat OS" do
  58. # it_behaves_like "a Linux OS" do
  59. # let :facts do
  60. # {
  61. # :operatingsystem => 'RedHat',
  62. # :osfamily => 'RedHat',
  63. # }
  64. # end
  65. # end
  66. # end
  67. context "CentOS" do
  68. it_behaves_like "a Linux OS" do
  69. let :facts do
  70. {
  71. :operatingsystem => 'CentOS',
  72. :osfamily => 'RedHat',
  73. :lsbdistcodename => 'Final',
  74. }
  75. end
  76. end
  77. end
  78. context "Gentoo" do
  79. let :facts do
  80. {
  81. :operatingsystem => 'Gentoo',
  82. :osfamily => 'Gentoo',
  83. }
  84. end
  85. it_behaves_like "a Linux OS"
  86. it { should contain_class('sshd::gentoo') }
  87. end
  88. context "OpenBSD" do
  89. let :facts do
  90. {
  91. :operatingsystem => 'OpenBSD',
  92. :osfamily => 'OpenBSD',
  93. }
  94. end
  95. it_behaves_like "a Linux OS"
  96. it { should contain_class('sshd::openbsd') }
  97. end
  98. # context "FreeBSD" do
  99. # it_behaves_like "a Linux OS" do
  100. # let :facts do
  101. # {
  102. # :operatingsystem => 'FreeBSD',
  103. # :osfamily => 'FreeBSD',
  104. # }
  105. # end
  106. # end
  107. # end
  108. end