Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wpscanteam
GitHub Repository: wpscanteam/wpscan
Path: blob/master/spec/shared_examples/views/main_theme.rb
485 views
1
# frozen_string_literal: true
2
3
shared_examples 'App::Views::MainTheme' do
4
let(:controller) { WPScan::Controller::MainTheme.new }
5
let(:tpl_vars) { { url: target_url } }
6
let(:theme) { WPScan::Model::Theme.new(theme_name, target, found_by: 'rspec') }
7
8
describe 'main_theme' do
9
let(:view) { 'theme' }
10
11
context 'when no theme found' do
12
let(:expected_view) { 'not_found' }
13
14
it 'outputs the expected string' do
15
@tpl_vars = tpl_vars.merge(theme: nil)
16
end
17
end
18
19
context 'when a theme found' do
20
let(:theme_name) { 'test' }
21
22
before do
23
expect(target).to receive(:content_dir).at_least(1).and_return('wp-content')
24
25
# Stub all requests to 200, to detect the readme.
26
# Detection of the error_log will fail as the empty body won't match the patterns
27
stub_request(:head, /.*/)
28
stub_request(:get, /.*/)
29
30
stub_request(:get, /.*\.css\z/)
31
.to_return(body: File.read(FIXTURES.join('models', 'theme', 'style.css')))
32
end
33
34
context 'when no verbose' do
35
let(:expected_view) { 'no_verbose' }
36
37
it 'outputs the expected string' do
38
expect(theme).to receive(:version).at_least(1)
39
40
@tpl_vars = tpl_vars.merge(theme: theme)
41
end
42
end
43
44
context 'when verbose' do
45
let(:expected_view) { 'verbose' }
46
47
it 'outputs the expected string' do
48
expect(theme)
49
.to receive(:version)
50
.at_least(1)
51
.and_return(WPScan::Model::Version.new('3.2', found_by: 'style'))
52
53
@tpl_vars = tpl_vars.merge(theme: theme, verbose: true)
54
end
55
end
56
57
context 'when vulnerable' do
58
let(:expected_view) { 'vulnerable' }
59
let(:theme_name) { 'dignitas-themes' }
60
61
it 'outputs the expected string' do
62
expect(theme).to receive(:version).at_least(1)
63
allow(theme).to receive(:db_data).and_return(vuln_api_data_for('themes/dignitas-themes'))
64
65
@tpl_vars = tpl_vars.merge(theme: theme, verbose: true)
66
end
67
end
68
end
69
end
70
end
71
72