Mercurial > hg > soundsoftware-site
comparison .svn/pristine/91/91db92d5f8c4cd8c1392a3d4def27437c7f826a5.svn-base @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../test_helper', __FILE__) | |
19 | |
20 class AccountControllerTest < ActionController::TestCase | |
21 fixtures :users, :roles | |
22 | |
23 def setup | |
24 User.current = nil | |
25 end | |
26 | |
27 def test_get_login | |
28 get :login | |
29 assert_response :success | |
30 assert_template 'login' | |
31 | |
32 assert_select 'input[name=username]' | |
33 assert_select 'input[name=password]' | |
34 end | |
35 | |
36 def test_get_login_while_logged_in_should_redirect_to_home | |
37 @request.session[:user_id] = 2 | |
38 | |
39 get :login | |
40 assert_redirected_to '/' | |
41 assert_equal 2, @request.session[:user_id] | |
42 end | |
43 | |
44 def test_login_should_redirect_to_back_url_param | |
45 # request.uri is "test.host" in test environment | |
46 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.host/issues/show/1' | |
47 assert_redirected_to '/issues/show/1' | |
48 end | |
49 | |
50 def test_login_should_not_redirect_to_another_host | |
51 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.foo/fake' | |
52 assert_redirected_to '/my/page' | |
53 end | |
54 | |
55 def test_login_with_wrong_password | |
56 post :login, :username => 'admin', :password => 'bad' | |
57 assert_response :success | |
58 assert_template 'login' | |
59 | |
60 assert_select 'div.flash.error', :text => /Invalid user or password/ | |
61 assert_select 'input[name=username][value=admin]' | |
62 assert_select 'input[name=password]' | |
63 assert_select 'input[name=password][value]', 0 | |
64 end | |
65 | |
66 def test_login_should_rescue_auth_source_exception | |
67 source = AuthSource.create!(:name => 'Test') | |
68 User.find(2).update_attribute :auth_source_id, source.id | |
69 AuthSource.any_instance.stubs(:authenticate).raises(AuthSourceException.new("Something wrong")) | |
70 | |
71 post :login, :username => 'jsmith', :password => 'jsmith' | |
72 assert_response 500 | |
73 assert_error_tag :content => /Something wrong/ | |
74 end | |
75 | |
76 def test_login_should_reset_session | |
77 @controller.expects(:reset_session).once | |
78 | |
79 post :login, :username => 'jsmith', :password => 'jsmith' | |
80 assert_response 302 | |
81 end | |
82 | |
83 def test_get_logout_should_not_logout | |
84 @request.session[:user_id] = 2 | |
85 get :logout | |
86 assert_response :success | |
87 assert_template 'logout' | |
88 | |
89 assert_equal 2, @request.session[:user_id] | |
90 end | |
91 | |
92 def test_logout | |
93 @request.session[:user_id] = 2 | |
94 post :logout | |
95 assert_redirected_to '/' | |
96 assert_nil @request.session[:user_id] | |
97 end | |
98 | |
99 def test_logout_should_reset_session | |
100 @controller.expects(:reset_session).once | |
101 | |
102 @request.session[:user_id] = 2 | |
103 post :logout | |
104 assert_response 302 | |
105 end | |
106 | |
107 def test_get_register_with_registration_on | |
108 with_settings :self_registration => '3' do | |
109 get :register | |
110 assert_response :success | |
111 assert_template 'register' | |
112 assert_not_nil assigns(:user) | |
113 | |
114 assert_select 'input[name=?]', 'user[password]' | |
115 assert_select 'input[name=?]', 'user[password_confirmation]' | |
116 end | |
117 end | |
118 | |
119 def test_get_register_should_detect_user_language | |
120 with_settings :self_registration => '3' do | |
121 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' | |
122 get :register | |
123 assert_response :success | |
124 assert_not_nil assigns(:user) | |
125 assert_equal 'fr', assigns(:user).language | |
126 assert_select 'select[name=?]', 'user[language]' do | |
127 assert_select 'option[value=fr][selected=selected]' | |
128 end | |
129 end | |
130 end | |
131 | |
132 def test_get_register_with_registration_off_should_redirect | |
133 with_settings :self_registration => '0' do | |
134 get :register | |
135 assert_redirected_to '/' | |
136 end | |
137 end | |
138 | |
139 # See integration/account_test.rb for the full test | |
140 def test_post_register_with_registration_on | |
141 with_settings :self_registration => '3' do | |
142 assert_difference 'User.count' do | |
143 post :register, :user => { | |
144 :login => 'register', | |
145 :password => 'secret123', | |
146 :password_confirmation => 'secret123', | |
147 :firstname => 'John', | |
148 :lastname => 'Doe', | |
149 :mail => 'register@example.com' | |
150 } | |
151 assert_redirected_to '/my/account' | |
152 end | |
153 user = User.first(:order => 'id DESC') | |
154 assert_equal 'register', user.login | |
155 assert_equal 'John', user.firstname | |
156 assert_equal 'Doe', user.lastname | |
157 assert_equal 'register@example.com', user.mail | |
158 assert user.check_password?('secret123') | |
159 assert user.active? | |
160 end | |
161 end | |
162 | |
163 def test_post_register_with_registration_off_should_redirect | |
164 with_settings :self_registration => '0' do | |
165 assert_no_difference 'User.count' do | |
166 post :register, :user => { | |
167 :login => 'register', | |
168 :password => 'test', | |
169 :password_confirmation => 'test', | |
170 :firstname => 'John', | |
171 :lastname => 'Doe', | |
172 :mail => 'register@example.com' | |
173 } | |
174 assert_redirected_to '/' | |
175 end | |
176 end | |
177 end | |
178 | |
179 def test_get_lost_password_should_display_lost_password_form | |
180 get :lost_password | |
181 assert_response :success | |
182 assert_select 'input[name=mail]' | |
183 end | |
184 | |
185 def test_lost_password_for_active_user_should_create_a_token | |
186 Token.delete_all | |
187 ActionMailer::Base.deliveries.clear | |
188 assert_difference 'ActionMailer::Base.deliveries.size' do | |
189 assert_difference 'Token.count' do | |
190 with_settings :host_name => 'mydomain.foo', :protocol => 'http' do | |
191 post :lost_password, :mail => 'JSmith@somenet.foo' | |
192 assert_redirected_to '/login' | |
193 end | |
194 end | |
195 end | |
196 | |
197 token = Token.order('id DESC').first | |
198 assert_equal User.find(2), token.user | |
199 assert_equal 'recovery', token.action | |
200 | |
201 assert_select_email do | |
202 assert_select "a[href=?]", "http://mydomain.foo/account/lost_password?token=#{token.value}" | |
203 end | |
204 end | |
205 | |
206 def test_lost_password_for_unknown_user_should_fail | |
207 Token.delete_all | |
208 assert_no_difference 'Token.count' do | |
209 post :lost_password, :mail => 'invalid@somenet.foo' | |
210 assert_response :success | |
211 end | |
212 end | |
213 | |
214 def test_lost_password_for_non_active_user_should_fail | |
215 Token.delete_all | |
216 assert User.find(2).lock! | |
217 | |
218 assert_no_difference 'Token.count' do | |
219 post :lost_password, :mail => 'JSmith@somenet.foo' | |
220 assert_response :success | |
221 end | |
222 end | |
223 | |
224 def test_get_lost_password_with_token_should_display_the_password_recovery_form | |
225 user = User.find(2) | |
226 token = Token.create!(:action => 'recovery', :user => user) | |
227 | |
228 get :lost_password, :token => token.value | |
229 assert_response :success | |
230 assert_template 'password_recovery' | |
231 | |
232 assert_select 'input[type=hidden][name=token][value=?]', token.value | |
233 end | |
234 | |
235 def test_get_lost_password_with_invalid_token_should_redirect | |
236 get :lost_password, :token => "abcdef" | |
237 assert_redirected_to '/' | |
238 end | |
239 | |
240 def test_post_lost_password_with_token_should_change_the_user_password | |
241 user = User.find(2) | |
242 token = Token.create!(:action => 'recovery', :user => user) | |
243 | |
244 post :lost_password, :token => token.value, :new_password => 'newpass123', :new_password_confirmation => 'newpass123' | |
245 assert_redirected_to '/login' | |
246 user.reload | |
247 assert user.check_password?('newpass123') | |
248 assert_nil Token.find_by_id(token.id), "Token was not deleted" | |
249 end | |
250 | |
251 def test_post_lost_password_with_token_for_non_active_user_should_fail | |
252 user = User.find(2) | |
253 token = Token.create!(:action => 'recovery', :user => user) | |
254 user.lock! | |
255 | |
256 post :lost_password, :token => token.value, :new_password => 'newpass123', :new_password_confirmation => 'newpass123' | |
257 assert_redirected_to '/' | |
258 assert ! user.check_password?('newpass123') | |
259 end | |
260 | |
261 def test_post_lost_password_with_token_and_password_confirmation_failure_should_redisplay_the_form | |
262 user = User.find(2) | |
263 token = Token.create!(:action => 'recovery', :user => user) | |
264 | |
265 post :lost_password, :token => token.value, :new_password => 'newpass', :new_password_confirmation => 'wrongpass' | |
266 assert_response :success | |
267 assert_template 'password_recovery' | |
268 assert_not_nil Token.find_by_id(token.id), "Token was deleted" | |
269 | |
270 assert_select 'input[type=hidden][name=token][value=?]', token.value | |
271 end | |
272 | |
273 def test_post_lost_password_with_invalid_token_should_redirect | |
274 post :lost_password, :token => "abcdef", :new_password => 'newpass', :new_password_confirmation => 'newpass' | |
275 assert_redirected_to '/' | |
276 end | |
277 end |