##// END OF EJS Templates
Moved openid functional tests for their own test case....
Jean-Philippe Lang -
r9743:6351631ec618
parent child
Show More
@@ -0,0 +1,133
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 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 tests AccountController
22 fixtures :users, :roles
23
24 def setup
25 User.current = nil
26 end
27
28 if Object.const_defined?(:OpenID)
29
30 def test_login_with_openid_for_existing_user
31 Setting.self_registration = '3'
32 Setting.openid = '1'
33 existing_user = User.new(:firstname => 'Cool',
34 :lastname => 'User',
35 :mail => 'user@somedomain.com',
36 :identity_url => 'http://openid.example.com/good_user')
37 existing_user.login = 'cool_user'
38 assert existing_user.save!
39
40 post :login, :openid_url => existing_user.identity_url
41 assert_redirected_to '/my/page'
42 end
43
44 def test_login_with_invalid_openid_provider
45 Setting.self_registration = '0'
46 Setting.openid = '1'
47 post :login, :openid_url => 'http;//openid.example.com/good_user'
48 assert_redirected_to home_url
49 end
50
51 def test_login_with_openid_for_existing_non_active_user
52 Setting.self_registration = '2'
53 Setting.openid = '1'
54 existing_user = User.new(:firstname => 'Cool',
55 :lastname => 'User',
56 :mail => 'user@somedomain.com',
57 :identity_url => 'http://openid.example.com/good_user',
58 :status => User::STATUS_REGISTERED)
59 existing_user.login = 'cool_user'
60 assert existing_user.save!
61
62 post :login, :openid_url => existing_user.identity_url
63 assert_redirected_to '/login'
64 end
65
66 def test_login_with_openid_with_new_user_created
67 Setting.self_registration = '3'
68 Setting.openid = '1'
69 post :login, :openid_url => 'http://openid.example.com/good_user'
70 assert_redirected_to '/my/account'
71 user = User.find_by_login('cool_user')
72 assert user
73 assert_equal 'Cool', user.firstname
74 assert_equal 'User', user.lastname
75 end
76
77 def test_login_with_openid_with_new_user_and_self_registration_off
78 Setting.self_registration = '0'
79 Setting.openid = '1'
80 post :login, :openid_url => 'http://openid.example.com/good_user'
81 assert_redirected_to home_url
82 user = User.find_by_login('cool_user')
83 assert ! user
84 end
85
86 def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
87 Setting.self_registration = '1'
88 Setting.openid = '1'
89 post :login, :openid_url => 'http://openid.example.com/good_user'
90 assert_redirected_to '/login'
91 user = User.find_by_login('cool_user')
92 assert user
93
94 token = Token.find_by_user_id_and_action(user.id, 'register')
95 assert token
96 end
97
98 def test_login_with_openid_with_new_user_created_with_manual_activation
99 Setting.self_registration = '2'
100 Setting.openid = '1'
101 post :login, :openid_url => 'http://openid.example.com/good_user'
102 assert_redirected_to '/login'
103 user = User.find_by_login('cool_user')
104 assert user
105 assert_equal User::STATUS_REGISTERED, user.status
106 end
107
108 def test_login_with_openid_with_new_user_with_conflict_should_register
109 Setting.self_registration = '3'
110 Setting.openid = '1'
111 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
112 existing_user.login = 'cool_user'
113 assert existing_user.save!
114
115 post :login, :openid_url => 'http://openid.example.com/good_user'
116 assert_response :success
117 assert_template 'register'
118 assert assigns(:user)
119 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
120 end
121
122 def test_setting_openid_should_return_true_when_set_to_true
123 Setting.openid = '1'
124 assert_equal true, Setting.openid?
125 end
126
127 else
128 puts "Skipping openid tests."
129
130 def test_dummy
131 end
132 end
133 end
@@ -68,109 +68,6 class AccountControllerTest < ActionController::TestCase
68 assert_response 302
68 assert_response 302
69 end
69 end
70
70
71 if Object.const_defined?(:OpenID)
72
73 def test_login_with_openid_for_existing_user
74 Setting.self_registration = '3'
75 Setting.openid = '1'
76 existing_user = User.new(:firstname => 'Cool',
77 :lastname => 'User',
78 :mail => 'user@somedomain.com',
79 :identity_url => 'http://openid.example.com/good_user')
80 existing_user.login = 'cool_user'
81 assert existing_user.save!
82
83 post :login, :openid_url => existing_user.identity_url
84 assert_redirected_to '/my/page'
85 end
86
87 def test_login_with_invalid_openid_provider
88 Setting.self_registration = '0'
89 Setting.openid = '1'
90 post :login, :openid_url => 'http;//openid.example.com/good_user'
91 assert_redirected_to home_url
92 end
93
94 def test_login_with_openid_for_existing_non_active_user
95 Setting.self_registration = '2'
96 Setting.openid = '1'
97 existing_user = User.new(:firstname => 'Cool',
98 :lastname => 'User',
99 :mail => 'user@somedomain.com',
100 :identity_url => 'http://openid.example.com/good_user',
101 :status => User::STATUS_REGISTERED)
102 existing_user.login = 'cool_user'
103 assert existing_user.save!
104
105 post :login, :openid_url => existing_user.identity_url
106 assert_redirected_to '/login'
107 end
108
109 def test_login_with_openid_with_new_user_created
110 Setting.self_registration = '3'
111 Setting.openid = '1'
112 post :login, :openid_url => 'http://openid.example.com/good_user'
113 assert_redirected_to '/my/account'
114 user = User.find_by_login('cool_user')
115 assert user
116 assert_equal 'Cool', user.firstname
117 assert_equal 'User', user.lastname
118 end
119
120 def test_login_with_openid_with_new_user_and_self_registration_off
121 Setting.self_registration = '0'
122 Setting.openid = '1'
123 post :login, :openid_url => 'http://openid.example.com/good_user'
124 assert_redirected_to home_url
125 user = User.find_by_login('cool_user')
126 assert ! user
127 end
128
129 def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
130 Setting.self_registration = '1'
131 Setting.openid = '1'
132 post :login, :openid_url => 'http://openid.example.com/good_user'
133 assert_redirected_to '/login'
134 user = User.find_by_login('cool_user')
135 assert user
136
137 token = Token.find_by_user_id_and_action(user.id, 'register')
138 assert token
139 end
140
141 def test_login_with_openid_with_new_user_created_with_manual_activation
142 Setting.self_registration = '2'
143 Setting.openid = '1'
144 post :login, :openid_url => 'http://openid.example.com/good_user'
145 assert_redirected_to '/login'
146 user = User.find_by_login('cool_user')
147 assert user
148 assert_equal User::STATUS_REGISTERED, user.status
149 end
150
151 def test_login_with_openid_with_new_user_with_conflict_should_register
152 Setting.self_registration = '3'
153 Setting.openid = '1'
154 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
155 existing_user.login = 'cool_user'
156 assert existing_user.save!
157
158 post :login, :openid_url => 'http://openid.example.com/good_user'
159 assert_response :success
160 assert_template 'register'
161 assert assigns(:user)
162 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
163 end
164
165 def test_setting_openid_should_return_true_when_set_to_true
166 Setting.openid = '1'
167 assert_equal true, Setting.openid?
168 end
169
170 else
171 puts "Skipping openid tests."
172 end
173
174 def test_logout
71 def test_logout
175 @request.session[:user_id] = 2
72 @request.session[:user_id] = 2
176 get :logout
73 get :logout
General Comments 0
You need to be logged in to leave comments. Login now