Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wpscanteam
GitHub Repository: wpscanteam/wpscan
Path: blob/master/spec/spec_helper.rb
485 views
1
# frozen_string_literal: true
2
3
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
5
require 'simplecov' # More config is defined in ./.simplecov
6
require 'rspec/its'
7
require 'webmock/rspec'
8
9
# See http://betterspecs.org/
10
RSpec.configure do |config|
11
config.expect_with :rspec do |c|
12
c.syntax = :expect
13
end
14
15
# For --only-failures / --next-failure
16
config.example_status_persistence_file_path = '/tmp/rspec_examples.txt'
17
end
18
19
def redefine_constant(constant, value)
20
WPScan.send(:remove_const, constant)
21
WPScan.const_set(constant, value)
22
end
23
24
# Dynamic Finders Helpers
25
def df_expected_all
26
YAML.safe_load(File.read(DYNAMIC_FINDERS_FIXTURES.join('expected.yml')))
27
end
28
29
def df_tested_class_constant(type, finder_class, slug = nil)
30
if slug
31
"WPScan::Finders::#{type}::#{classify_slug(slug)}::#{classify_slug(finder_class)}".constantize
32
else
33
"WPScan::Finders::#{type}::#{classify_slug(finder_class)}".constantize
34
end
35
end
36
37
def df_stubbed_response(fixture, finder_super_class)
38
if finder_super_class == 'HeaderPattern'
39
{ headers: JSON.parse(File.read(fixture)) }
40
else
41
{ body: File.read(fixture, mode: 'rb') }
42
end
43
end
44
45
def vuln_api_data_for(path)
46
JSON.parse(File.read(FIXTURES.join('db', 'vuln_api', "#{path}.json")))
47
end
48
49
require 'wpscan'
50
require 'shared_examples'
51
52
def rspec_parsed_options(args)
53
controllers = WPScan::Controller.constants.reject { |c| c == :Base }.reduce(WPScan::Controllers.new) do |a, sym|
54
a << WPScan::Controller.const_get(sym).new
55
end
56
57
controllers.option_parser.results(args.split)
58
end
59
60
# TODO: remove when https://github.com/bblimke/webmock/issues/552 fixed
61
# Also remove from CMSScanner
62
# rubocop:disable all
63
module WebMock
64
module HttpLibAdapters
65
class TyphoeusAdapter < HttpLibAdapter
66
def self.effective_url(effective_uri)
67
effective_uri.port = nil if effective_uri.scheme == 'http' && effective_uri.port == 80
68
effective_uri.port = nil if effective_uri.scheme == 'https' && effective_uri.port == 443
69
70
effective_uri.to_s
71
end
72
73
def self.generate_typhoeus_response(request_signature, webmock_response)
74
response = if webmock_response.should_timeout
75
::Typhoeus::Response.new(
76
code: 0,
77
status_message: '',
78
body: '',
79
headers: {},
80
return_code: :operation_timedout
81
)
82
else
83
::Typhoeus::Response.new(
84
code: webmock_response.status[0],
85
status_message: webmock_response.status[1],
86
body: webmock_response.body,
87
headers: webmock_response.headers,
88
effective_url: effective_url(request_signature.uri)
89
)
90
end
91
response.mock = :webmock
92
response
93
end
94
end
95
end
96
end
97
# rubocop:enable all
98
99
SPECS = Pathname.new(__FILE__).dirname
100
FIXTURES = SPECS.join('fixtures')
101
FINDERS_FIXTURES = FIXTURES.join('finders')
102
DYNAMIC_FINDERS_FIXTURES = FIXTURES.join('dynamic_finders')
103
ERROR_404_URL_PATTERN = %r{/[a-z\d]{7}\.html$}.freeze
104
105
redefine_constant(:DB_DIR, FIXTURES.join('db'))
106
107