<commit_before>require 'spec_helper'

describe 'et_upload::default' do
  let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }

  before do
    stub_command('test -d /opt/evertrue/upload').and_return(0)
  end

  # it 'includes openssh::default' do
  #   expect(chef_run).to include_recipe('openssh::default')
  # end
end<commit_msg>Add ChefSpec tests for et_upload::users<commit_after>require 'spec_helper'

describe 'et_upload::default' do
  let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }

  users = {
    'upload' => {
      'id' => 'upload',
      'penncharter4616' => {
        'uid'      => 10_042,
        'ssh_keys'     => 'ssh-key-1',
        'comment'  => 'Test User 1',
        'password' => 'password'
      },
      'randolphschool6139' => {
        'uid'      => 10_041,
        'ssh_keys'     => 'ssh-key-2',
        'comment'  => 'Test User 2',
        'password' => 'password'
      }
    }
  }

  before do
    stub_command('test -d /opt/evertrue/upload').and_return(0)

    ChefSpec::Server.create_data_bag('users', users)
  end

  users['upload'].each do |uname, u|
    if uname != 'id'
      u['home'] = "/home/#{uname}"
      u['gid']  = 'uploadonly'

      it "creates user #{uname}" do
        expect(chef_run).to create_user(uname).with(
          uid:      u['uid'],
          gid:      u['gid'],
          comment:  u['comment'],
          password: u['password'],
          home:     u['home']
        )
      end

      it "sets #{uname} home folder mode and ownership" do
        expect(chef_run).to create_directory(u['home']).with(
          user:  'root',
          group: u['gid'],
          mode:  '0755'
        )
      end

      ["#{u['home']}/.ssh", "#{u['home']}/uploads"].each do |dir|
        it "creates #{dir}" do
          expect(chef_run).to create_directory(dir).with(
            user:  uname,
            group: u['gid'],
            mode:  '0700'
          )
        end
      end

      it "creates #{uname}'s authorized_keys" do
        auth_keys_path = "#{u['home']}/.ssh/authorized_keys"

        expect(chef_run).to create_template(auth_keys_path).with(
          user:  uname,
          group: u['gid'],
          mode:  '0600'
        )
        expect(chef_run).to render_file(auth_keys_path).with_content(u['keys'])
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1607372481783112, 'fraction_numerical': 0.015430775825117874, 'mean_word_length': 2.16260162601626, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5186642', 'n_tokens_mistral': 848, 'n_tokens_neox': 799, 'n_words': 151}