fix rspecs

This commit is contained in:
Christian Mehlmauer
2016-07-21 13:57:18 +02:00
parent d697127261
commit 2cc5bb0311
2 changed files with 18 additions and 6 deletions

View File

@@ -67,11 +67,16 @@ class Browser
@@instance = nil
end
# Override for setting the User-Agent
def user_agent=(user_agent)
Typhoeus::Config.user_agent = user_agent
end
#
# sets browser default values
#
def browser_defaults
@user_agent = "WPScan v#{WPSCAN_VERSION} (http://wpscan.org)"
Typhoeus::Config.user_agent = "WPScan v#{WPSCAN_VERSION} (http://wpscan.org)"
@max_threads = 20
# 10 minutes, at this time the cache is cleaned before each scan.
# If this value is set to 0, the cache will be disabled
@@ -115,8 +120,6 @@ class Browser
#
# @return [ Hash ]
def merge_request_params(params = {})
Typhoeus::Config.user_agent = @user_agent
if @proxy
params.merge!(proxy: @proxy)
params.merge!(proxyauth: @proxy_auth) if @proxy_auth

View File

@@ -124,10 +124,10 @@ describe Browser do
describe '#merge_request_params' do
let(:params) { {} }
let(:cookie_jar) { CACHE_DIR + '/browser/cookie-jar' }
let(:user_agent) { 'SomeUA' }
let(:default_expectation) {
{
cache_ttl: 250,
headers: { 'User-Agent' => 'SomeUA' },
ssl_verifypeer: false, ssl_verifyhost: 0,
cookiejar: cookie_jar, cookiefile: cookie_jar,
timeout: 60, connecttimeout: 10,
@@ -137,16 +137,25 @@ describe Browser do
}
after :each do
browser.user_agent = 'SomeUA'
browser.user_agent = user_agent
browser.cache_ttl = 250
expect(browser.merge_request_params(params)).to eq @expected
expect(Typhoeus::Config.user_agent).to eq user_agent
end
it 'sets the User-Agent header field and cache_ttl' do
@expected = default_expectation
end
context 'when @user_agent' do
let(:user_agent) { 'test' }
it 'sets the User-Agent' do
@expected = default_expectation
end
end
context 'when @proxy' do
let(:proxy) { '127.0.0.1:9050' }
let(:proxy_expectation) { default_expectation.merge(proxy: proxy) }
@@ -177,7 +186,7 @@ describe Browser do
it 'appends the basic_auth' do
browser.basic_auth = 'user:pass'
@expected = default_expectation.merge(
headers: default_expectation[:headers].merge('Authorization' => 'Basic ' + Base64.encode64('user:pass').chomp)
headers: { 'Authorization' => 'Basic ' + Base64.encode64('user:pass').chomp }
)
end
end