annotate .svn/pristine/7e/7e3d39301783d138f7a6d49cba0462adeb117d57.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 cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19 require 'account_controller'
Chris@909 20
Chris@909 21 # Re-raise errors caught by the controller.
Chris@909 22 class AccountController; def rescue_action(e) raise e end; end
Chris@909 23
Chris@909 24 class AccountControllerTest < ActionController::TestCase
Chris@909 25 fixtures :users, :roles
Chris@909 26
Chris@909 27 def setup
Chris@909 28 @controller = AccountController.new
Chris@909 29 @request = ActionController::TestRequest.new
Chris@909 30 @response = ActionController::TestResponse.new
Chris@909 31 User.current = nil
Chris@909 32 end
Chris@909 33
Chris@909 34 def test_login_should_redirect_to_back_url_param
Chris@909 35 # request.uri is "test.host" in test environment
Chris@909 36 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
Chris@909 37 assert_redirected_to '/issues/show/1'
Chris@909 38 end
Chris@909 39
Chris@909 40 def test_login_should_not_redirect_to_another_host
Chris@909 41 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.foo%2Ffake'
Chris@909 42 assert_redirected_to '/my/page'
Chris@909 43 end
Chris@909 44
Chris@909 45 def test_login_with_wrong_password
Chris@909 46 post :login, :username => 'admin', :password => 'bad'
Chris@909 47 assert_response :success
Chris@909 48 assert_template 'login'
Chris@909 49 assert_tag 'div',
Chris@909 50 :attributes => { :class => "flash error" },
Chris@909 51 :content => /Invalid user or password/
Chris@909 52 end
Chris@909 53
Chris@909 54 if Object.const_defined?(:OpenID)
Chris@909 55
Chris@909 56 def test_login_with_openid_for_existing_user
Chris@909 57 Setting.self_registration = '3'
Chris@909 58 Setting.openid = '1'
Chris@909 59 existing_user = User.new(:firstname => 'Cool',
Chris@909 60 :lastname => 'User',
Chris@909 61 :mail => 'user@somedomain.com',
Chris@909 62 :identity_url => 'http://openid.example.com/good_user')
Chris@909 63 existing_user.login = 'cool_user'
Chris@909 64 assert existing_user.save!
Chris@909 65
Chris@909 66 post :login, :openid_url => existing_user.identity_url
Chris@909 67 assert_redirected_to '/my/page'
Chris@909 68 end
Chris@909 69
Chris@909 70 def test_login_with_invalid_openid_provider
Chris@909 71 Setting.self_registration = '0'
Chris@909 72 Setting.openid = '1'
Chris@909 73 post :login, :openid_url => 'http;//openid.example.com/good_user'
Chris@909 74 assert_redirected_to home_url
Chris@909 75 end
Chris@909 76
Chris@909 77 def test_login_with_openid_for_existing_non_active_user
Chris@909 78 Setting.self_registration = '2'
Chris@909 79 Setting.openid = '1'
Chris@909 80 existing_user = User.new(:firstname => 'Cool',
Chris@909 81 :lastname => 'User',
Chris@909 82 :mail => 'user@somedomain.com',
Chris@909 83 :identity_url => 'http://openid.example.com/good_user',
Chris@909 84 :status => User::STATUS_REGISTERED)
Chris@909 85 existing_user.login = 'cool_user'
Chris@909 86 assert existing_user.save!
Chris@909 87
Chris@909 88 post :login, :openid_url => existing_user.identity_url
Chris@909 89 assert_redirected_to '/login'
Chris@909 90 end
Chris@909 91
Chris@909 92 def test_login_with_openid_with_new_user_created
Chris@909 93 Setting.self_registration = '3'
Chris@909 94 Setting.openid = '1'
Chris@909 95 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@909 96 assert_redirected_to '/my/account'
Chris@909 97 user = User.find_by_login('cool_user')
Chris@909 98 assert user
Chris@909 99 assert_equal 'Cool', user.firstname
Chris@909 100 assert_equal 'User', user.lastname
Chris@909 101 end
Chris@909 102
Chris@909 103 def test_login_with_openid_with_new_user_and_self_registration_off
Chris@909 104 Setting.self_registration = '0'
Chris@909 105 Setting.openid = '1'
Chris@909 106 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@909 107 assert_redirected_to home_url
Chris@909 108 user = User.find_by_login('cool_user')
Chris@909 109 assert ! user
Chris@909 110 end
Chris@909 111
Chris@909 112 def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
Chris@909 113 Setting.self_registration = '1'
Chris@909 114 Setting.openid = '1'
Chris@909 115 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@909 116 assert_redirected_to '/login'
Chris@909 117 user = User.find_by_login('cool_user')
Chris@909 118 assert user
Chris@909 119
Chris@909 120 token = Token.find_by_user_id_and_action(user.id, 'register')
Chris@909 121 assert token
Chris@909 122 end
Chris@909 123
Chris@909 124 def test_login_with_openid_with_new_user_created_with_manual_activation
Chris@909 125 Setting.self_registration = '2'
Chris@909 126 Setting.openid = '1'
Chris@909 127 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@909 128 assert_redirected_to '/login'
Chris@909 129 user = User.find_by_login('cool_user')
Chris@909 130 assert user
Chris@909 131 assert_equal User::STATUS_REGISTERED, user.status
Chris@909 132 end
Chris@909 133
Chris@909 134 def test_login_with_openid_with_new_user_with_conflict_should_register
Chris@909 135 Setting.self_registration = '3'
Chris@909 136 Setting.openid = '1'
Chris@909 137 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
Chris@909 138 existing_user.login = 'cool_user'
Chris@909 139 assert existing_user.save!
Chris@909 140
Chris@909 141 post :login, :openid_url => 'http://openid.example.com/good_user'
Chris@909 142 assert_response :success
Chris@909 143 assert_template 'register'
Chris@909 144 assert assigns(:user)
Chris@909 145 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
Chris@909 146 end
Chris@909 147
Chris@909 148 def test_setting_openid_should_return_true_when_set_to_true
Chris@909 149 Setting.openid = '1'
Chris@909 150 assert_equal true, Setting.openid?
Chris@909 151 end
Chris@909 152
Chris@909 153 else
Chris@909 154 puts "Skipping openid tests."
Chris@909 155 end
Chris@909 156
Chris@909 157 def test_logout
Chris@909 158 @request.session[:user_id] = 2
Chris@909 159 get :logout
Chris@909 160 assert_redirected_to '/'
Chris@909 161 assert_nil @request.session[:user_id]
Chris@909 162 end
Chris@909 163
Chris@909 164 context "GET #register" do
Chris@909 165 context "with self registration on" do
Chris@909 166 setup do
Chris@909 167 Setting.self_registration = '3'
Chris@909 168 get :register
Chris@909 169 end
Chris@909 170
Chris@909 171 should_respond_with :success
Chris@909 172 should_render_template :register
Chris@909 173 should_assign_to :user
Chris@909 174 end
Chris@909 175
Chris@909 176 context "with self registration off" do
Chris@909 177 setup do
Chris@909 178 Setting.self_registration = '0'
Chris@909 179 get :register
Chris@909 180 end
Chris@909 181
Chris@909 182 should_redirect_to('/') { home_url }
Chris@909 183 end
Chris@909 184 end
Chris@909 185
Chris@909 186 # See integration/account_test.rb for the full test
Chris@909 187 context "POST #register" do
Chris@909 188 context "with self registration on automatic" do
Chris@909 189 setup do
Chris@909 190 Setting.self_registration = '3'
Chris@909 191 post :register, :user => {
Chris@909 192 :login => 'register',
Chris@909 193 :password => 'test',
Chris@909 194 :password_confirmation => 'test',
Chris@909 195 :firstname => 'John',
Chris@909 196 :lastname => 'Doe',
Chris@909 197 :mail => 'register@example.com'
Chris@909 198 }
Chris@909 199 end
Chris@909 200
Chris@909 201 should_respond_with :redirect
Chris@909 202 should_assign_to :user
Chris@909 203 should_redirect_to('my page') { {:controller => 'my', :action => 'account'} }
Chris@909 204
Chris@909 205 should_create_a_new_user { User.last(:conditions => {:login => 'register'}) }
Chris@909 206
Chris@909 207 should 'set the user status to active' do
Chris@909 208 user = User.last(:conditions => {:login => 'register'})
Chris@909 209 assert user
Chris@909 210 assert_equal User::STATUS_ACTIVE, user.status
Chris@909 211 end
Chris@909 212 end
Chris@909 213
Chris@909 214 context "with self registration off" do
Chris@909 215 setup do
Chris@909 216 Setting.self_registration = '0'
Chris@909 217 post :register
Chris@909 218 end
Chris@909 219
Chris@909 220 should_redirect_to('/') { home_url }
Chris@909 221 end
Chris@909 222 end
Chris@909 223 end