annotate .svn/pristine/10/10c9cdd06a52f023cccd6f598c36e6c63972ac76.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class AccountControllerOpenidTest < ActionController::TestCase
Chris@1295 21 tests AccountController
Chris@1295 22 fixtures :users, :roles
Chris@1295 23
Chris@1295 24 def setup
Chris@1295 25 User.current = nil
Chris@1295 26 Setting.openid = '1'
Chris@1295 27 end
Chris@1295 28
Chris@1295 29 def teardown
Chris@1295 30 Setting.openid = '0'
Chris@1295 31 end
Chris@1295 32
Chris@1295 33 if Object.const_defined?(:OpenID)
Chris@1295 34
Chris@1295 35 def test_login_with_openid_for_existing_user
Chris@1295 36 Setting.self_registration = '3'
Chris@1295 37 existing_user = User.new(:firstname => 'Cool',
Chris@1295 38 :lastname => 'User',
Chris@1295 39 :mail => 'user@somedomain.com',
Chris@1295 40 :identity_url => 'http://openid.example.com/good_user')
Chris@1295 41 existing_user.login = 'cool_user'
Chris@1295 42 assert existing_user.save!
Chris@1295 43
Chris@1295 44 post :login, :openid_url => existing_user.identity_url
Chris@1295 45 assert_redirected_to '/my/page'
Chris@1295 46 end
Chris@1295 47
Chris@1295 48 def test_login_with_invalid_openid_provider
Chris@1295 49 Setting.self_registration = '0'
Chris@1295 50 post :login, :openid_url => 'http;//openid.example.com/good_user'
Chris@1295 51 assert_redirected_to home_url
Chris@1295 52 end
Chris@1295 53
Chris@1295 54 def test_login_with_openid_for_existing_non_active_user
Chris@1295 55 Setting.self_registration = '2'
Chris@1295 56 existing_user = User.new(:firstname => 'Cool',
Chris@1295 57 :lastname => 'User',
Chris@1295 58 :mail => 'user@somedomain.com',
Chris@1295 59 :identity_url => 'http://openid.example.com/good_user',
Chris@1295 60 :status => User::STATUS_REGISTERED)
Chris@1295 61 existing_user.login = 'cool_user'
Chris@1295 62 assert existing_user.save!
Chris@1295 63
Chris@1295 64 post :login, :openid_url => existing_user.identity_url
Chris@1295 65 assert_redirected_to '/login'
Chris@1295 66 end
Chris@1295 67
Chris@1295 68 def test_login_with_openid_with_new_user_created
Chris@1295 69 Setting.self_registration = '3'
Chris@1295 70 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@1295 71 assert_redirected_to '/my/account'
Chris@1295 72 user = User.find_by_login('cool_user')
Chris@1295 73 assert user
Chris@1295 74 assert_equal 'Cool', user.firstname
Chris@1295 75 assert_equal 'User', user.lastname
Chris@1295 76 end
Chris@1295 77
Chris@1295 78 def test_login_with_openid_with_new_user_and_self_registration_off
Chris@1295 79 Setting.self_registration = '0'
Chris@1295 80 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@1295 81 assert_redirected_to home_url
Chris@1295 82 user = User.find_by_login('cool_user')
Chris@1295 83 assert_nil user
Chris@1295 84 end
Chris@1295 85
Chris@1295 86 def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
Chris@1295 87 Setting.self_registration = '1'
Chris@1295 88 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@1295 89 assert_redirected_to '/login'
Chris@1295 90 user = User.find_by_login('cool_user')
Chris@1295 91 assert user
Chris@1295 92
Chris@1295 93 token = Token.find_by_user_id_and_action(user.id, 'register')
Chris@1295 94 assert token
Chris@1295 95 end
Chris@1295 96
Chris@1295 97 def test_login_with_openid_with_new_user_created_with_manual_activation
Chris@1295 98 Setting.self_registration = '2'
Chris@1295 99 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@1295 100 assert_redirected_to '/login'
Chris@1295 101 user = User.find_by_login('cool_user')
Chris@1295 102 assert user
Chris@1295 103 assert_equal User::STATUS_REGISTERED, user.status
Chris@1295 104 end
Chris@1295 105
Chris@1295 106 def test_login_with_openid_with_new_user_with_conflict_should_register
Chris@1295 107 Setting.self_registration = '3'
Chris@1295 108 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
Chris@1295 109 existing_user.login = 'cool_user'
Chris@1295 110 assert existing_user.save!
Chris@1295 111
Chris@1295 112 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@1295 113 assert_response :success
Chris@1295 114 assert_template 'register'
Chris@1295 115 assert assigns(:user)
Chris@1295 116 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
Chris@1295 117 end
Chris@1295 118
Chris@1295 119 def test_login_with_openid_with_new_user_with_missing_information_should_register
Chris@1295 120 Setting.self_registration = '3'
Chris@1295 121
Chris@1295 122 post :login, :openid_url => 'http://openid.example.com/good_blank_user'
Chris@1295 123 assert_response :success
Chris@1295 124 assert_template 'register'
Chris@1295 125 assert assigns(:user)
Chris@1295 126 assert_equal 'http://openid.example.com/good_blank_user', assigns(:user)[:identity_url]
Chris@1295 127
Chris@1295 128 assert_select 'input[name=?]', 'user[login]'
Chris@1295 129 assert_select 'input[name=?]', 'user[password]'
Chris@1295 130 assert_select 'input[name=?]', 'user[password_confirmation]'
Chris@1295 131 assert_select 'input[name=?][value=?]', 'user[identity_url]', 'http://openid.example.com/good_blank_user'
Chris@1295 132 end
Chris@1295 133
Chris@1295 134 def test_register_after_login_failure_should_not_require_user_to_enter_a_password
Chris@1295 135 Setting.self_registration = '3'
Chris@1295 136
Chris@1295 137 assert_difference 'User.count' do
Chris@1295 138 post :register, :user => {
Chris@1295 139 :login => 'good_blank_user',
Chris@1295 140 :password => '',
Chris@1295 141 :password_confirmation => '',
Chris@1295 142 :firstname => 'Cool',
Chris@1295 143 :lastname => 'User',
Chris@1295 144 :mail => 'user@somedomain.com',
Chris@1295 145 :identity_url => 'http://openid.example.com/good_blank_user'
Chris@1295 146 }
Chris@1295 147 assert_response 302
Chris@1295 148 end
Chris@1295 149
Chris@1295 150 user = User.first(:order => 'id DESC')
Chris@1295 151 assert_equal 'http://openid.example.com/good_blank_user', user.identity_url
Chris@1295 152 assert user.hashed_password.blank?, "Hashed password was #{user.hashed_password}"
Chris@1295 153 end
Chris@1295 154
Chris@1295 155 def test_setting_openid_should_return_true_when_set_to_true
Chris@1295 156 assert_equal true, Setting.openid?
Chris@1295 157 end
Chris@1295 158
Chris@1295 159 else
Chris@1295 160 puts "Skipping openid tests."
Chris@1295 161
Chris@1295 162 def test_dummy
Chris@1295 163 end
Chris@1295 164 end
Chris@1295 165 end