Path: blob/master/spec/app/finders/plugin_version/readme_spec.rb
2193 views
# frozen_string_literal: true12describe WPScan::Finders::PluginVersion::Readme do3subject(:finder) { described_class.new(plugin) }4let(:plugin) { WPScan::Model::Plugin.new('spec', target) }5let(:target) { WPScan::Target.new('http://wp.lab/') }6let(:fixtures) { FINDERS_FIXTURES.join('plugin_version', 'readme') }78def version(number, found_by, confidence)9WPScan::Model::Version.new(10number,11found_by: format('Readme - %s (Aggressive Detection)', found_by),12confidence: confidence,13interesting_entries: [readme_url]14)15end1617def stable_tag(number)18version(number, 'Stable Tag', 80)19end2021def changelog_section(number)22version(number, 'ChangeLog Section', 50)23end2425describe '#aggressive' do26before do27expect(target).to receive(:content_dir).and_return('wp-content')2829allow(target).to receive(:head_or_get_params).and_return(method: :head)3031stub_request(:head, /.*/).to_return(status: 404)32stub_request(:head, readme_url).to_return(status: 200)33end3435let(:readme_url) { plugin.url(WPScan::Model::WpItem::READMES.sample) }3637after do38stub_request(:get, readme_url).to_return(body: File.read(fixtures.join(@file)))3940expect(finder.aggressive).to eql @expected41end4243context 'when no version' do44it 'returns nil' do45@file = 'no_version.txt'46@expected = nil47end48end4950context 'when the stable tag does not contain numbers' do51it 'returns nil' do52@file = 'aa-health-calculator.txt'53@expected = nil54end55end5657context 'when empty changelog section' do58it 'returns nil' do59@file = 'all-in-one-facebook.txt'60@expected = nil61end62end6364context 'when no changelog section' do65it 'returns nil' do66@file = 'blog-reordering.txt'67@expected = nil68end69end7071context 'when leaked from the stable tag' do72it 'returns the expected versions' do73@file = 'simple-login-lockdown-0.4.txt'74@expected = [stable_tag('0.4'), changelog_section('04')]75end76end7778context 'when leaked from the version' do79it 'returns it' do80@file = 'wp-photo-plus-5.1.15.txt'81@expected = [stable_tag('5.1.15')]82end83end8485context 'when version is in a release date format' do86it 'detects and returns it' do87@file = 's2member.txt'88@expected = [stable_tag('141007')]89end90end9192context 'when version contains letters' do93it 'returns it' do94@file = 'beta1.txt'95@expected = [stable_tag('2.0.0-beta1')]96end97end9899context 'when parsing the changelog for version numbers' do100{101'changelog_version' => '1.3',102'wp_polls' => '2.64',103'nextgen_gallery' => '2.0.66.33',104'wp_user_frontend' => '1.2.3',105'my_calendar' => '2.1.5',106'nextgen_gallery_2' => '1.9.13',107'advanced-most-recent-posts-mod' => '1.6.5.2',108'a-lead-capture-contact-form-and-tab-button-by-awebvoicecom' => '3.1',109'backup-scheduler' => '1.5.9',110'release_date_slash' => '1.0.4',111'cool_tag_cloud' => '2.27'112}.each do |file, version_number|113context "whith #{file}.txt" do114it 'returns the expected version' do115@file = "#{file}.txt"116@expected = [changelog_section(version_number)]117end118end119end120end121end122end123124125