You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

open_id_authentication_test.rb 1.8KB

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