freeipa_spec.rb 8.16 KB
Newer Older
Scott Barthelemy's avatar
Scott Barthelemy committed
1 2
require 'spec_helper_acceptance'

3
describe 'freeipa class' do
4 5 6 7 8 9
  context 'with ipa_role master' do
    hosts_as('master').each do |master|
      it 'applies idempotently' do
        pp = <<-EOS
        class { 'freeipa':
          ipa_role => 'master',
10 11
          domain => 'example.lan',
          ipa_server_fqdn => 'ipa-server-1.example.lan',
12
          puppet_admin_password => 'vagrant123',
13
          directory_services_password => 'vagrant123',
14
	  humanadmins => { foo => { password => 'vagrant123', ensure => 'present'}, bar => { password => 'vagrant123', ensure => 'present'} },
15
          install_ipa_server => true,
16
          ip_address => '10.10.10.35',
17 18
          enable_ip_address => true,
          enable_hostname => true,
19
	  enable_manage_admins => false,
20 21 22 23 24
          manage_host_entry => true,
          install_epel => true,
          webui_disable_kerberos => true,
          webui_enable_proxy => true,
          webui_force_https => true,
25
          ipa_master_fqdn => 'ipa-server-1.example.lan',
26 27 28 29 30 31 32 33 34
        }
        EOS

        apply_manifest_on(master, pp, catch_failures: true)
        apply_manifest_on(master, pp, catch_changes: true)
      end

      describe command('ipactl status') do
        its(:exit_status) { is_expected.to be 0 }
Scott Barthelemy's avatar
Scott Barthelemy committed
35 36
      end
    end
37
  end
38

39 40 41 42 43 44
  context 'with ipa_role replica' do
    hosts_as('replica').each do |replica|
      it 'applies idempotently' do
        pp = <<-EOS
        class {'freeipa':
         ipa_role => 'replica',
45 46
         domain => 'example.lan',
         ipa_server_fqdn => 'ipa-server-2.example.lan',
47
         puppet_admin_password => 'vagrant123',
48 49 50
         directory_services_password => 'vagrant123',
         password_usedto_joindomain => 'vagrant123',
         install_ipa_server => true,
51
         ip_address => '10.10.10.36',
52 53 54 55
         enable_ip_address => true,
         enable_hostname => true,
         manage_host_entry => true,
         install_epel => true,
56
         ipa_master_fqdn => 'ipa-server-1.example.lan'
57 58 59 60 61 62 63 64 65 66
        }
        EOS

        apply_manifest_on(replica, pp, catch_failures: true)
        apply_manifest_on(replica, pp, catch_changes: true)
      end

      it 'ipactl status on replica' do
        result = on(replica, 'ipactl status')
        result.exit_code.should == 0
67 68
      end
    end
69
  end
70

71 72 73 74 75 76
  context 'with ipa_role client' do
    hosts_as('client').each do |client|
      it 'applies idempotently' do
        pp = <<-EOS
        class {'freeipa':
         ipa_role => 'client',
77
         domain => 'example.lan',
78
         puppet_admin_password => 'vagrant123',
79 80
         directory_services_password => 'vagrant123',
         password_usedto_joindomain => 'vagrant123',
81
         ip_address => '10.10.10.37',
82
         install_epel => true,
83
         ipa_master_fqdn => 'ipa-server-1.example.lan'
84 85 86 87 88
        }
        EOS

        apply_manifest_on(client, pp, catch_failures: true)
        apply_manifest_on(client, pp, catch_changes: true)
89 90
      end
    end
91 92
  end

93 94 95 96 97 98 99 100
  context 'with ipa_role replica on master' do
    hosts_as('master').each do |master|
      it 'fails' do
        pp = <<-EOS
        class { 'freeipa':
          ipa_role => 'replica',
          domain => 'example.lan',
          ipa_server_fqdn => 'ipa-server-1.example.lan',
101
          puppet_admin_password => 'vagrant123',
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
          directory_services_password => 'vagrant123',
          install_ipa_server => true,
          ip_address => '10.10.10.35',
          enable_ip_address => true,
          enable_hostname => true,
          manage_host_entry => true,
          install_epel => true,
          webui_disable_kerberos => true,
          webui_enable_proxy => true,
          webui_force_https => true,
          ipa_master_fqdn => 'ipa-server-1.example.lan',
        }
        EOS

        apply_manifest_on(master, pp, expect_failures: true)
      end
    end
  end

  context 'with ipa_role client on master' do
    hosts_as('master').each do |master|
      it 'fails' do
        pp = <<-EOS
        class { 'freeipa':
          ipa_role => 'client',
          domain => 'example.lan',
128
          puppet_admin_password => 'vagrant123',
129 130 131 132 133 134 135 136 137 138 139 140 141
          directory_services_password => 'vagrant123',
          password_usedto_joindomain => 'vagrant123',
          ip_address => '10.10.10.35',
          install_epel => true,
          ipa_master_fqdn => 'ipa-server-1.example.lan'
        }
        EOS

        apply_manifest_on(master, pp, expect_failures: true)
      end
    end
  end

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
  context 'Test ssh connnections for toto user with pre-defined ssh-key' do
    # Install ssh key on root on master
    hosts_as('master').each do |master|
      it 'doest a kinit' do
        on(master, "echo 'vagrant123' | kinit admin")
      end

      it 'creates user toto in freeipa' do
        on(master, "echo 'vagrant123' | ipa user-add toto --first=John --last=Smith --password")
      end

      it 'creates ssh key' do
        on(master, "ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa")
      end

      it 'adds the public key in freeipa to toto' do
        on(master, 'key=`cat /root/.ssh/id_rsa.pub`; ipa user-mod toto --sshpubkey="$key"')
      end

      # Add HBAC Rule to give all ipa users access to ipa-client-centos
      it 'creates a HBAC rule for all users' do
        on(master, 'ipa hbacrule-add --usercat=all --servicecat=all allGroup')
      end

      it 'adds centos client to allGroup rule' do
        on(master, 'ipa hbacrule-add-host --hosts=ipa-client-centos allGroup')
      end

      # Remove allow_all HBAC
      it 'deletes the allow_all default rule' do
        on(master, 'ipa hbacrule-del allow_all')
      end

      it 'test ssh on allowed host with returns' do
        pp = <<-EOS
          exec { 'test ssh':
          path     => '/bin/',
179
          command  => 'ssh -o "StrictHostKeyChecking no" toto@10.10.10.37 id',
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
          returns  => "0"
          }
          EOS

        apply_manifest_on(master, pp, catch_failures: true)
      end

      it 'test ssh on not allowed host with returns' do
        pp = <<-EOS
          exec { 'test ssh':
          path     => '/bin/',
          command  => 'ssh -o "StrictHostKeyChecking no" toto@localhost id',
          returns  => "255"
          }
          EOS
195

196
        apply_manifest_on(master, pp, catch_failures: true)
197 198
      end
    end
Scott Barthelemy's avatar
Scott Barthelemy committed
199
  end
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

  context 'Test creation of admin accounts' do
    hosts_as('master').each do |master|
      it 'updates admin password' do
        pp = <<-EOS
        class { 'freeipa':
          ipa_role => 'master',
          domain => 'example.lan',
          ipa_server_fqdn => 'ipa-server-1.example.lan',
          puppet_admin_password => 'vagrant123',
          directory_services_password => 'vagrant123',
	  humanadmins => { foo => { password => 'vagrant123', ensure => 'present'}, bar => { password => 'vagrant123'} },
          install_ipa_server => true,
          ip_address => '10.10.10.35',
          enable_ip_address => true,
          enable_hostname => true,
          manage_host_entry => true,
          install_epel => true,
          webui_disable_kerberos => true,
          webui_enable_proxy => true,
          webui_force_https => true,
          ipa_master_fqdn => 'ipa-server-1.example.lan',
        }
        EOS

        apply_manifest_on(master, pp, catch_failures: true)
      end
    end
  end

  context 'Test update and delete on admin accounts' do
    hosts_as('master').each do |master|
      it 'updates admin password' do
        pp = <<-EOS
        class { 'freeipa':
          ipa_role => 'master',
          domain => 'example.lan',
          ipa_server_fqdn => 'ipa-server-1.example.lan',
          puppet_admin_password => 'vagrant123',
          directory_services_password => 'vagrant123',
	  humanadmins => { foo => { password => 'beaker456', ensure => 'present'}, bar => { password => 'vagrant123', ensure => 'absent'} },
          install_ipa_server => true,
          ip_address => '10.10.10.35',
          enable_ip_address => true,
          enable_hostname => true,
          manage_host_entry => true,
          install_epel => true,
          webui_disable_kerberos => true,
          webui_enable_proxy => true,
          webui_force_https => true,
          ipa_master_fqdn => 'ipa-server-1.example.lan',
        }
        EOS

        apply_manifest_on(master, pp, catch_failures: true)
      end
    end
  end
Scott Barthelemy's avatar
Scott Barthelemy committed
258
end