Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wpscanteam
GitHub Repository: wpscanteam/wpscan
Path: blob/master/spec/shared_examples/dynamic_finders/wp_items.rb
485 views
1
# frozen_string_literal: true
2
3
shared_examples WPScan::Finders::DynamicFinder::WpItems::Finder do
4
let(:passive_fixture) do
5
fixtures.join("#{described_class.to_s.demodulize.underscore}_passive_all.html")
6
end
7
8
describe '#passive_configs' do
9
# Not sure if it's worth to do it as it's just a call to something tested
10
# and an exception will be raised if the method called is wrong
11
end
12
13
describe '#aggressive_configs' do
14
# Same as above
15
end
16
17
describe '#passive' do
18
before do
19
stub_request(:get, target.url).to_return(body: homepage_body)
20
stub_request(:get, ERROR_404_URL_PATTERN).to_return(body: error_404_body)
21
22
allow(target).to receive(:content_dir).and_return('wp-content')
23
end
24
25
context 'when no matches' do
26
let(:homepage_body) { '' }
27
let(:error_404_body) { '' }
28
29
it 'returns an empty array' do
30
expect(finder.passive).to eql([])
31
end
32
end
33
34
context 'when matches' do
35
let(:expected_items) do
36
expected = []
37
38
finder.passive_configs.each do |slug, configs|
39
configs.each_key do |finder_class|
40
expected_finding_opts = expected_all[slug][finder_class]
41
42
expected << item_class.new(
43
slug,
44
target,
45
confidence: expected_finding_opts['confidence'] || described_class::DEFAULT_CONFIDENCE,
46
found_by: expected_finding_opts['found_by']
47
)
48
end
49
end
50
51
expected
52
end
53
54
context 'from the homepage' do
55
let(:homepage_body) { File.read(passive_fixture) }
56
let(:error_404_body) { '' }
57
58
it 'contains the expected items' do
59
expect(finder.passive).to match_array(expected_items.map { |item| eql(item) })
60
end
61
end
62
63
context 'from the 404' do
64
let(:homepage_body) { '' }
65
let(:error_404_body) { File.read(passive_fixture) }
66
67
it 'contains the expected items' do
68
expect(finder.passive).to match_array(expected_items.map { |item| eql(item) })
69
end
70
end
71
72
context 'from both the homepage and 404' do
73
let(:homepage_body) { File.read(passive_fixture) }
74
let(:error_404_body) { File.read(passive_fixture) }
75
76
it 'does not contains the same finding twice (but from different page)' do
77
expect(finder.passive).to match_array(expected_items.map { |item| eql(item) })
78
end
79
end
80
end
81
end
82
83
describe '#aggressive' do
84
its(:aggressive) { should be nil }
85
end
86
87
xdescribe '#aggressive' do
88
# TODO: Maybe also stub all paths to an empty body and expect an empty array ?
89
90
before do
91
@expected = []
92
93
allow(target).to receive(:content_dir).and_return('wp-content')
94
95
# Stubbing all requests to the different paths
96
97
finder.aggressive_configs.each do |slug, configs|
98
configs.each do |finder_class, config|
99
finder_super_class = config['class'] || finder_class
100
101
fixture = fixtures.join(slug, finder_class.underscore, config['path'])
102
stubbed_response = df_stubbed_response(fixture, finder_super_class)
103
path = finder.aggressive_path(slug, config)
104
105
expected_finding_opts = expected_all[slug][finder_class]
106
107
stub_request(:get, target.url(path)).to_return(stubbed_response)
108
109
@expected << item_class.new(
110
slug,
111
target,
112
confidence: expected_finding_opts['confidence'] || described_class::DEFAULT_CONFIDENCE,
113
found_by: expected_finding_opts['found_by']
114
)
115
end
116
end
117
end
118
119
it 'returns the expected items' do
120
expect(finder.aggressive).to match_array(@expected.map { |item| eql(item) })
121
end
122
end
123
end
124
125