Complexity of Browser#proxy_auth= reduced
This commit is contained in:
@@ -109,25 +109,18 @@ class Browser
|
||||
|
||||
def proxy_auth=(auth)
|
||||
unless auth.nil?
|
||||
if auth.is_a?(Hash)
|
||||
if !auth.include?(:proxy_username) or !auth.include?(:proxy_password)
|
||||
raise_invalid_proxy_format()
|
||||
end
|
||||
if auth.is_a?(Hash) && auth.include?(:proxy_username) && auth.include?(:proxy_password)
|
||||
@proxy_auth = auth[:proxy_username] + ':' + auth[:proxy_password]
|
||||
elsif auth.is_a?(String)
|
||||
if auth.index(':') != nil
|
||||
@proxy_auth = auth
|
||||
else
|
||||
raise_invalid_proxy_auth_format()
|
||||
end
|
||||
elsif auth.is_a?(String) && auth.index(':') != nil
|
||||
@proxy_auth = auth
|
||||
else
|
||||
raise_invalid_proxy_auth_format()
|
||||
raise invalid_proxy_auth_format
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def raise_invalid_proxy_auth_format
|
||||
raise 'Invalid proxy auth format, expected username:password or {proxy_username: username, proxy_password: password}'
|
||||
def invalid_proxy_auth_format
|
||||
'Invalid proxy auth format, expected username:password or {proxy_username: username, proxy_password: password}'
|
||||
end
|
||||
|
||||
# TODO reload hydra (if the .load_config is called on a browser object,
|
||||
|
||||
@@ -84,29 +84,54 @@ describe Browser do
|
||||
end
|
||||
end
|
||||
|
||||
it 'should raise an error if the format is not correct' do
|
||||
@proxy_auth = 'invaludauthformat'
|
||||
@raise_error = true
|
||||
end
|
||||
context 'when the auth supplied is' do
|
||||
|
||||
it 'should raise an error if the hash does not contain :proxy_username and :proxy_password' do
|
||||
@proxy_auth = { proxy_password: 'hello' }
|
||||
@raise_error = true
|
||||
end
|
||||
context 'not a String or a Hash' do
|
||||
it 'raises an error' do
|
||||
@proxy_auth = 10
|
||||
@raise_error = true
|
||||
end
|
||||
end
|
||||
|
||||
it 'should raise an error if the auth if not a string or a hash' do
|
||||
@proxy_auth = 10
|
||||
@raise_error = true
|
||||
end
|
||||
context 'a String with' do
|
||||
context 'invalid format' do
|
||||
it 'raises an error' do
|
||||
@proxy_auth = 'invaludauthformat'
|
||||
@raise_error = true
|
||||
end
|
||||
end
|
||||
|
||||
it 'should set the correct credentials' do
|
||||
@proxy_auth = { proxy_username: 'user', proxy_password: 'pass' }
|
||||
@expected = 'user:pass'
|
||||
end
|
||||
context 'valid format' do
|
||||
it 'sets the auth' do
|
||||
@proxy_auth = 'username:passwd'
|
||||
@expected = @proxy_auth
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'a Hash with' do
|
||||
context 'only :proxy_username' do
|
||||
it 'raises an error' do
|
||||
@proxy_auth = { proxy_username: 'username' }
|
||||
@raise_error = true
|
||||
end
|
||||
end
|
||||
|
||||
context 'only :proxy_password' do
|
||||
it 'raises an error' do
|
||||
@proxy_auth = { proxy_password: 'hello' }
|
||||
@raise_error = true
|
||||
end
|
||||
end
|
||||
|
||||
context ':proxy_username and :proxy_password' do
|
||||
it 'sets the auth' do
|
||||
@proxy_auth = { proxy_username: 'user', proxy_password: 'pass' }
|
||||
@expected = 'user:pass'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should set the correct credentials' do
|
||||
@proxy_auth = 'username:passwd'
|
||||
@expected = @proxy_auth
|
||||
end
|
||||
end
|
||||
|
||||
@@ -204,7 +229,7 @@ describe Browser do
|
||||
it 'should raise an error if file is a symlink' do
|
||||
symlink = './rspec_symlink'
|
||||
browser = Browser.instance
|
||||
|
||||
|
||||
File.symlink('./testfile', symlink)
|
||||
expect { browser.load_config(symlink) }.to raise_error("[ERROR] Config file is a symlink.")
|
||||
File.unlink(symlink)
|
||||
|
||||
Reference in New Issue
Block a user