@@ -1,16 +1,16 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 |
# |
|
|
8 | # | |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 |
# |
|
|
13 | # | |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
@@ -31,17 +31,17 class AccountTest < ActionController::IntegrationTest | |||
|
31 | 31 | get "my/page" |
|
32 | 32 | assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage" |
|
33 | 33 | log_user('jsmith', 'jsmith') |
|
34 | ||
|
34 | ||
|
35 | 35 | get "my/account" |
|
36 | 36 | assert_response :success |
|
37 |
assert_template "my/account" |
|
|
37 | assert_template "my/account" | |
|
38 | 38 | end |
|
39 | ||
|
39 | ||
|
40 | 40 | def test_autologin |
|
41 | 41 | user = User.find(1) |
|
42 | 42 | Setting.autologin = "7" |
|
43 | 43 | Token.delete_all |
|
44 | ||
|
44 | ||
|
45 | 45 | # User logs in with 'autologin' checked |
|
46 | 46 | post '/login', :username => user.login, :password => 'admin', :autologin => 1 |
|
47 | 47 | assert_redirected_to '/my/page' |
@@ -51,14 +51,14 class AccountTest < ActionController::IntegrationTest | |||
|
51 | 51 | assert_equal 'autologin', token.action |
|
52 | 52 | assert_equal user.id, session[:user_id] |
|
53 | 53 | assert_equal token.value, cookies['autologin'] |
|
54 | ||
|
54 | ||
|
55 | 55 | # Session is cleared |
|
56 | 56 | reset! |
|
57 | 57 | User.current = nil |
|
58 | 58 | # Clears user's last login timestamp |
|
59 | 59 | user.update_attribute :last_login_on, nil |
|
60 | 60 | assert_nil user.reload.last_login_on |
|
61 | ||
|
61 | ||
|
62 | 62 | # User comes back with his autologin cookie |
|
63 | 63 | cookies[:autologin] = token.value |
|
64 | 64 | get '/my/page' |
@@ -68,103 +68,103 class AccountTest < ActionController::IntegrationTest | |||
|
68 | 68 | assert_not_nil user.reload.last_login_on |
|
69 | 69 | assert user.last_login_on.utc > 10.second.ago.utc |
|
70 | 70 | end |
|
71 | ||
|
71 | ||
|
72 | 72 | def test_lost_password |
|
73 | 73 | Token.delete_all |
|
74 | ||
|
74 | ||
|
75 | 75 | get "account/lost_password" |
|
76 | 76 | assert_response :success |
|
77 | 77 | assert_template "account/lost_password" |
|
78 | ||
|
78 | ||
|
79 | 79 | post "account/lost_password", :mail => 'jSmith@somenet.foo' |
|
80 | 80 | assert_redirected_to "/login" |
|
81 | ||
|
81 | ||
|
82 | 82 | token = Token.find(:first) |
|
83 | 83 | assert_equal 'recovery', token.action |
|
84 | 84 | assert_equal 'jsmith@somenet.foo', token.user.mail |
|
85 | 85 | assert !token.expired? |
|
86 | ||
|
86 | ||
|
87 | 87 | get "account/lost_password", :token => token.value |
|
88 | 88 | assert_response :success |
|
89 | 89 | assert_template "account/password_recovery" |
|
90 | ||
|
90 | ||
|
91 | 91 | post "account/lost_password", :token => token.value, :new_password => 'newpass', :new_password_confirmation => 'newpass' |
|
92 | 92 | assert_redirected_to "/login" |
|
93 | 93 | assert_equal 'Password was successfully updated.', flash[:notice] |
|
94 | ||
|
94 | ||
|
95 | 95 | log_user('jsmith', 'newpass') |
|
96 |
assert_equal 0, Token.count |
|
|
96 | assert_equal 0, Token.count | |
|
97 | 97 | end |
|
98 | ||
|
98 | ||
|
99 | 99 | def test_register_with_automatic_activation |
|
100 | 100 | Setting.self_registration = '3' |
|
101 | ||
|
101 | ||
|
102 | 102 | get 'account/register' |
|
103 | 103 | assert_response :success |
|
104 | 104 | assert_template 'account/register' |
|
105 | ||
|
106 |
post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"}, |
|
|
105 | ||
|
106 | post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"}, | |
|
107 | 107 | :password => "newpass", :password_confirmation => "newpass" |
|
108 | 108 | assert_redirected_to '/my/account' |
|
109 | 109 | follow_redirect! |
|
110 | 110 | assert_response :success |
|
111 | 111 | assert_template 'my/account' |
|
112 | ||
|
112 | ||
|
113 | 113 | user = User.find_by_login('newuser') |
|
114 | 114 | assert_not_nil user |
|
115 | 115 | assert user.active? |
|
116 | 116 | assert_not_nil user.last_login_on |
|
117 | 117 | end |
|
118 | ||
|
118 | ||
|
119 | 119 | def test_register_with_manual_activation |
|
120 | 120 | Setting.self_registration = '2' |
|
121 | ||
|
122 |
post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"}, |
|
|
121 | ||
|
122 | post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"}, | |
|
123 | 123 | :password => "newpass", :password_confirmation => "newpass" |
|
124 | 124 | assert_redirected_to '/login' |
|
125 | 125 | assert !User.find_by_login('newuser').active? |
|
126 | 126 | end |
|
127 | ||
|
127 | ||
|
128 | 128 | def test_register_with_email_activation |
|
129 | 129 | Setting.self_registration = '1' |
|
130 | 130 | Token.delete_all |
|
131 | ||
|
132 |
post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"}, |
|
|
131 | ||
|
132 | post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"}, | |
|
133 | 133 | :password => "newpass", :password_confirmation => "newpass" |
|
134 | 134 | assert_redirected_to '/login' |
|
135 | 135 | assert !User.find_by_login('newuser').active? |
|
136 | ||
|
136 | ||
|
137 | 137 | token = Token.find(:first) |
|
138 | 138 | assert_equal 'register', token.action |
|
139 | 139 | assert_equal 'newuser@foo.bar', token.user.mail |
|
140 | 140 | assert !token.expired? |
|
141 | ||
|
141 | ||
|
142 | 142 | get 'account/activate', :token => token.value |
|
143 | 143 | assert_redirected_to '/login' |
|
144 | 144 | log_user('newuser', 'newpass') |
|
145 | 145 | end |
|
146 | ||
|
146 | ||
|
147 | 147 | if Object.const_defined?(:Mocha) |
|
148 | ||
|
148 | ||
|
149 | 149 | def test_onthefly_registration |
|
150 | 150 | # disable registration |
|
151 | 151 | Setting.self_registration = '0' |
|
152 | 152 | AuthSource.expects(:authenticate).returns({:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com', :auth_source_id => 66}) |
|
153 | ||
|
153 | ||
|
154 | 154 | post 'account/login', :username => 'foo', :password => 'bar' |
|
155 | 155 | assert_redirected_to '/my/page' |
|
156 | ||
|
156 | ||
|
157 | 157 | user = User.find_by_login('foo') |
|
158 | 158 | assert user.is_a?(User) |
|
159 | 159 | assert_equal 66, user.auth_source_id |
|
160 | 160 | assert user.hashed_password.blank? |
|
161 | 161 | end |
|
162 | ||
|
162 | ||
|
163 | 163 | def test_onthefly_registration_with_invalid_attributes |
|
164 | 164 | # disable registration |
|
165 | 165 | Setting.self_registration = '0' |
|
166 | 166 | AuthSource.expects(:authenticate).returns({:login => 'foo', :lastname => 'Smith', :auth_source_id => 66}) |
|
167 | ||
|
167 | ||
|
168 | 168 | post 'account/login', :username => 'foo', :password => 'bar' |
|
169 | 169 | assert_response :success |
|
170 | 170 | assert_template 'account/register' |
@@ -172,34 +172,34 class AccountTest < ActionController::IntegrationTest | |||
|
172 | 172 | assert_tag :input, :attributes => { :name => 'user[lastname]', :value => 'Smith' } |
|
173 | 173 | assert_no_tag :input, :attributes => { :name => 'user[login]' } |
|
174 | 174 | assert_no_tag :input, :attributes => { :name => 'user[password]' } |
|
175 | ||
|
175 | ||
|
176 | 176 | post 'account/register', :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'} |
|
177 | 177 | assert_redirected_to '/my/account' |
|
178 | ||
|
178 | ||
|
179 | 179 | user = User.find_by_login('foo') |
|
180 | 180 | assert user.is_a?(User) |
|
181 | 181 | assert_equal 66, user.auth_source_id |
|
182 | 182 | assert user.hashed_password.blank? |
|
183 | 183 | end |
|
184 | ||
|
184 | ||
|
185 | 185 | def test_login_and_logout_should_clear_session |
|
186 | 186 | get '/login' |
|
187 | 187 | sid = session[:session_id] |
|
188 | ||
|
188 | ||
|
189 | 189 | post '/login', :username => 'admin', :password => 'admin' |
|
190 | 190 | assert_redirected_to '/my/page' |
|
191 | 191 | assert_not_equal sid, session[:session_id], "login should reset session" |
|
192 | 192 | assert_equal 1, session[:user_id] |
|
193 | 193 | sid = session[:session_id] |
|
194 | ||
|
194 | ||
|
195 | 195 | get '/' |
|
196 | 196 | assert_equal sid, session[:session_id] |
|
197 | ||
|
197 | ||
|
198 | 198 | get '/logout' |
|
199 | 199 | assert_not_equal sid, session[:session_id], "logout should reset session" |
|
200 | 200 | assert_nil session[:user_id] |
|
201 | 201 | end |
|
202 | ||
|
202 | ||
|
203 | 203 | else |
|
204 | 204 | puts 'Mocha is missing. Skipping tests.' |
|
205 | 205 | end |
General Comments 0
You need to be logged in to leave comments.
Login now