##// END OF EJS Templates
remove trailing white-spaces from test/functional/account_controller_test.rb....
Toshi MARUYAMA -
r5869:c9ba5662e842
parent child
Show More
@@ -1,224 +1,223
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 require 'account_controller'
19 require 'account_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class AccountController; def rescue_action(e) raise e end; end
22 class AccountController; def rescue_action(e) raise e end; end
23
23
24 class AccountControllerTest < ActionController::TestCase
24 class AccountControllerTest < ActionController::TestCase
25 fixtures :users, :roles
25 fixtures :users, :roles
26
26
27 def setup
27 def setup
28 @controller = AccountController.new
28 @controller = AccountController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_login_should_redirect_to_back_url_param
34 def test_login_should_redirect_to_back_url_param
35 # request.uri is "test.host" in test environment
35 # request.uri is "test.host" in test environment
36 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
36 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
37 assert_redirected_to '/issues/show/1'
37 assert_redirected_to '/issues/show/1'
38 end
38 end
39
39
40 def test_login_should_not_redirect_to_another_host
40 def test_login_should_not_redirect_to_another_host
41 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.foo%2Ffake'
41 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.foo%2Ffake'
42 assert_redirected_to '/my/page'
42 assert_redirected_to '/my/page'
43 end
43 end
44
44
45 def test_login_with_wrong_password
45 def test_login_with_wrong_password
46 post :login, :username => 'admin', :password => 'bad'
46 post :login, :username => 'admin', :password => 'bad'
47 assert_response :success
47 assert_response :success
48 assert_template 'login'
48 assert_template 'login'
49 assert_tag 'div',
49 assert_tag 'div',
50 :attributes => { :class => "flash error" },
50 :attributes => { :class => "flash error" },
51 :content => /Invalid user or password/
51 :content => /Invalid user or password/
52 end
52 end
53
53
54 if Object.const_defined?(:OpenID)
54 if Object.const_defined?(:OpenID)
55
55
56 def test_login_with_openid_for_existing_user
56 def test_login_with_openid_for_existing_user
57 Setting.self_registration = '3'
57 Setting.self_registration = '3'
58 Setting.openid = '1'
58 Setting.openid = '1'
59 existing_user = User.new(:firstname => 'Cool',
59 existing_user = User.new(:firstname => 'Cool',
60 :lastname => 'User',
60 :lastname => 'User',
61 :mail => 'user@somedomain.com',
61 :mail => 'user@somedomain.com',
62 :identity_url => 'http://openid.example.com/good_user')
62 :identity_url => 'http://openid.example.com/good_user')
63 existing_user.login = 'cool_user'
63 existing_user.login = 'cool_user'
64 assert existing_user.save!
64 assert existing_user.save!
65
65
66 post :login, :openid_url => existing_user.identity_url
66 post :login, :openid_url => existing_user.identity_url
67 assert_redirected_to '/my/page'
67 assert_redirected_to '/my/page'
68 end
68 end
69
69
70 def test_login_with_invalid_openid_provider
70 def test_login_with_invalid_openid_provider
71 Setting.self_registration = '0'
71 Setting.self_registration = '0'
72 Setting.openid = '1'
72 Setting.openid = '1'
73 post :login, :openid_url => 'http;//openid.example.com/good_user'
73 post :login, :openid_url => 'http;//openid.example.com/good_user'
74 assert_redirected_to home_url
74 assert_redirected_to home_url
75 end
75 end
76
76
77 def test_login_with_openid_for_existing_non_active_user
77 def test_login_with_openid_for_existing_non_active_user
78 Setting.self_registration = '2'
78 Setting.self_registration = '2'
79 Setting.openid = '1'
79 Setting.openid = '1'
80 existing_user = User.new(:firstname => 'Cool',
80 existing_user = User.new(:firstname => 'Cool',
81 :lastname => 'User',
81 :lastname => 'User',
82 :mail => 'user@somedomain.com',
82 :mail => 'user@somedomain.com',
83 :identity_url => 'http://openid.example.com/good_user',
83 :identity_url => 'http://openid.example.com/good_user',
84 :status => User::STATUS_REGISTERED)
84 :status => User::STATUS_REGISTERED)
85 existing_user.login = 'cool_user'
85 existing_user.login = 'cool_user'
86 assert existing_user.save!
86 assert existing_user.save!
87
87
88 post :login, :openid_url => existing_user.identity_url
88 post :login, :openid_url => existing_user.identity_url
89 assert_redirected_to '/login'
89 assert_redirected_to '/login'
90 end
90 end
91
91
92 def test_login_with_openid_with_new_user_created
92 def test_login_with_openid_with_new_user_created
93 Setting.self_registration = '3'
93 Setting.self_registration = '3'
94 Setting.openid = '1'
94 Setting.openid = '1'
95 post :login, :openid_url => 'http://openid.example.com/good_user'
95 post :login, :openid_url => 'http://openid.example.com/good_user'
96 assert_redirected_to '/my/account'
96 assert_redirected_to '/my/account'
97 user = User.find_by_login('cool_user')
97 user = User.find_by_login('cool_user')
98 assert user
98 assert user
99 assert_equal 'Cool', user.firstname
99 assert_equal 'Cool', user.firstname
100 assert_equal 'User', user.lastname
100 assert_equal 'User', user.lastname
101 end
101 end
102
102
103 def test_login_with_openid_with_new_user_and_self_registration_off
103 def test_login_with_openid_with_new_user_and_self_registration_off
104 Setting.self_registration = '0'
104 Setting.self_registration = '0'
105 Setting.openid = '1'
105 Setting.openid = '1'
106 post :login, :openid_url => 'http://openid.example.com/good_user'
106 post :login, :openid_url => 'http://openid.example.com/good_user'
107 assert_redirected_to home_url
107 assert_redirected_to home_url
108 user = User.find_by_login('cool_user')
108 user = User.find_by_login('cool_user')
109 assert ! user
109 assert ! user
110 end
110 end
111
111
112 def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
112 def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
113 Setting.self_registration = '1'
113 Setting.self_registration = '1'
114 Setting.openid = '1'
114 Setting.openid = '1'
115 post :login, :openid_url => 'http://openid.example.com/good_user'
115 post :login, :openid_url => 'http://openid.example.com/good_user'
116 assert_redirected_to '/login'
116 assert_redirected_to '/login'
117 user = User.find_by_login('cool_user')
117 user = User.find_by_login('cool_user')
118 assert user
118 assert user
119
119
120 token = Token.find_by_user_id_and_action(user.id, 'register')
120 token = Token.find_by_user_id_and_action(user.id, 'register')
121 assert token
121 assert token
122 end
122 end
123
123
124 def test_login_with_openid_with_new_user_created_with_manual_activation
124 def test_login_with_openid_with_new_user_created_with_manual_activation
125 Setting.self_registration = '2'
125 Setting.self_registration = '2'
126 Setting.openid = '1'
126 Setting.openid = '1'
127 post :login, :openid_url => 'http://openid.example.com/good_user'
127 post :login, :openid_url => 'http://openid.example.com/good_user'
128 assert_redirected_to '/login'
128 assert_redirected_to '/login'
129 user = User.find_by_login('cool_user')
129 user = User.find_by_login('cool_user')
130 assert user
130 assert user
131 assert_equal User::STATUS_REGISTERED, user.status
131 assert_equal User::STATUS_REGISTERED, user.status
132 end
132 end
133
133
134 def test_login_with_openid_with_new_user_with_conflict_should_register
134 def test_login_with_openid_with_new_user_with_conflict_should_register
135 Setting.self_registration = '3'
135 Setting.self_registration = '3'
136 Setting.openid = '1'
136 Setting.openid = '1'
137 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
137 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
138 existing_user.login = 'cool_user'
138 existing_user.login = 'cool_user'
139 assert existing_user.save!
139 assert existing_user.save!
140
140
141 post :login, :openid_url => 'http://openid.example.com/good_user'
141 post :login, :openid_url => 'http://openid.example.com/good_user'
142 assert_response :success
142 assert_response :success
143 assert_template 'register'
143 assert_template 'register'
144 assert assigns(:user)
144 assert assigns(:user)
145 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
145 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
146 end
146 end
147
147
148 def test_setting_openid_should_return_true_when_set_to_true
148 def test_setting_openid_should_return_true_when_set_to_true
149 Setting.openid = '1'
149 Setting.openid = '1'
150 assert_equal true, Setting.openid?
150 assert_equal true, Setting.openid?
151 end
151 end
152
152
153 else
153 else
154 puts "Skipping openid tests."
154 puts "Skipping openid tests."
155 end
155 end
156
156
157 def test_logout
157 def test_logout
158 @request.session[:user_id] = 2
158 @request.session[:user_id] = 2
159 get :logout
159 get :logout
160 assert_redirected_to '/'
160 assert_redirected_to '/'
161 assert_nil @request.session[:user_id]
161 assert_nil @request.session[:user_id]
162 end
162 end
163
163
164 context "GET #register" do
164 context "GET #register" do
165 context "with self registration on" do
165 context "with self registration on" do
166 setup do
166 setup do
167 Setting.self_registration = '3'
167 Setting.self_registration = '3'
168 get :register
168 get :register
169 end
169 end
170
170
171 should_respond_with :success
171 should_respond_with :success
172 should_render_template :register
172 should_render_template :register
173 should_assign_to :user
173 should_assign_to :user
174 end
174 end
175
175
176 context "with self registration off" do
176 context "with self registration off" do
177 setup do
177 setup do
178 Setting.self_registration = '0'
178 Setting.self_registration = '0'
179 get :register
179 get :register
180 end
180 end
181
181
182 should_redirect_to('/') { home_url }
182 should_redirect_to('/') { home_url }
183 end
183 end
184 end
184 end
185
185
186 # See integration/account_test.rb for the full test
186 # See integration/account_test.rb for the full test
187 context "POST #register" do
187 context "POST #register" do
188 context "with self registration on automatic" do
188 context "with self registration on automatic" do
189 setup do
189 setup do
190 Setting.self_registration = '3'
190 Setting.self_registration = '3'
191 post :register, :user => {
191 post :register, :user => {
192 :login => 'register',
192 :login => 'register',
193 :password => 'test',
193 :password => 'test',
194 :password_confirmation => 'test',
194 :password_confirmation => 'test',
195 :firstname => 'John',
195 :firstname => 'John',
196 :lastname => 'Doe',
196 :lastname => 'Doe',
197 :mail => 'register@example.com'
197 :mail => 'register@example.com'
198 }
198 }
199 end
199 end
200
200
201 should_respond_with :redirect
201 should_respond_with :redirect
202 should_assign_to :user
202 should_assign_to :user
203 should_redirect_to('my page') { {:controller => 'my', :action => 'account'} }
203 should_redirect_to('my page') { {:controller => 'my', :action => 'account'} }
204
204
205 should_create_a_new_user { User.last(:conditions => {:login => 'register'}) }
205 should_create_a_new_user { User.last(:conditions => {:login => 'register'}) }
206
206
207 should 'set the user status to active' do
207 should 'set the user status to active' do
208 user = User.last(:conditions => {:login => 'register'})
208 user = User.last(:conditions => {:login => 'register'})
209 assert user
209 assert user
210 assert_equal User::STATUS_ACTIVE, user.status
210 assert_equal User::STATUS_ACTIVE, user.status
211 end
211 end
212 end
212 end
213
213
214 context "with self registration off" do
214 context "with self registration off" do
215 setup do
215 setup do
216 Setting.self_registration = '0'
216 Setting.self_registration = '0'
217 post :register
217 post :register
218 end
218 end
219
219
220 should_redirect_to('/') { home_url }
220 should_redirect_to('/') { home_url }
221 end
221 end
222 end
222 end
223
224 end
223 end
General Comments 0
You need to be logged in to leave comments. Login now