Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wpscanteam
GitHub Repository: wpscanteam/wpscan
Path: blob/master/spec/app/controllers/wp_version_spec.rb
486 views
1
# frozen_string_literal: true
2
3
def it_calls_the_formatter_with_the_correct_parameter(version)
4
it 'calls the formatter with the correct parameter' do
5
expect(controller.formatter).to receive(:output)
6
.with('version', hash_including(version: version), 'wp_version')
7
end
8
end
9
10
describe WPScan::Finders::WpVersionFinders do
11
subject(:finders) { described_class.new }
12
13
describe 'filter_findings' do
14
context 'when super returns false (nothing found)' do
15
before do
16
expect_any_instance_of(WPScan::Finders::UniqueFinders).to receive(:filter_findings).and_return(false)
17
end
18
19
its(:filter_findings) { should be false }
20
end
21
end
22
end
23
24
describe WPScan::Controller::WpVersion do
25
subject(:controller) { described_class.new }
26
let(:target_url) { 'http://ex.lo/' }
27
let(:cli_args) { "--url #{target_url}" }
28
29
before do
30
WPScan::ParsedCli.options = rspec_parsed_options(cli_args)
31
end
32
33
describe '#cli_options' do
34
its(:cli_options) { should_not be_empty }
35
its(:cli_options) { should be_a Array }
36
37
it 'contains to correct options' do
38
expect(controller.cli_options.map(&:to_sym)).to eq %i[wp_version_all wp_version_detection]
39
end
40
end
41
42
describe '#run' do
43
before do
44
expect(controller.target).to receive(:wp_version)
45
.with(
46
hash_including(
47
mode: WPScan::ParsedCli.wp_version_detection || WPScan::ParsedCli.detection_mode,
48
confidence_threshold: WPScan::ParsedCli.wp_version_all ? 0 : 100
49
)
50
).and_return(stubbed)
51
end
52
53
after { controller.run }
54
55
%i[mixed passive aggressive].each do |mode|
56
context "when --detection-mode #{mode}" do
57
let(:cli_args) { "#{super()} --detection-mode #{mode}" }
58
59
[WPScan::Model::WpVersion.new('4.0')].each do |version|
60
context "when version = #{version}" do
61
let(:stubbed) { version }
62
63
it_calls_the_formatter_with_the_correct_parameter(version)
64
end
65
end
66
end
67
end
68
69
context 'when --wp-version-all supplied' do
70
let(:cli_args) { "#{super()} --wp-version-all" }
71
let(:stubbed) { WPScan::Model::WpVersion.new('3.9.1') }
72
73
it_calls_the_formatter_with_the_correct_parameter(WPScan::Model::WpVersion.new('3.9.1'))
74
end
75
76
context 'when --wp-version-detection mode supplied' do
77
let(:cli_args) { "#{super()} --detection-mode mixed --wp-version-detection passive" }
78
let(:stubbed) { WPScan::Model::WpVersion.new('4.4') }
79
80
it_calls_the_formatter_with_the_correct_parameter(WPScan::Model::WpVersion.new('4.4'))
81
end
82
end
83
end
84
85