Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wpscanteam
GitHub Repository: wpscanteam/wpscan
Path: blob/master/spec/lib/db/dynamic_finders/plugin_spec.rb
486 views
1
# frozen_string_literal: true
2
3
describe WPScan::DB::DynamicFinders::Plugin do
4
subject(:dynamic_finders) { described_class }
5
6
describe '.finders_configs' do
7
context 'when the given class is not allowed' do
8
it 'returns an empty hash' do
9
expect(subject.finder_configs('aaaa')).to eql({})
10
end
11
end
12
13
context 'when the given class is allowed' do
14
context 'when aggressive argument is false' do
15
it 'returns only the configs w/o a path parameter' do
16
configs = subject.finder_configs(:Xpath)
17
18
expect(configs.keys).to include('wordpress-mobile-pack', 'shareaholic')
19
expect(configs.keys).to_not include('simple-share-button-adder')
20
21
expect(configs['sitepress-multilingual-cms']['MetaGenerator']['pattern']).to be_a Regexp
22
expect(configs['sitepress-multilingual-cms']['MetaGenerator']['version']).to eql true
23
end
24
end
25
26
context 'when aggressive argument is true' do
27
it 'returns only the configs with a path parameter' do
28
configs = subject.finder_configs(:Xpath, aggressive: true)
29
30
expect(configs.keys).to include('revslider')
31
expect(configs.keys).to_not include('shareaholic')
32
end
33
end
34
end
35
end
36
37
describe '.versions_finders_configs' do
38
# Just test a sample here
39
its('versions_finders_configs.keys') { should include('shareaholic') }
40
its('versions_finders_configs.keys') { should_not include('wordpress-mobile-pack') }
41
end
42
43
describe '.maybe_create_module' do
44
xit
45
end
46
47
describe '.create_versions_finders' do
48
# handled and tested in spec/lib/finders/dynamic_finders/plugin_version_spec
49
50
context 'When trying to create the finders twice' do
51
# let's just test one slug, no need to test them all
52
let(:slug) { '12-step-meeting-list' }
53
54
it 'does not raise an error when the class already exists' do
55
WPScan::DB::DynamicFinders::Plugin.create_versions_finders(slug)
56
57
expect { WPScan::DB::DynamicFinders::Plugin.create_versions_finders(slug) }.to_not raise_error
58
end
59
end
60
61
context 'when the slug contains non alpha-numeric chars' do
62
let(:slug) { 'test.something' }
63
64
it 'sanitize it and does not raise an error' do
65
expect { WPScan::DB::DynamicFinders::Plugin.create_versions_finders(slug) }.to_not raise_error
66
end
67
end
68
end
69
70
describe '.version_finder_super_class' do
71
# handled and tested in spec/lib/finders/dynamic_finders/plugin_version_spec
72
end
73
74
describe '.method_missing' do
75
context 'when the method matches a valid call' do
76
its('passive_comment_finder_configs.keys') { should include('addthis') }
77
its('passive_comment_finder_configs.keys') { should_not include('shareaholic') }
78
79
its('passive_xpath_finder_configs.keys') { should include('shareaholic') }
80
its('passive_xpath_finder_configs.keys') { should_not include('simple-share-button-adder') }
81
its('aggressive_xpath_finder_configs.keys') { should_not include('wordpress-mobile-pack') }
82
its('aggressive_xpath_finder_configs.keys') { should include('revslider') }
83
end
84
85
context 'when the method does not match a valid call' do
86
it 'raises an error' do
87
expect { subject.aaa }.to raise_error(NoMethodError)
88
end
89
end
90
end
91
end
92
93