@@ -1,129 +1,129 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 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. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class AccountControllerTest < ActionController::TestCase |
|
21 | 21 | tests AccountController |
|
22 | 22 | fixtures :users, :roles |
|
23 | 23 | |
|
24 | 24 | def setup |
|
25 | 25 | User.current = nil |
|
26 | 26 | Setting.openid = '1' |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def teardown |
|
30 | 30 | Setting.openid = '0' |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | if Object.const_defined?(:OpenID) |
|
34 | 34 | |
|
35 | 35 | def test_login_with_openid_for_existing_user |
|
36 | 36 | Setting.self_registration = '3' |
|
37 | 37 | existing_user = User.new(:firstname => 'Cool', |
|
38 | 38 | :lastname => 'User', |
|
39 | 39 | :mail => 'user@somedomain.com', |
|
40 | 40 | :identity_url => 'http://openid.example.com/good_user') |
|
41 | 41 | existing_user.login = 'cool_user' |
|
42 | 42 | assert existing_user.save! |
|
43 | 43 | |
|
44 | 44 | post :login, :openid_url => existing_user.identity_url |
|
45 | 45 | assert_redirected_to '/my/page' |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def test_login_with_invalid_openid_provider |
|
49 | 49 | Setting.self_registration = '0' |
|
50 | 50 | post :login, :openid_url => 'http;//openid.example.com/good_user' |
|
51 | 51 | assert_redirected_to home_url |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_login_with_openid_for_existing_non_active_user |
|
55 | 55 | Setting.self_registration = '2' |
|
56 | 56 | existing_user = User.new(:firstname => 'Cool', |
|
57 | 57 | :lastname => 'User', |
|
58 | 58 | :mail => 'user@somedomain.com', |
|
59 | 59 | :identity_url => 'http://openid.example.com/good_user', |
|
60 | 60 | :status => User::STATUS_REGISTERED) |
|
61 | 61 | existing_user.login = 'cool_user' |
|
62 | 62 | assert existing_user.save! |
|
63 | 63 | |
|
64 | 64 | post :login, :openid_url => existing_user.identity_url |
|
65 | 65 | assert_redirected_to '/login' |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def test_login_with_openid_with_new_user_created |
|
69 | 69 | Setting.self_registration = '3' |
|
70 | 70 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
71 | 71 | assert_redirected_to '/my/account' |
|
72 | 72 | user = User.find_by_login('cool_user') |
|
73 | 73 | assert user |
|
74 | 74 | assert_equal 'Cool', user.firstname |
|
75 | 75 | assert_equal 'User', user.lastname |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | def test_login_with_openid_with_new_user_and_self_registration_off |
|
79 | 79 | Setting.self_registration = '0' |
|
80 | 80 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
81 | 81 | assert_redirected_to home_url |
|
82 | 82 | user = User.find_by_login('cool_user') |
|
83 |
assert |
|
|
83 | assert_nil user | |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token |
|
87 | 87 | Setting.self_registration = '1' |
|
88 | 88 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
89 | 89 | assert_redirected_to '/login' |
|
90 | 90 | user = User.find_by_login('cool_user') |
|
91 | 91 | assert user |
|
92 | 92 | |
|
93 | 93 | token = Token.find_by_user_id_and_action(user.id, 'register') |
|
94 | 94 | assert token |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | def test_login_with_openid_with_new_user_created_with_manual_activation |
|
98 | 98 | Setting.self_registration = '2' |
|
99 | 99 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
100 | 100 | assert_redirected_to '/login' |
|
101 | 101 | user = User.find_by_login('cool_user') |
|
102 | 102 | assert user |
|
103 | 103 | assert_equal User::STATUS_REGISTERED, user.status |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | def test_login_with_openid_with_new_user_with_conflict_should_register |
|
107 | 107 | Setting.self_registration = '3' |
|
108 | 108 | existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com') |
|
109 | 109 | existing_user.login = 'cool_user' |
|
110 | 110 | assert existing_user.save! |
|
111 | 111 | |
|
112 | 112 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
113 | 113 | assert_response :success |
|
114 | 114 | assert_template 'register' |
|
115 | 115 | assert assigns(:user) |
|
116 | 116 | assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url] |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | def test_setting_openid_should_return_true_when_set_to_true |
|
120 | 120 | assert_equal true, Setting.openid? |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | 123 | else |
|
124 | 124 | puts "Skipping openid tests." |
|
125 | 125 | |
|
126 | 126 | def test_dummy |
|
127 | 127 | end |
|
128 | 128 | end |
|
129 | 129 | end |
General Comments 0
You need to be logged in to leave comments.
Login now