Path: blob/master/spec/app/finders/interesting_findings/backup_db_spec.rb
1483 views
# frozen_string_literal: true12describe WPScan::Finders::InterestingFindings::BackupDB do3subject(:finder) { described_class.new(target) }4let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }5let(:url) { 'http://ex.lo/' }6let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'backup_db') }7let(:wp_content) { 'wp-content' }8let(:dir_url) { target.url("#{wp_content}/backup-db/") }910before do11expect(target).to receive(:content_dir).at_least(1).and_return(wp_content)12expect(target).to receive(:head_or_get_params).and_return(method: :head)13end1415describe '#aggressive' do16context 'when not a 200 or 403' do17it 'returns nil' do18stub_request(:head, dir_url).to_return(status: 404)1920expect(finder.aggressive).to eql nil21end22end2324context 'when 200 and matching the homepage' do25it 'returns nil' do26stub_request(:head, dir_url)27stub_request(:get, dir_url)2829expect(target).to receive(:homepage_or_404?).and_return(true)3031expect(finder.aggressive).to eql nil32end33end3435context 'when 200 or 403' do36before do37stub_request(:head, dir_url)38stub_request(:get, dir_url).and_return(body: body)3940expect(target).to receive(:homepage_or_404?).and_return(false)41end4243after do44found = finder.aggressive4546expect(found).to eql WPScan::Model::BackupDB.new(47dir_url,48confidence: 70,49found_by: described_class::DIRECT_ACCESS50)5152expect(found.interesting_entries).to eq @expected_entries53end5455context 'when no directory listing' do56let(:body) { '' }5758it 'returns an empty interesting_findings attribute' do59@expected_entries = []60end61end6263context 'when directory listing enabled' do64let(:body) { File.read(fixtures.join('dir_listing.html')) }6566it 'returns the expected interesting_findings attribute' do67@expected_entries = %w[sqldump.sql test.txt]68end69end70end71end72end737475