# Inspec test for recipe irrigate-php::deploy_qa_user

# The Inspec reference, with examples and extensive documentation, can be
# found at http://inspec.io/docs/reference/resources/

control 'deploy_user' do
  # For using node attributes in tests
  attribute_file = '/tmp/kitchen/node_attributes.json'
  if file(attribute_file).exist?
    node = json(attribute_file).params

    describe user node['default']['php']['deploy_user'] do
      it { should exist }
      its('uid') { should eq 1001 }
      its('home') { should eq node['default']['php']['deploy_home_dir'] }
      its('shell') { should eq '/bin/bash' }
    end

    describe group 'webdev' do
      it { should exist }
      its('gid') { should eq 1099 }
    end

    %w(apache deploy).each do |user_name|
      describe user user_name do
        its('groups') { should include 'webdev' }
      end
    end

    user_home = node['default']['php']['deploy_home_dir']
    describe file "#{user_home}/.ssh/authorized_keys" do
      it { should exist }
      its('content') { should include node['default']['php']['prod_deploy_user_pub_key'] }
    end

  else
    puts "File #{attribute_file} does not exist, skiping attribute-depending checks"
  end
end
