Path: blob/master/spec/shared_examples/views/main_theme.rb
485 views
# frozen_string_literal: true12shared_examples 'App::Views::MainTheme' do3let(:controller) { WPScan::Controller::MainTheme.new }4let(:tpl_vars) { { url: target_url } }5let(:theme) { WPScan::Model::Theme.new(theme_name, target, found_by: 'rspec') }67describe 'main_theme' do8let(:view) { 'theme' }910context 'when no theme found' do11let(:expected_view) { 'not_found' }1213it 'outputs the expected string' do14@tpl_vars = tpl_vars.merge(theme: nil)15end16end1718context 'when a theme found' do19let(:theme_name) { 'test' }2021before do22expect(target).to receive(:content_dir).at_least(1).and_return('wp-content')2324# Stub all requests to 200, to detect the readme.25# Detection of the error_log will fail as the empty body won't match the patterns26stub_request(:head, /.*/)27stub_request(:get, /.*/)2829stub_request(:get, /.*\.css\z/)30.to_return(body: File.read(FIXTURES.join('models', 'theme', 'style.css')))31end3233context 'when no verbose' do34let(:expected_view) { 'no_verbose' }3536it 'outputs the expected string' do37expect(theme).to receive(:version).at_least(1)3839@tpl_vars = tpl_vars.merge(theme: theme)40end41end4243context 'when verbose' do44let(:expected_view) { 'verbose' }4546it 'outputs the expected string' do47expect(theme)48.to receive(:version)49.at_least(1)50.and_return(WPScan::Model::Version.new('3.2', found_by: 'style'))5152@tpl_vars = tpl_vars.merge(theme: theme, verbose: true)53end54end5556context 'when vulnerable' do57let(:expected_view) { 'vulnerable' }58let(:theme_name) { 'dignitas-themes' }5960it 'outputs the expected string' do61expect(theme).to receive(:version).at_least(1)62allow(theme).to receive(:db_data).and_return(vuln_api_data_for('themes/dignitas-themes'))6364@tpl_vars = tpl_vars.merge(theme: theme, verbose: true)65end66end67end68end69end707172