Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wpscanteam
GitHub Repository: wpscanteam/wpscan
Path: blob/master/spec/shared_examples/finders/wp_items/urls_in_page.rb
486 views
1
# frozen_string_literal: true
2
3
shared_examples 'App::Finders::WpItems::UrlsInPage' do
4
before do
5
allow(finder.target).to receive(:content_dir).and_return('wp-content')
6
7
stub_request(:get, page_url).to_return(body: defined?(body) ? body : File.read(fixtures.join(fixture)))
8
end
9
10
describe '#items_from_links' do
11
context 'when none found' do
12
let(:fixture) { 'none.html' }
13
14
it 'returns an empty array' do
15
expect(finder.items_from_links(type)).to eql([])
16
end
17
end
18
19
context 'when found' do
20
let(:fixture) { 'found.html' }
21
22
it 'returns the expected array' do
23
expect(finder.items_from_links(type, uniq: uniq_links)).to eql expected_from_links
24
end
25
end
26
27
context 'when a lof of unrelated links' do
28
let(:body) do
29
Array.new(250) { |i| "<a href='#{url}#{i}.html'>Link</a><img src='#{url}img-#{i}.gif'/>" }.join("\n")
30
end
31
32
it 'should not take a while to process the page' do
33
time_start = Time.now
34
expect(finder.items_from_links(type)).to eql []
35
time_end = Time.now
36
37
expect(time_end - time_start).to be < 1
38
end
39
end
40
end
41
42
describe '#items_from_codes' do
43
context 'when none found' do
44
let(:fixture) { 'none.html' }
45
46
it 'returns an empty array' do
47
expect(finder.items_from_codes(type)).to eql([])
48
end
49
end
50
51
context 'when found' do
52
let(:fixture) { 'found.html' }
53
54
it 'returns the expected array' do
55
expect(finder.items_from_codes(type, uniq: uniq_codes)).to eql expected_from_codes
56
end
57
end
58
end
59
end
60
61