To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 0d / 0dec78f36b0f6507c2aa4e50dcd86ca0850c844a.svn-base @ 912:5e80956cc792
History | View | Annotate | Download (1.83 KB)
| 1 | 909:cbb26bc654de | Chris | require File.dirname(__FILE__) + '/test_helper' |
|---|---|---|---|
| 2 | |||
| 3 | class OpenIdAuthenticationTest < Test::Unit::TestCase |
||
| 4 | def setup |
||
| 5 | @controller = Class.new do |
||
| 6 | include OpenIdAuthentication |
||
| 7 | def params() {} end
|
||
| 8 | end.new |
||
| 9 | end |
||
| 10 | |||
| 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)) |
||
| 16 | |||
| 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 |
||
| 20 | end |
||
| 21 | end |
||
| 22 | |||
| 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 |
||
| 27 | end |
||
| 28 | end |
||
| 29 | |||
| 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)) |
||
| 35 | |||
| 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 |
||
| 39 | end |
||
| 40 | end |
||
| 41 | |||
| 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") |
||
| 45 | end |
||
| 46 | end |