diff --git a/lib/fog/xenserver.rb b/lib/fog/xenserver.rb index 985cf76ba..4ed89d924 100644 --- a/lib/fog/xenserver.rb +++ b/lib/fog/xenserver.rb @@ -1,5 +1,8 @@ module Fog module XenServer + + class InvalidLogin < Fog::Errors::Error; end + extend Fog::Provider service(:compute, 'xenserver/compute', 'Compute') @@ -13,10 +16,8 @@ module Fog end def authenticate( username, password ) - begin - response = @factory.call('session.login_with_password', username, password ) - raise Fog::XenServer::InvalidLogin unless response["Status"] =~ /Success/ - end + response = @factory.call('session.login_with_password', username, password ) + raise Fog::XenServer::InvalidLogin.new unless response["Status"] =~ /Success/ @credentials = response["Value"] end diff --git a/tests/xenserver/xenserver_tests.rb b/tests/xenserver/xenserver_tests.rb new file mode 100644 index 000000000..9ef6e2f00 --- /dev/null +++ b/tests/xenserver/xenserver_tests.rb @@ -0,0 +1,34 @@ +Shindo.tests('Fog::Compute[:xenserver]', ['xenserver']) do + + tests("Login") do + raises(Fog::XenServer::InvalidLogin, 'raises error when invalid password') do + conn = Fog::Compute.new({ + :provider => 'XenServer', + :xenserver_url => 'xenserver-test', + :xenserver_username => 'root', + :xenserver_password => 'asdfsadf' + + }) + end + raises(Fog::XenServer::InvalidLogin, 'raises error when invalid user') do + conn = Fog::Compute.new({ + :provider => 'XenServer', + :xenserver_url => 'xenserver-test', + :xenserver_username => 'rootffff', + :xenserver_password => 'changeme' + + }) + end + raises(SocketError, 'raises error when invalid host') do + conn = Fog::Compute.new({ + :provider => 'XenServer', + :xenserver_url => 'xenserver-testlakjsdflkj', + :xenserver_username => 'root', + :xenserver_password => 'changeme' + + }) + end + end + +end +