@@ -0,0 +1,45 | |||||
|
1 | # Mocks out OpenID | |||
|
2 | # | |||
|
3 | # http://www.northpub.com/articles/2007/04/02/testing-openid-support | |||
|
4 | module OpenIdAuthentication | |||
|
5 | ||||
|
6 | EXTENSION_FIELDS = {'email' => 'user@somedomain.com', | |||
|
7 | 'nickname' => 'cool_user', | |||
|
8 | 'country' => 'US', | |||
|
9 | 'postcode' => '12345', | |||
|
10 | 'fullname' => 'Cool User', | |||
|
11 | 'dob' => '1970-04-01', | |||
|
12 | 'language' => 'en', | |||
|
13 | 'timezone' => 'America/New_York'} | |||
|
14 | ||||
|
15 | protected | |||
|
16 | ||||
|
17 | def authenticate_with_open_id(identity_url = params[:openid_url], options = {}) #:doc: | |||
|
18 | if User.find_by_identity_url(identity_url) || identity_url.include?('good') | |||
|
19 | # Don't process registration fields unless it is requested. | |||
|
20 | unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?) | |||
|
21 | extension_response_fields = {} | |||
|
22 | ||||
|
23 | options[:required].each do |field| | |||
|
24 | extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s] | |||
|
25 | end unless options[:required].nil? | |||
|
26 | ||||
|
27 | options[:optional].each do |field| | |||
|
28 | extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s] | |||
|
29 | end unless options[:optional].nil? | |||
|
30 | end | |||
|
31 | ||||
|
32 | yield Result[:successful], identity_url , extension_response_fields | |||
|
33 | else | |||
|
34 | logger.info "OpenID authentication failed: #{identity_url}" | |||
|
35 | yield Result[:failed], identity_url, nil | |||
|
36 | end | |||
|
37 | end | |||
|
38 | ||||
|
39 | private | |||
|
40 | ||||
|
41 | def add_simple_registration_fields(open_id_response, fields) | |||
|
42 | open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required] | |||
|
43 | open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional] | |||
|
44 | end | |||
|
45 | end |
@@ -64,6 +64,20 class AccountControllerTest < Test::Unit::TestCase | |||||
64 | :content => /Invalid user or password/ |
|
64 | :content => /Invalid user or password/ | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
|
67 | def test_login_with_openid | |||
|
68 | post :login, :openid_url => 'http://openid.example.com/good_user' | |||
|
69 | assert_redirected_to 'my/page' | |||
|
70 | end | |||
|
71 | ||||
|
72 | def test_login_with_openid_with_new_user_created | |||
|
73 | ||||
|
74 | end | |||
|
75 | ||||
|
76 | ||||
|
77 | def test_login_with_openid_with_new_user_with_conflict | |||
|
78 | ||||
|
79 | end | |||
|
80 | ||||
67 | def test_autologin |
|
81 | def test_autologin | |
68 | Setting.autologin = "7" |
|
82 | Setting.autologin = "7" | |
69 | Token.delete_all |
|
83 | Token.delete_all |
@@ -19,6 +19,7 ENV["RAILS_ENV"] ||= "test" | |||||
19 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") |
|
19 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") | |
20 | require 'test_help' |
|
20 | require 'test_help' | |
21 | require File.expand_path(File.dirname(__FILE__) + '/helper_testcase') |
|
21 | require File.expand_path(File.dirname(__FILE__) + '/helper_testcase') | |
|
22 | load File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb') | |||
22 |
|
23 | |||
23 | class Test::Unit::TestCase |
|
24 | class Test::Unit::TestCase | |
24 | # Transactional fixtures accelerate your tests by wrapping each test method |
|
25 | # Transactional fixtures accelerate your tests by wrapping each test method |
General Comments 0
You need to be logged in to leave comments.
Login now