aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Young <alex@bytemark.co.uk>2015-02-23 16:36:40 +0000
committerAlex Young <alex@bytemark.co.uk>2015-02-23 16:36:40 +0000
commitb212665b4e5ecaf9652ab7d3cfcd20597b3ef436 (patch)
tree74863ebc466b3b1a157bd47cd31fa18663b399ee
parent3beebea7549ae4ed46dfaa91d4f3047f3b242b6c (diff)
Stub out test calls to auth which relied on a user who no longer exists
-rw-r--r--test/tc_mauve_authentication.rb49
1 files changed, 42 insertions, 7 deletions
diff --git a/test/tc_mauve_authentication.rb b/test/tc_mauve_authentication.rb
index c364aca..a770bc9 100644
--- a/test/tc_mauve_authentication.rb
+++ b/test/tc_mauve_authentication.rb
@@ -10,8 +10,11 @@ require 'mauve/configuration'
require 'mauve/configuration_builder'
require 'mauve/configuration_builders'
-class TcMauveAuthentication < Mauve::UnitTest
+require 'webmock'
+
+class TcMauveAuthentication < Mauve::UnitTest
include Mauve
+ include WebMock::API
def setup
@@ -84,8 +87,35 @@ EOF
assert(Authentication.authenticate("test","password"))
end
+ def stub_auth_response(auth_method, success, return_value)
+ xml_writer = XMLRPC::XMLWriter::Simple.new
+ response_body = XMLRPC::Create.new(xml_writer).methodResponse(success, return_value)
+ stub_request(:post, "https://auth.bytemark.co.uk/").
+ with(:body => /bytemark\.auth\.#{Regexp.escape(auth_method)}/,:times => 1).
+ to_return(:body => response_body,
+ :headers => {"Content-Type" => "text/xml"})
+ end
+
+ def stub_auth_call(auth_method, return_value)
+ stub_auth_response(auth_method, true, return_value)
+ end
+
+ def stub_auth_failure(auth_method, failure)
+ stub_auth_response(auth_method, false, failure)
+ end
+
+ def stub_bad_login
+ stub_auth_call("getChallengeForUser", "challengechallengechallenge")
+ stub_auth_failure("login", XMLRPC::FaultException.new(91, "Bad login credentials"))
+ end
+
+ def stub_good_login
+ stub_auth_call("getChallengeForUser", "challengechallengechallenge")
+ stub_auth_call("login", "sessionsessionsession")
+ end
+
def test_bytemark_auth
- #
+ #
# BytemarkAuth test users are:
# test1: ummVRu7qF
# test2: POKvBqLT7
@@ -111,23 +141,26 @@ EOF
#
# Test to make sure auth can fail
#
+ stub_bad_login
assert(!Authentication.authenticate("test1","password"))
- #
+ #
# Should issue a warning for just bytemark auth failing, and no more.
#
assert_match(/AuthBytemark for test1 failed/, logger_shift)
assert_nil(logger_shift)
+ stub_good_login
assert(Authentication.authenticate("test1","ummVRu7qF"))
- #
+ #
# Shouldn't issue any warnings.
#
assert_nil(logger_shift)
-
+
#
# Test to make sure that in the event of failure we fall back to local
# auth, which should also fail in this case.
#
+ stub_bad_login
assert(!Authentication.authenticate("test2","badpassword"))
assert_match(/AuthBytemark for test2 failed/, logger_shift)
assert_match(/AuthLocal for test2 failed/, logger_shift)
@@ -136,8 +169,9 @@ EOF
# Test to make sure that in the event of failure we fall back to local
# auth, which should pass in this case.
#
+ stub_bad_login
assert(Authentication.authenticate("test2","password"))
- #
+ #
# Should issue a warning for just bytemark auth failing, and no more.
#
assert_match(/AuthBytemark for test2 failed/, logger_shift)
@@ -146,8 +180,9 @@ EOF
#
# Finally test to make sure local-only still works
#
+ stub_bad_login
assert(Authentication.authenticate("test3","password"))
- #
+ #
# Should issue a warning for just bytemark auth failing, and no more.
#
assert_match(/AuthBytemark for test3 failed/, logger_shift)