Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wpscanteam
GitHub Repository: wpscanteam/wpscan
Path: blob/master/spec/app/models/wp_item_spec.rb
486 views
1
# frozen_string_literal: true
2
3
describe WPScan::Model::WpItem do
4
subject(:wp_item) { described_class.new(slug, blog, opts) }
5
let(:slug) { 'test_item' }
6
let(:blog) { WPScan::Target.new(url) }
7
let(:url) { 'http://wp.lab/' }
8
let(:opts) { {} }
9
10
its(:blog) { should eql blog }
11
12
describe '#new' do
13
context 'when no opts' do
14
its(:slug) { should eql slug }
15
its(:detection_opts) { should eql(mode: nil) }
16
its(:version_detection_opts) { should eql({}) }
17
end
18
19
context 'when :mode' do
20
let(:opts) { super().merge(mode: :passive, version_detection: { mode: :aggressive }) }
21
22
its(:detection_opts) { should eql(mode: :passive) }
23
its(:version_detection_opts) { should eql(mode: :aggressive) }
24
end
25
26
context 'when the slug contains encoded chars' do
27
let(:slug) { 'theme%212%23a' }
28
29
its(:slug) { should eql 'theme!2#a' }
30
end
31
end
32
33
describe '#url' do
34
context 'when no opts[:url]' do
35
its(:url) { should eql nil }
36
end
37
38
context 'when opts[:url]' do
39
let(:opts) { super().merge(url: item_url) }
40
let(:item_url) { "#{url}item/" }
41
42
context 'when path given' do
43
it 'appends it' do
44
expect(wp_item.url('path')).to eql "#{item_url}path"
45
end
46
end
47
48
it 'encodes the path' do
49
expect(wp_item.url('#t#')).to eql "#{item_url}#t%23"
50
expect(wp_item.url('t .txt')).to eql "#{item_url}t%20.txt"
51
end
52
end
53
end
54
55
describe '#==' do
56
context 'when the same slug' do
57
it 'returns true' do
58
other = described_class.new(slug, blog)
59
60
expect(wp_item == other).to be true
61
end
62
end
63
64
context 'when another object' do
65
it 'returns false' do
66
expect(wp_item == 'string').to be false
67
end
68
end
69
70
context 'when different slugs' do
71
it 'returns false' do
72
other = described_class.new('another', blog)
73
74
expect(wp_item == other).to be false
75
end
76
end
77
end
78
79
describe '#latest_version' do
80
# Handled in plugin_spec / theme_spec
81
end
82
83
describe '#popular?' do
84
# Handled in plugin_spec / theme_spec
85
end
86
87
describe '#last_updated' do
88
# Handled in plugin_spec / theme_spec
89
end
90
91
describe '#outdated?' do
92
# Handled in plugin_spec / theme_spec
93
end
94
95
describe '#to_s' do
96
its(:to_s) { should eql slug }
97
end
98
99
describe '#classify' do
100
its(:classify) { should eql :TestItem }
101
102
context 'when it starts with a digit' do
103
let(:slug) { '2test' }
104
105
its(:classify) { should eql :D_2test }
106
107
context 'when a digit and -' do
108
let(:slug) { '23-test' }
109
110
its(:classify) { should eql :D_23Test }
111
end
112
end
113
end
114
115
# Guess all the below should be in the theme/plugin specs
116
describe '#readme_url' do
117
xit
118
end
119
120
describe '#directory_listing?' do
121
xit
122
end
123
124
describe '#error_log?' do
125
xit
126
end
127
128
describe '#head_and_get' do
129
xit
130
end
131
end
132
133