require_relative 'spec_helper'

describe 'pentester::cobaltstrike' do
  let(:subject) do
    ChefSpec::SoloRunner.new.converge(described_recipe)
  end

  it 'does not create template[/root/.aggressor.prop]' do
    expect(subject).to_not create_template('/root/.aggressor.prop')
  end

  context 'with properties' do
    let(:subject) do
      ChefSpec::SoloRunner.new do |node|
        node.override['pentester']['cobaltstrike']['props'] = {
          'connection.profiles' => '127.0.0.1',
          'connection.profiles.127.0.0.1.port' => '1337',
          'connection.profiles.127.0.0.1.user' => 'Pentester',
        }
      end.converge(described_recipe)
    end

    it 'creates template[/root/.aggressor.prop]' do
      props_file = '/root/.aggressor.prop'
      expect(subject).to create_template(props_file)
        .with(owner: 'root', group: 'root', mode: '0600', source: 'armitage.prop.erb')

      [/^connection.profiles=127.0.0.1$/,
       /^connection.profiles.127.0.0.1.port=1337$/,
       /^connection.profiles.127.0.0.1.user=Pentester$/].each do |m|
        expect(subject).to render_file(props_file).with_content(m)
      end
    end
  end
end
