annotate .svn/pristine/51/51d87f4fbdc2edb520d458a18a1662813140ff5c.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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