@@ -1,175 +1,175 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class AccountControllerOpenidTest < ActionController::TestCase |
|
20 | class AccountControllerOpenidTest < ActionController::TestCase | |
21 | tests AccountController |
|
21 | tests AccountController | |
22 | fixtures :users, :roles |
|
22 | fixtures :users, :roles | |
23 |
|
23 | |||
24 | def setup |
|
24 | def setup | |
25 | User.current = nil |
|
25 | User.current = nil | |
26 | Setting.openid = '1' |
|
26 | Setting.openid = '1' | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 | def teardown |
|
29 | def teardown | |
30 | Setting.openid = '0' |
|
30 | Setting.openid = '0' | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | if Object.const_defined?(:OpenID) |
|
33 | if Object.const_defined?(:OpenID) | |
34 |
|
34 | |||
35 | def test_login_with_openid_for_existing_user |
|
35 | def test_login_with_openid_for_existing_user | |
36 | Setting.self_registration = '3' |
|
36 | Setting.self_registration = '3' | |
37 | existing_user = User.new(:firstname => 'Cool', |
|
37 | existing_user = User.new(:firstname => 'Cool', | |
38 | :lastname => 'User', |
|
38 | :lastname => 'User', | |
39 | :mail => 'user@somedomain.com', |
|
39 | :mail => 'user@somedomain.com', | |
40 | :identity_url => 'http://openid.example.com/good_user') |
|
40 | :identity_url => 'http://openid.example.com/good_user') | |
41 | existing_user.login = 'cool_user' |
|
41 | existing_user.login = 'cool_user' | |
42 | assert existing_user.save! |
|
42 | assert existing_user.save! | |
43 |
|
43 | |||
44 | post :login, :openid_url => existing_user.identity_url |
|
44 | post :login, :openid_url => existing_user.identity_url | |
45 | assert_redirected_to '/my/page' |
|
45 | assert_redirected_to '/my/page' | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_login_with_invalid_openid_provider |
|
48 | def test_login_with_invalid_openid_provider | |
49 | Setting.self_registration = '0' |
|
49 | Setting.self_registration = '0' | |
50 | post :login, :openid_url => 'http;//openid.example.com/good_user' |
|
50 | post :login, :openid_url => 'http;//openid.example.com/good_user' | |
51 | assert_redirected_to home_url |
|
51 | assert_redirected_to home_url | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def test_login_with_openid_for_existing_non_active_user |
|
54 | def test_login_with_openid_for_existing_non_active_user | |
55 | Setting.self_registration = '2' |
|
55 | Setting.self_registration = '2' | |
56 | existing_user = User.new(:firstname => 'Cool', |
|
56 | existing_user = User.new(:firstname => 'Cool', | |
57 | :lastname => 'User', |
|
57 | :lastname => 'User', | |
58 | :mail => 'user@somedomain.com', |
|
58 | :mail => 'user@somedomain.com', | |
59 | :identity_url => 'http://openid.example.com/good_user', |
|
59 | :identity_url => 'http://openid.example.com/good_user', | |
60 | :status => User::STATUS_REGISTERED) |
|
60 | :status => User::STATUS_REGISTERED) | |
61 | existing_user.login = 'cool_user' |
|
61 | existing_user.login = 'cool_user' | |
62 | assert existing_user.save! |
|
62 | assert existing_user.save! | |
63 |
|
63 | |||
64 | post :login, :openid_url => existing_user.identity_url |
|
64 | post :login, :openid_url => existing_user.identity_url | |
65 | assert_redirected_to '/login' |
|
65 | assert_redirected_to '/login' | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def test_login_with_openid_with_new_user_created |
|
68 | def test_login_with_openid_with_new_user_created | |
69 | Setting.self_registration = '3' |
|
69 | Setting.self_registration = '3' | |
70 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
70 | post :login, :openid_url => 'http://openid.example.com/good_user' | |
71 | assert_redirected_to '/my/account' |
|
71 | assert_redirected_to '/my/account' | |
72 | user = User.find_by_login('cool_user') |
|
72 | user = User.find_by_login('cool_user') | |
73 | assert user |
|
73 | assert user | |
74 | assert_equal 'Cool', user.firstname |
|
74 | assert_equal 'Cool', user.firstname | |
75 | assert_equal 'User', user.lastname |
|
75 | assert_equal 'User', user.lastname | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_login_with_openid_with_new_user_and_self_registration_off |
|
78 | def test_login_with_openid_with_new_user_and_self_registration_off | |
79 | Setting.self_registration = '0' |
|
79 | Setting.self_registration = '0' | |
80 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
80 | post :login, :openid_url => 'http://openid.example.com/good_user' | |
81 | assert_redirected_to home_url |
|
81 | assert_redirected_to home_url | |
82 | user = User.find_by_login('cool_user') |
|
82 | user = User.find_by_login('cool_user') | |
83 | assert_nil user |
|
83 | assert_nil user | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token |
|
86 | def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token | |
87 | Setting.self_registration = '1' |
|
87 | Setting.self_registration = '1' | |
88 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
88 | post :login, :openid_url => 'http://openid.example.com/good_user' | |
89 | assert_redirected_to '/login' |
|
89 | assert_redirected_to '/login' | |
90 | user = User.find_by_login('cool_user') |
|
90 | user = User.find_by_login('cool_user') | |
91 | assert user |
|
91 | assert user | |
92 |
|
92 | |||
93 | token = Token.find_by_user_id_and_action(user.id, 'register') |
|
93 | token = Token.find_by_user_id_and_action(user.id, 'register') | |
94 | assert token |
|
94 | assert token | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def test_login_with_openid_with_new_user_created_with_manual_activation |
|
97 | def test_login_with_openid_with_new_user_created_with_manual_activation | |
98 | Setting.self_registration = '2' |
|
98 | Setting.self_registration = '2' | |
99 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
99 | post :login, :openid_url => 'http://openid.example.com/good_user' | |
100 | assert_redirected_to '/login' |
|
100 | assert_redirected_to '/login' | |
101 | user = User.find_by_login('cool_user') |
|
101 | user = User.find_by_login('cool_user') | |
102 | assert user |
|
102 | assert user | |
103 | assert_equal User::STATUS_REGISTERED, user.status |
|
103 | assert_equal User::STATUS_REGISTERED, user.status | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | def test_login_with_openid_with_new_user_with_conflict_should_register |
|
106 | def test_login_with_openid_with_new_user_with_conflict_should_register | |
107 | Setting.self_registration = '3' |
|
107 | Setting.self_registration = '3' | |
108 | existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com') |
|
108 | existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com') | |
109 | existing_user.login = 'cool_user' |
|
109 | existing_user.login = 'cool_user' | |
110 | assert existing_user.save! |
|
110 | assert existing_user.save! | |
111 |
|
111 | |||
112 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
112 | post :login, :openid_url => 'http://openid.example.com/good_user' | |
113 | assert_response :success |
|
113 | assert_response :success | |
114 | assert_template 'register' |
|
114 | assert_template 'register' | |
115 | assert assigns(:user) |
|
115 | assert assigns(:user) | |
116 | assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url] |
|
116 | assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url] | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def test_login_with_openid_with_new_user_with_missing_information_should_register |
|
119 | def test_login_with_openid_with_new_user_with_missing_information_should_register | |
120 | Setting.self_registration = '3' |
|
120 | Setting.self_registration = '3' | |
121 |
|
121 | |||
122 | post :login, :openid_url => 'http://openid.example.com/good_blank_user' |
|
122 | post :login, :openid_url => 'http://openid.example.com/good_blank_user' | |
123 | assert_response :success |
|
123 | assert_response :success | |
124 | assert_template 'register' |
|
124 | assert_template 'register' | |
125 | assert assigns(:user) |
|
125 | assert assigns(:user) | |
126 | assert_equal 'http://openid.example.com/good_blank_user', assigns(:user)[:identity_url] |
|
126 | assert_equal 'http://openid.example.com/good_blank_user', assigns(:user)[:identity_url] | |
127 |
|
127 | |||
128 | assert_select 'input[name=?]', 'user[login]' |
|
128 | assert_select 'input[name=?]', 'user[login]' | |
129 | assert_select 'input[name=?]', 'user[password]' |
|
129 | assert_select 'input[name=?]', 'user[password]' | |
130 | assert_select 'input[name=?]', 'user[password_confirmation]' |
|
130 | assert_select 'input[name=?]', 'user[password_confirmation]' | |
131 | assert_select 'input[name=?][value=?]', 'user[identity_url]', 'http://openid.example.com/good_blank_user' |
|
131 | assert_select 'input[name=?][value=?]', 'user[identity_url]', 'http://openid.example.com/good_blank_user' | |
132 | end |
|
132 | end | |
133 |
|
133 | |||
134 | def test_post_login_should_not_verify_token_when_using_open_id |
|
134 | def test_post_login_should_not_verify_token_when_using_open_id | |
135 | ActionController::Base.allow_forgery_protection = true |
|
135 | ActionController::Base.allow_forgery_protection = true | |
136 | AccountController.any_instance.stubs(:using_open_id?).returns(true) |
|
136 | AccountController.any_instance.stubs(:using_open_id?).returns(true) | |
137 | AccountController.any_instance.stubs(:authenticate_with_open_id).returns(true) |
|
137 | AccountController.any_instance.stubs(:authenticate_with_open_id).returns(true) | |
138 | post :login |
|
138 | post :login | |
139 | assert_response 200 |
|
139 | assert_response 200 | |
140 | ensure |
|
140 | ensure | |
141 | ActionController::Base.allow_forgery_protection = false |
|
141 | ActionController::Base.allow_forgery_protection = false | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | def test_register_after_login_failure_should_not_require_user_to_enter_a_password |
|
144 | def test_register_after_login_failure_should_not_require_user_to_enter_a_password | |
145 | Setting.self_registration = '3' |
|
145 | Setting.self_registration = '3' | |
146 |
|
146 | |||
147 | assert_difference 'User.count' do |
|
147 | assert_difference 'User.count' do | |
148 | post :register, :user => { |
|
148 | post :register, :user => { | |
149 | :login => 'good_blank_user', |
|
149 | :login => 'good_blank_user', | |
150 | :password => '', |
|
150 | :password => '', | |
151 | :password_confirmation => '', |
|
151 | :password_confirmation => '', | |
152 | :firstname => 'Cool', |
|
152 | :firstname => 'Cool', | |
153 | :lastname => 'User', |
|
153 | :lastname => 'User', | |
154 | :mail => 'user@somedomain.com', |
|
154 | :mail => 'user@somedomain.com', | |
155 | :identity_url => 'http://openid.example.com/good_blank_user' |
|
155 | :identity_url => 'http://openid.example.com/good_blank_user' | |
156 | } |
|
156 | } | |
157 | assert_response 302 |
|
157 | assert_response 302 | |
158 | end |
|
158 | end | |
159 |
|
159 | |||
160 |
user = User. |
|
160 | user = User.order('id DESC').first | |
161 | assert_equal 'http://openid.example.com/good_blank_user', user.identity_url |
|
161 | assert_equal 'http://openid.example.com/good_blank_user', user.identity_url | |
162 | assert user.hashed_password.blank?, "Hashed password was #{user.hashed_password}" |
|
162 | assert user.hashed_password.blank?, "Hashed password was #{user.hashed_password}" | |
163 | end |
|
163 | end | |
164 |
|
164 | |||
165 | def test_setting_openid_should_return_true_when_set_to_true |
|
165 | def test_setting_openid_should_return_true_when_set_to_true | |
166 | assert_equal true, Setting.openid? |
|
166 | assert_equal true, Setting.openid? | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | else |
|
169 | else | |
170 | puts "Skipping openid tests." |
|
170 | puts "Skipping openid tests." | |
171 |
|
171 | |||
172 | def test_dummy |
|
172 | def test_dummy | |
173 | end |
|
173 | end | |
174 | end |
|
174 | end | |
175 | end |
|
175 | end |
General Comments 0
You need to be logged in to leave comments.
Login now