@@ -1,325 +1,326 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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 AccountTest < Redmine::IntegrationTest |
|
20 | class AccountTest < Redmine::IntegrationTest | |
21 | fixtures :users, :email_addresses, :roles |
|
21 | fixtures :users, :email_addresses, :roles | |
22 |
|
22 | |||
23 | def test_login |
|
23 | def test_login | |
24 | get "/my/page" |
|
24 | get "/my/page" | |
25 | assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage" |
|
25 | assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage" | |
26 | log_user('jsmith', 'jsmith') |
|
26 | log_user('jsmith', 'jsmith') | |
27 |
|
27 | |||
28 | get "/my/account" |
|
28 | get "/my/account" | |
29 | assert_response :success |
|
29 | assert_response :success | |
30 | assert_template "my/account" |
|
30 | assert_template "my/account" | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_autologin |
|
33 | def test_autologin | |
34 | user = User.find(1) |
|
34 | user = User.find(1) | |
35 | Setting.autologin = "7" |
|
35 | Setting.autologin = "7" | |
36 | Token.delete_all |
|
36 | Token.delete_all | |
37 |
|
37 | |||
38 | # User logs in with 'autologin' checked |
|
38 | # User logs in with 'autologin' checked | |
39 | post '/login', :username => user.login, :password => 'admin', :autologin => 1 |
|
39 | post '/login', :username => user.login, :password => 'admin', :autologin => 1 | |
40 | assert_redirected_to '/my/page' |
|
40 | assert_redirected_to '/my/page' | |
41 | token = Token.first |
|
41 | token = Token.first | |
42 | assert_not_nil token |
|
42 | assert_not_nil token | |
43 | assert_equal user, token.user |
|
43 | assert_equal user, token.user | |
44 | assert_equal 'autologin', token.action |
|
44 | assert_equal 'autologin', token.action | |
45 | assert_equal user.id, session[:user_id] |
|
45 | assert_equal user.id, session[:user_id] | |
46 | assert_equal token.value, cookies['autologin'] |
|
46 | assert_equal token.value, cookies['autologin'] | |
47 |
|
47 | |||
48 | # Session is cleared |
|
48 | # Session is cleared | |
49 | reset! |
|
49 | reset! | |
50 | User.current = nil |
|
50 | User.current = nil | |
51 | # Clears user's last login timestamp |
|
51 | # Clears user's last login timestamp | |
52 | user.update_attribute :last_login_on, nil |
|
52 | user.update_attribute :last_login_on, nil | |
53 | assert_nil user.reload.last_login_on |
|
53 | assert_nil user.reload.last_login_on | |
54 |
|
54 | |||
55 | # User comes back with user's autologin cookie |
|
55 | # User comes back with user's autologin cookie | |
56 | cookies[:autologin] = token.value |
|
56 | cookies[:autologin] = token.value | |
57 | get '/my/page' |
|
57 | get '/my/page' | |
58 | assert_response :success |
|
58 | assert_response :success | |
59 | assert_template 'my/page' |
|
59 | assert_template 'my/page' | |
60 | assert_equal user.id, session[:user_id] |
|
60 | assert_equal user.id, session[:user_id] | |
61 | assert_not_nil user.reload.last_login_on |
|
61 | assert_not_nil user.reload.last_login_on | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_autologin_should_use_autologin_cookie_name |
|
64 | def test_autologin_should_use_autologin_cookie_name | |
65 | Token.delete_all |
|
65 | Token.delete_all | |
66 | Redmine::Configuration.stubs(:[]).with('autologin_cookie_name').returns('custom_autologin') |
|
66 | Redmine::Configuration.stubs(:[]).with('autologin_cookie_name').returns('custom_autologin') | |
67 | Redmine::Configuration.stubs(:[]).with('autologin_cookie_path').returns('/') |
|
67 | Redmine::Configuration.stubs(:[]).with('autologin_cookie_path').returns('/') | |
68 | Redmine::Configuration.stubs(:[]).with('autologin_cookie_secure').returns(false) |
|
68 | Redmine::Configuration.stubs(:[]).with('autologin_cookie_secure').returns(false) | |
|
69 | Redmine::Configuration.stubs(:[]).with('sudo_mode_timeout').returns(15) | |||
69 |
|
70 | |||
70 | with_settings :autologin => '7' do |
|
71 | with_settings :autologin => '7' do | |
71 | assert_difference 'Token.count' do |
|
72 | assert_difference 'Token.count' do | |
72 | post '/login', :username => 'admin', :password => 'admin', :autologin => 1 |
|
73 | post '/login', :username => 'admin', :password => 'admin', :autologin => 1 | |
73 | end |
|
|||
74 | assert_response 302 |
|
74 | assert_response 302 | |
|
75 | end | |||
75 | assert cookies['custom_autologin'].present? |
|
76 | assert cookies['custom_autologin'].present? | |
76 | token = cookies['custom_autologin'] |
|
77 | token = cookies['custom_autologin'] | |
77 |
|
78 | |||
78 | # Session is cleared |
|
79 | # Session is cleared | |
79 | reset! |
|
80 | reset! | |
80 | cookies['custom_autologin'] = token |
|
81 | cookies['custom_autologin'] = token | |
81 | get '/my/page' |
|
82 | get '/my/page' | |
82 | assert_response :success |
|
83 | assert_response :success | |
83 |
|
84 | |||
84 | assert_difference 'Token.count', -1 do |
|
85 | assert_difference 'Token.count', -1 do | |
85 | post '/logout' |
|
86 | post '/logout' | |
86 | end |
|
87 | end | |
87 | assert cookies['custom_autologin'].blank? |
|
88 | assert cookies['custom_autologin'].blank? | |
88 | end |
|
89 | end | |
89 | end |
|
90 | end | |
90 |
|
91 | |||
91 | def test_lost_password |
|
92 | def test_lost_password | |
92 | Token.delete_all |
|
93 | Token.delete_all | |
93 |
|
94 | |||
94 | get "/account/lost_password" |
|
95 | get "/account/lost_password" | |
95 | assert_response :success |
|
96 | assert_response :success | |
96 | assert_template "account/lost_password" |
|
97 | assert_template "account/lost_password" | |
97 | assert_select 'input[name=mail]' |
|
98 | assert_select 'input[name=mail]' | |
98 |
|
99 | |||
99 | post "/account/lost_password", :mail => 'jSmith@somenet.foo' |
|
100 | post "/account/lost_password", :mail => 'jSmith@somenet.foo' | |
100 | assert_redirected_to "/login" |
|
101 | assert_redirected_to "/login" | |
101 |
|
102 | |||
102 | token = Token.first |
|
103 | token = Token.first | |
103 | assert_equal 'recovery', token.action |
|
104 | assert_equal 'recovery', token.action | |
104 | assert_equal 'jsmith@somenet.foo', token.user.mail |
|
105 | assert_equal 'jsmith@somenet.foo', token.user.mail | |
105 | assert !token.expired? |
|
106 | assert !token.expired? | |
106 |
|
107 | |||
107 | get "/account/lost_password", :token => token.value |
|
108 | get "/account/lost_password", :token => token.value | |
108 | assert_response :success |
|
109 | assert_response :success | |
109 | assert_template "account/password_recovery" |
|
110 | assert_template "account/password_recovery" | |
110 | assert_select 'input[type=hidden][name=token][value=?]', token.value |
|
111 | assert_select 'input[type=hidden][name=token][value=?]', token.value | |
111 | assert_select 'input[name=new_password]' |
|
112 | assert_select 'input[name=new_password]' | |
112 | assert_select 'input[name=new_password_confirmation]' |
|
113 | assert_select 'input[name=new_password_confirmation]' | |
113 |
|
114 | |||
114 | post "/account/lost_password", |
|
115 | post "/account/lost_password", | |
115 | :token => token.value, :new_password => 'newpass123', |
|
116 | :token => token.value, :new_password => 'newpass123', | |
116 | :new_password_confirmation => 'newpass123' |
|
117 | :new_password_confirmation => 'newpass123' | |
117 | assert_redirected_to "/login" |
|
118 | assert_redirected_to "/login" | |
118 | assert_equal 'Password was successfully updated.', flash[:notice] |
|
119 | assert_equal 'Password was successfully updated.', flash[:notice] | |
119 |
|
120 | |||
120 | log_user('jsmith', 'newpass123') |
|
121 | log_user('jsmith', 'newpass123') | |
121 | assert_equal 0, Token.count |
|
122 | assert_equal 0, Token.count | |
122 | end |
|
123 | end | |
123 |
|
124 | |||
124 | def test_user_with_must_change_passwd_should_be_forced_to_change_its_password |
|
125 | def test_user_with_must_change_passwd_should_be_forced_to_change_its_password | |
125 | User.find_by_login('jsmith').update_attribute :must_change_passwd, true |
|
126 | User.find_by_login('jsmith').update_attribute :must_change_passwd, true | |
126 |
|
127 | |||
127 | post '/login', :username => 'jsmith', :password => 'jsmith' |
|
128 | post '/login', :username => 'jsmith', :password => 'jsmith' | |
128 | assert_redirected_to '/my/page' |
|
129 | assert_redirected_to '/my/page' | |
129 | follow_redirect! |
|
130 | follow_redirect! | |
130 | assert_redirected_to '/my/password' |
|
131 | assert_redirected_to '/my/password' | |
131 |
|
132 | |||
132 | get '/issues' |
|
133 | get '/issues' | |
133 | assert_redirected_to '/my/password' |
|
134 | assert_redirected_to '/my/password' | |
134 | end |
|
135 | end | |
135 |
|
136 | |||
136 | def test_user_with_must_change_passwd_should_be_able_to_change_its_password |
|
137 | def test_user_with_must_change_passwd_should_be_able_to_change_its_password | |
137 | User.find_by_login('jsmith').update_attribute :must_change_passwd, true |
|
138 | User.find_by_login('jsmith').update_attribute :must_change_passwd, true | |
138 |
|
139 | |||
139 | post '/login', :username => 'jsmith', :password => 'jsmith' |
|
140 | post '/login', :username => 'jsmith', :password => 'jsmith' | |
140 | assert_redirected_to '/my/page' |
|
141 | assert_redirected_to '/my/page' | |
141 | follow_redirect! |
|
142 | follow_redirect! | |
142 | assert_redirected_to '/my/password' |
|
143 | assert_redirected_to '/my/password' | |
143 | follow_redirect! |
|
144 | follow_redirect! | |
144 | assert_response :success |
|
145 | assert_response :success | |
145 | post '/my/password', :password => 'jsmith', :new_password => 'newpassword', :new_password_confirmation => 'newpassword' |
|
146 | post '/my/password', :password => 'jsmith', :new_password => 'newpassword', :new_password_confirmation => 'newpassword' | |
146 | assert_redirected_to '/my/account' |
|
147 | assert_redirected_to '/my/account' | |
147 | follow_redirect! |
|
148 | follow_redirect! | |
148 | assert_response :success |
|
149 | assert_response :success | |
149 |
|
150 | |||
150 | assert_equal false, User.find_by_login('jsmith').must_change_passwd? |
|
151 | assert_equal false, User.find_by_login('jsmith').must_change_passwd? | |
151 | end |
|
152 | end | |
152 |
|
153 | |||
153 | def test_user_with_expired_password_should_be_forced_to_change_its_password |
|
154 | def test_user_with_expired_password_should_be_forced_to_change_its_password | |
154 | User.find_by_login('jsmith').update_attribute :passwd_changed_on, 14.days.ago |
|
155 | User.find_by_login('jsmith').update_attribute :passwd_changed_on, 14.days.ago | |
155 |
|
156 | |||
156 | with_settings :password_max_age => 7 do |
|
157 | with_settings :password_max_age => 7 do | |
157 | post '/login', :username => 'jsmith', :password => 'jsmith' |
|
158 | post '/login', :username => 'jsmith', :password => 'jsmith' | |
158 | assert_redirected_to '/my/page' |
|
159 | assert_redirected_to '/my/page' | |
159 | follow_redirect! |
|
160 | follow_redirect! | |
160 | assert_redirected_to '/my/password' |
|
161 | assert_redirected_to '/my/password' | |
161 |
|
162 | |||
162 | get '/issues' |
|
163 | get '/issues' | |
163 | assert_redirected_to '/my/password' |
|
164 | assert_redirected_to '/my/password' | |
164 | end |
|
165 | end | |
165 | end |
|
166 | end | |
166 |
|
167 | |||
167 | def test_user_with_expired_password_should_be_able_to_change_its_password |
|
168 | def test_user_with_expired_password_should_be_able_to_change_its_password | |
168 | User.find_by_login('jsmith').update_attribute :passwd_changed_on, 14.days.ago |
|
169 | User.find_by_login('jsmith').update_attribute :passwd_changed_on, 14.days.ago | |
169 |
|
170 | |||
170 | with_settings :password_max_age => 7 do |
|
171 | with_settings :password_max_age => 7 do | |
171 | post '/login', :username => 'jsmith', :password => 'jsmith' |
|
172 | post '/login', :username => 'jsmith', :password => 'jsmith' | |
172 | assert_redirected_to '/my/page' |
|
173 | assert_redirected_to '/my/page' | |
173 | follow_redirect! |
|
174 | follow_redirect! | |
174 | assert_redirected_to '/my/password' |
|
175 | assert_redirected_to '/my/password' | |
175 | follow_redirect! |
|
176 | follow_redirect! | |
176 | assert_response :success |
|
177 | assert_response :success | |
177 | post '/my/password', :password => 'jsmith', :new_password => 'newpassword', :new_password_confirmation => 'newpassword' |
|
178 | post '/my/password', :password => 'jsmith', :new_password => 'newpassword', :new_password_confirmation => 'newpassword' | |
178 | assert_redirected_to '/my/account' |
|
179 | assert_redirected_to '/my/account' | |
179 | follow_redirect! |
|
180 | follow_redirect! | |
180 | assert_response :success |
|
181 | assert_response :success | |
181 |
|
182 | |||
182 | assert_equal false, User.find_by_login('jsmith').must_change_passwd? |
|
183 | assert_equal false, User.find_by_login('jsmith').must_change_passwd? | |
183 | end |
|
184 | end | |
184 |
|
185 | |||
185 | end |
|
186 | end | |
186 |
|
187 | |||
187 | def test_register_with_automatic_activation |
|
188 | def test_register_with_automatic_activation | |
188 | Setting.self_registration = '3' |
|
189 | Setting.self_registration = '3' | |
189 |
|
190 | |||
190 | get '/account/register' |
|
191 | get '/account/register' | |
191 | assert_response :success |
|
192 | assert_response :success | |
192 | assert_template 'account/register' |
|
193 | assert_template 'account/register' | |
193 |
|
194 | |||
194 | post '/account/register', |
|
195 | post '/account/register', | |
195 | :user => {:login => "newuser", :language => "en", |
|
196 | :user => {:login => "newuser", :language => "en", | |
196 | :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar", |
|
197 | :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar", | |
197 | :password => "newpass123", :password_confirmation => "newpass123"} |
|
198 | :password => "newpass123", :password_confirmation => "newpass123"} | |
198 | assert_redirected_to '/my/account' |
|
199 | assert_redirected_to '/my/account' | |
199 | follow_redirect! |
|
200 | follow_redirect! | |
200 | assert_response :success |
|
201 | assert_response :success | |
201 | assert_template 'my/account' |
|
202 | assert_template 'my/account' | |
202 |
|
203 | |||
203 | user = User.find_by_login('newuser') |
|
204 | user = User.find_by_login('newuser') | |
204 | assert_not_nil user |
|
205 | assert_not_nil user | |
205 | assert user.active? |
|
206 | assert user.active? | |
206 | assert_not_nil user.last_login_on |
|
207 | assert_not_nil user.last_login_on | |
207 | end |
|
208 | end | |
208 |
|
209 | |||
209 | def test_register_with_manual_activation |
|
210 | def test_register_with_manual_activation | |
210 | Setting.self_registration = '2' |
|
211 | Setting.self_registration = '2' | |
211 |
|
212 | |||
212 | post '/account/register', |
|
213 | post '/account/register', | |
213 | :user => {:login => "newuser", :language => "en", |
|
214 | :user => {:login => "newuser", :language => "en", | |
214 | :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar", |
|
215 | :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar", | |
215 | :password => "newpass123", :password_confirmation => "newpass123"} |
|
216 | :password => "newpass123", :password_confirmation => "newpass123"} | |
216 | assert_redirected_to '/login' |
|
217 | assert_redirected_to '/login' | |
217 | assert !User.find_by_login('newuser').active? |
|
218 | assert !User.find_by_login('newuser').active? | |
218 | end |
|
219 | end | |
219 |
|
220 | |||
220 | def test_register_with_email_activation |
|
221 | def test_register_with_email_activation | |
221 | Setting.self_registration = '1' |
|
222 | Setting.self_registration = '1' | |
222 | Token.delete_all |
|
223 | Token.delete_all | |
223 |
|
224 | |||
224 | post '/account/register', |
|
225 | post '/account/register', | |
225 | :user => {:login => "newuser", :language => "en", |
|
226 | :user => {:login => "newuser", :language => "en", | |
226 | :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar", |
|
227 | :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar", | |
227 | :password => "newpass123", :password_confirmation => "newpass123"} |
|
228 | :password => "newpass123", :password_confirmation => "newpass123"} | |
228 | assert_redirected_to '/login' |
|
229 | assert_redirected_to '/login' | |
229 | assert !User.find_by_login('newuser').active? |
|
230 | assert !User.find_by_login('newuser').active? | |
230 |
|
231 | |||
231 | token = Token.first |
|
232 | token = Token.first | |
232 | assert_equal 'register', token.action |
|
233 | assert_equal 'register', token.action | |
233 | assert_equal 'newuser@foo.bar', token.user.mail |
|
234 | assert_equal 'newuser@foo.bar', token.user.mail | |
234 | assert !token.expired? |
|
235 | assert !token.expired? | |
235 |
|
236 | |||
236 | get '/account/activate', :token => token.value |
|
237 | get '/account/activate', :token => token.value | |
237 | assert_redirected_to '/login' |
|
238 | assert_redirected_to '/login' | |
238 | log_user('newuser', 'newpass123') |
|
239 | log_user('newuser', 'newpass123') | |
239 | end |
|
240 | end | |
240 |
|
241 | |||
241 | def test_onthefly_registration |
|
242 | def test_onthefly_registration | |
242 | # disable registration |
|
243 | # disable registration | |
243 | Setting.self_registration = '0' |
|
244 | Setting.self_registration = '0' | |
244 | AuthSource.expects(:authenticate).returns( |
|
245 | AuthSource.expects(:authenticate).returns( | |
245 | {:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', |
|
246 | {:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', | |
246 | :mail => 'foo@bar.com', :auth_source_id => 66}) |
|
247 | :mail => 'foo@bar.com', :auth_source_id => 66}) | |
247 |
|
248 | |||
248 | post '/login', :username => 'foo', :password => 'bar' |
|
249 | post '/login', :username => 'foo', :password => 'bar' | |
249 | assert_redirected_to '/my/page' |
|
250 | assert_redirected_to '/my/page' | |
250 |
|
251 | |||
251 | user = User.find_by_login('foo') |
|
252 | user = User.find_by_login('foo') | |
252 | assert user.is_a?(User) |
|
253 | assert user.is_a?(User) | |
253 | assert_equal 66, user.auth_source_id |
|
254 | assert_equal 66, user.auth_source_id | |
254 | assert user.hashed_password.blank? |
|
255 | assert user.hashed_password.blank? | |
255 | end |
|
256 | end | |
256 |
|
257 | |||
257 | def test_onthefly_registration_with_invalid_attributes |
|
258 | def test_onthefly_registration_with_invalid_attributes | |
258 | # disable registration |
|
259 | # disable registration | |
259 | Setting.self_registration = '0' |
|
260 | Setting.self_registration = '0' | |
260 | AuthSource.expects(:authenticate).returns( |
|
261 | AuthSource.expects(:authenticate).returns( | |
261 | {:login => 'foo', :lastname => 'Smith', :auth_source_id => 66}) |
|
262 | {:login => 'foo', :lastname => 'Smith', :auth_source_id => 66}) | |
262 |
|
263 | |||
263 | post '/login', :username => 'foo', :password => 'bar' |
|
264 | post '/login', :username => 'foo', :password => 'bar' | |
264 | assert_response :success |
|
265 | assert_response :success | |
265 | assert_template 'account/register' |
|
266 | assert_template 'account/register' | |
266 | assert_select 'input[name=?][value=""]', 'user[firstname]' |
|
267 | assert_select 'input[name=?][value=""]', 'user[firstname]' | |
267 | assert_select 'input[name=?][value=Smith]', 'user[lastname]' |
|
268 | assert_select 'input[name=?][value=Smith]', 'user[lastname]' | |
268 | assert_select 'input[name=?]', 'user[login]', 0 |
|
269 | assert_select 'input[name=?]', 'user[login]', 0 | |
269 | assert_select 'input[name=?]', 'user[password]', 0 |
|
270 | assert_select 'input[name=?]', 'user[password]', 0 | |
270 |
|
271 | |||
271 | post '/account/register', |
|
272 | post '/account/register', | |
272 | :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'} |
|
273 | :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'} | |
273 | assert_redirected_to '/my/account' |
|
274 | assert_redirected_to '/my/account' | |
274 |
|
275 | |||
275 | user = User.find_by_login('foo') |
|
276 | user = User.find_by_login('foo') | |
276 | assert user.is_a?(User) |
|
277 | assert user.is_a?(User) | |
277 | assert_equal 66, user.auth_source_id |
|
278 | assert_equal 66, user.auth_source_id | |
278 | assert user.hashed_password.blank? |
|
279 | assert user.hashed_password.blank? | |
279 | end |
|
280 | end | |
280 |
|
281 | |||
281 | def test_registered_user_should_be_able_to_get_a_new_activation_email |
|
282 | def test_registered_user_should_be_able_to_get_a_new_activation_email | |
282 | Token.delete_all |
|
283 | Token.delete_all | |
283 |
|
284 | |||
284 | with_settings :self_registration => '1', :default_language => 'en' do |
|
285 | with_settings :self_registration => '1', :default_language => 'en' do | |
285 | # register a new account |
|
286 | # register a new account | |
286 | assert_difference 'User.count' do |
|
287 | assert_difference 'User.count' do | |
287 | assert_difference 'Token.count' do |
|
288 | assert_difference 'Token.count' do | |
288 | post '/account/register', |
|
289 | post '/account/register', | |
289 | :user => {:login => "newuser", :language => "en", |
|
290 | :user => {:login => "newuser", :language => "en", | |
290 | :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar", |
|
291 | :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar", | |
291 | :password => "newpass123", :password_confirmation => "newpass123"} |
|
292 | :password => "newpass123", :password_confirmation => "newpass123"} | |
292 | end |
|
293 | end | |
293 | end |
|
294 | end | |
294 | user = User.order('id desc').first |
|
295 | user = User.order('id desc').first | |
295 | assert_equal User::STATUS_REGISTERED, user.status |
|
296 | assert_equal User::STATUS_REGISTERED, user.status | |
296 | reset! |
|
297 | reset! | |
297 |
|
298 | |||
298 | # try to use "lost password" |
|
299 | # try to use "lost password" | |
299 | assert_no_difference 'ActionMailer::Base.deliveries.size' do |
|
300 | assert_no_difference 'ActionMailer::Base.deliveries.size' do | |
300 | post '/account/lost_password', :mail => 'newuser@foo.bar' |
|
301 | post '/account/lost_password', :mail => 'newuser@foo.bar' | |
301 | end |
|
302 | end | |
302 | assert_redirected_to '/account/lost_password' |
|
303 | assert_redirected_to '/account/lost_password' | |
303 | follow_redirect! |
|
304 | follow_redirect! | |
304 | assert_response :success |
|
305 | assert_response :success | |
305 | assert_select 'div.flash', :text => /new activation email/ |
|
306 | assert_select 'div.flash', :text => /new activation email/ | |
306 | assert_select 'div.flash a[href="/account/activation_email"]' |
|
307 | assert_select 'div.flash a[href="/account/activation_email"]' | |
307 |
|
308 | |||
308 | # request a new action activation email |
|
309 | # request a new action activation email | |
309 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
310 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
310 | get '/account/activation_email' |
|
311 | get '/account/activation_email' | |
311 | end |
|
312 | end | |
312 | assert_redirected_to '/login' |
|
313 | assert_redirected_to '/login' | |
313 | token = Token.order('id desc').first |
|
314 | token = Token.order('id desc').first | |
314 | activation_path = "/account/activate?token=#{token.value}" |
|
315 | activation_path = "/account/activate?token=#{token.value}" | |
315 | assert_include activation_path, mail_body(ActionMailer::Base.deliveries.last) |
|
316 | assert_include activation_path, mail_body(ActionMailer::Base.deliveries.last) | |
316 |
|
317 | |||
317 | # activate the account |
|
318 | # activate the account | |
318 | get activation_path |
|
319 | get activation_path | |
319 | assert_redirected_to '/login' |
|
320 | assert_redirected_to '/login' | |
320 |
|
321 | |||
321 | post '/login', :username => 'newuser', :password => 'newpass123' |
|
322 | post '/login', :username => 'newuser', :password => 'newpass123' | |
322 | assert_redirected_to '/my/page' |
|
323 | assert_redirected_to '/my/page' | |
323 | end |
|
324 | end | |
324 | end |
|
325 | end | |
325 | end |
|
326 | end |
General Comments 0
You need to be logged in to leave comments.
Login now