Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wpscanteam
GitHub Repository: wpscanteam/wpscan
Path: blob/master/spec/app/finders/users/oembed_api_spec.rb
1483 views
1
# frozen_string_literal: true
2
3
describe WPScan::Finders::Users::OembedApi do
4
subject(:finder) { described_class.new(target) }
5
let(:target) { WPScan::Target.new(url) }
6
let(:url) { 'http://wp.lab/' }
7
let(:fixtures) { FINDERS_FIXTURES.join('users', 'oembed_api') }
8
9
describe '#aggressive' do
10
before do
11
allow(target).to receive(:sub_dir).and_return(false)
12
stub_request(:get, finder.api_url).to_return(body: body)
13
end
14
15
context 'when not a JSON response' do
16
let(:body) { '' }
17
18
its(:aggressive) { should eql([]) }
19
end
20
21
context 'when a JSON response' do
22
let(:body) { File.read(fixture) }
23
24
context 'when 404' do
25
let(:fixture) { fixtures.join('404.json') }
26
27
its(:aggressive) { should eql([]) }
28
end
29
30
context 'when 200' do
31
context 'when author_url present' do
32
let(:fixture) { fixtures.join('200_author_url.json') }
33
34
it 'returns the expected array of users' do
35
users = finder.aggressive
36
37
expect(users.size).to eql 1
38
39
user = users.first
40
41
expect(user.username).to eql 'admin'
42
expect(user.confidence).to eql 90
43
expect(user.found_by).to eql 'Oembed API - Author URL (Aggressive Detection)'
44
expect(user.interesting_entries).to eql ['http://wp.lab/wp-json/oembed/1.0/embed?url=http://wp.lab/&format=json']
45
end
46
end
47
48
context 'when author_url not present but author_name' do
49
let(:fixture) { fixtures.join('200_author_name.json') }
50
51
it 'returns the expected array of users' do
52
users = finder.aggressive
53
54
expect(users.size).to eql 1
55
56
user = users.first
57
58
expect(user.username).to eql 'admin sa'
59
expect(user.confidence).to eql 70
60
expect(user.found_by).to eql 'Oembed API - Author Name (Aggressive Detection)'
61
expect(user.interesting_entries).to eql ['http://wp.lab/wp-json/oembed/1.0/embed?url=http://wp.lab/&format=json']
62
end
63
end
64
65
context 'when body is an array' do
66
let(:fixture) { fixtures.join('array.json') }
67
68
its(:aggressive) { should eql([]) }
69
end
70
end
71
end
72
end
73
end
74
75