annotate .svn/pristine/2c/2c2690417bf095320f6312e550c41841ed5d033a.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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