require 'metasploit/exploit_run_description'

file_path = 'config/exploit.yml'
describe 'exploit_user_config_file_tests' do
  if File.file?('config/exploit.yml')
    File.rename('config/exploit.yml','config/exploit.yml.bak')
  end

  describe 'start' do
    before(:each) do
      config_file = File.new(file_path, 'w')
      config_file.puts("connection_url: 'mydomain.wat'")
      config_file.close
      @exploit_run_description = ExploitRunDescription.new({})
    end

    after(:each) do
      File.delete(file_path) if File.exist?(file_path)
    end

    it 'should get configuration from the config/exploit.yaml when provided' do
      expect(@exploit_run_description.connection_url).to eq('mydomain.wat')
    end
  end

  if File.file?('config/exploit.yml.bak')
    File.rename('config/exploit.yml.bak', 'config/exploit.yml')
  end

end

describe 'exploit_default_config_tests' do
  if File.file?('config/exploit.yml')
    File.rename('config/exploit.yml', 'config/exploit.yml.bak')
  end

  describe 'start' do
    before(:each) do
      @options = {
        'connection_url' => 'foo.bar'
      }
      @exploit_run_description = ExploitRunDescription.new(@options)
    end

    it 'should get configuration from the command line options' do
      expect(@exploit_run_description.connection_url).to eq('foo.bar')
    end
  end

  if File.file?('config/exploit.yml.bak')
    File.rename('config/exploit.yml.bak', 'config/exploit.yml')
  end

end
