Path: blob/master/spec/app/finders/theme_version/style_spec.rb
1483 views
# frozen_string_literal: true12describe WPScan::Finders::ThemeVersion::Style do3subject(:finder) { described_class.new(theme) }4let(:theme) { WPScan::Model::Theme.new('spec', target) }5let(:target) { WPScan::Target.new('http://wp.lab/') }6let(:fixtures) { FINDERS_FIXTURES.join('theme_version', 'style') }78before :all do9Typhoeus::Config.cache = WPScan::Cache::Typhoeus.new(SPECS.join('cache'))10end1112before do13expect(target).to receive(:content_dir).at_least(1).and_return('wp-content')14stub_request(:get, /.*.css/).and_return(body: defined?(style_body) ? style_body : '')15end1617describe '#passive' do18before { expect(finder).to receive(:cached_style?).and_return(cached?) }19after { finder.passive }2021context 'when the style_url request has been cached' do22let(:cached?) { true }2324it 'calls the style_version' do25expect(finder).to receive(:style_version)26end27end2829context 'when the style_url request has not been cached' do30let(:cached?) { false }3132it 'returns nil' do33expect(finder).to_not receive(:style_version)34end35end36end3738describe '#aggressive' do39before { expect(finder).to receive(:cached_style?).and_return(cached?) }40after { finder.aggressive }4142context 'when the style_url request has been cached' do43let(:cached?) { true }4445it 'returns nil' do46expect(finder).to_not receive(:style_version)47end48end4950context 'when the style_url request has not been cached' do51let(:cached?) { false }5253it 'calls the style_version' do54expect(finder).to receive(:style_version)55end56end57end5859describe '#cached_style?' do60it 'calls the Cache with the correct arguments' do61expected = Typhoeus::Request.new(62theme.style_url,63finder.browser.default_request_params.merge(method: :get)64)6566expect(Typhoeus::Config.cache).to receive(:get) { |arg| expect(arg).to eql expected }67finder.cached_style?68end69end7071describe '#style_version' do72{73'inline' => '1.5.1',74'firefart' => '1.0.0',75'tralling_quote' => '1.3',76'no_version_tag' => nil,77'trunk_version' => nil,78'no_version' => nil79}.each do |file, expected_version|80context "when #{file}" do81let(:style_body) { File.new(fixtures.join("#{file}.css")) }8283it 'returns the expected version' do84expected = if expected_version85WPScan::Model::Version.new(86expected_version,87confidence: 80,88interesting_entries: ["#{theme.style_url}, Version: #{expected_version}"]89)90end9192expect(finder.style_version).to eql expected93end94end95end96end97end9899100