annotate .svn/pristine/10/10c9cdd06a52f023cccd6f598c36e6c63972ac76.svn-base @ 1485:c8d3ad483bea redmine-2.4-integration

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