Path: blob/master/spec/app/finders/config_backups/known_filenames_spec.rb
1483 views
# frozen_string_literal: true12describe WPScan::Finders::ConfigBackups::KnownFilenames do3subject(:finder) { described_class.new(target) }4let(:target) { WPScan::Target.new(url) }5let(:url) { 'http://ex.lo/' }6let(:fixtures) { FINDERS_FIXTURES.join('config_backups') }7let(:opts) { { list: WPScan::DB_DIR.join('config_backups.txt').to_s } }89describe '#aggressive' do10before do11expect(target).to receive(:sub_dir).at_least(1).and_return(false)12expect(target).to receive(:head_or_get_params).and_return(method: :head)1314finder.potential_urls(opts).each_key do |url|15stub_request(:head, url).to_return(status: 404)16end17end1819context 'when all files are 404s' do20it 'returns an empty array' do21expect(finder.aggressive(opts)).to eql []22end23end2425context 'when some files exist' do26let(:found_files) { ['%23wp-config.php%23', 'wp-config.bak'] }27let(:config_backup) { File.read(fixtures.join('wp-config.php')) }2829before do30found_files.each do |file|31stub_request(:head, "#{url}#{file}").to_return(status: 200)32stub_request(:get, "#{url}#{file}").to_return(status: 200, body: config_backup)33end3435expect(target).to receive(:homepage_or_404?).twice.and_return(false)36end3738it 'returns the expected Array<ConfigBackup>' do39expected = []4041found_files.each do |file|42url = "#{target.url}#{file}"4344expected << WPScan::Model::ConfigBackup.new(45url,46confidence: 100,47found_by: described_class::DIRECT_ACCESS48)49end5051expect(finder.aggressive(opts)).to eql expected52end53end54end55end565758