1 require File.dirname(__FILE__) + '/test_helper'
3 class OpenIdAuthenticationTest < Test::Unit::TestCase
5 @controller = Class.new do
6 include OpenIdAuthentication
11 def test_authentication_should_fail_when_the_identity_server_is_missing
12 open_id_consumer = mock()
13 open_id_consumer.expects(:begin).raises(OpenID::OpenIDError)
14 @controller.expects(:open_id_consumer).returns(open_id_consumer)
15 @controller.expects(:logger).returns(mock(:error => true))
17 @controller.send(:authenticate_with_open_id, "http://someone.example.com") do |result, identity_url|
18 assert result.missing?
19 assert_equal "Sorry, the OpenID server couldn't be found", result.message
23 def test_authentication_should_be_invalid_when_the_identity_url_is_invalid
24 @controller.send(:authenticate_with_open_id, "!") do |result, identity_url|
25 assert result.invalid?, "Result expected to be invalid but was not"
26 assert_equal "Sorry, but this does not appear to be a valid OpenID", result.message
30 def test_authentication_should_fail_when_the_identity_server_times_out
31 open_id_consumer = mock()
32 open_id_consumer.expects(:begin).raises(Timeout::Error, "Identity Server took too long.")
33 @controller.expects(:open_id_consumer).returns(open_id_consumer)
34 @controller.expects(:logger).returns(mock(:error => true))
36 @controller.send(:authenticate_with_open_id, "http://someone.example.com") do |result, identity_url|
37 assert result.missing?
38 assert_equal "Sorry, the OpenID server couldn't be found", result.message
42 def test_authentication_should_begin_when_the_identity_server_is_present
43 @controller.expects(:begin_open_id_authentication)
44 @controller.send(:authenticate_with_open_id, "http://someone.example.com")