##// END OF EJS Templates
Require password re-entry for sensitive actions (#19851)....
Require password re-entry for sensitive actions (#19851). Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@14333 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r13863:ef2e75f07212
r13951:d6f389658b9e
Show More
sessions_test.rb
132 lines | 4.6 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 # Redmine - project management software
Jean-Philippe Lang
Copyright update....
r13490 # Copyright (C) 2006-2015 Jean-Philippe Lang
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../test_helper', __FILE__)
class SessionStartTest < ActionController::TestCase
tests AccountController
Jean-Baptiste Barth
Fixed test/functional/sessions_test.rb breaking when run alone (#12285)...
r10562 fixtures :users
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 def test_login_should_set_session_timestamps
post :login, :username => 'jsmith', :password => 'jsmith'
assert_response 302
assert_equal 2, session[:user_id]
assert_not_nil session[:ctime]
assert_not_nil session[:atime]
end
end
class SessionsTest < ActionController::TestCase
Jean-Philippe Lang
Fixed: The error flash message on session expiration is not in the language of the user but of the user of the previous request (#17023)....
r13028 include Redmine::I18n
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 tests WelcomeController
Toshi MARUYAMA
add missing fixtures...
r13550 fixtures :users, :email_addresses
Jean-Baptiste Barth
Fixed test/functional/sessions_test.rb breaking when run alone (#12285)...
r10562
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 def test_atime_from_user_session_should_be_updated
created = 2.hours.ago.utc.to_i
get :index, {}, {:user_id => 2, :ctime => created, :atime => created}
assert_response :success
assert_equal created, session[:ctime]
assert_not_equal created, session[:atime]
assert session[:atime] > created
end
def test_user_session_should_not_be_reset_if_lifetime_and_timeout_disabled
with_settings :session_lifetime => '0', :session_timeout => '0' do
get :index, {}, {:user_id => 2}
assert_response :success
end
end
def test_user_session_without_ctime_should_be_reset_if_lifetime_enabled
with_settings :session_lifetime => '720' do
get :index, {}, {:user_id => 2}
Jean-Philippe Lang
Set a back_url when forcing new login after session expiration (#19655)....
r13863 assert_redirected_to 'http://test.host/login?back_url=http%3A%2F%2Ftest.host%2F'
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 end
end
def test_user_session_with_expired_ctime_should_be_reset_if_lifetime_enabled
with_settings :session_timeout => '720' do
get :index, {}, {:user_id => 2, :atime => 2.days.ago.utc.to_i}
Jean-Philippe Lang
Set a back_url when forcing new login after session expiration (#19655)....
r13863 assert_redirected_to 'http://test.host/login?back_url=http%3A%2F%2Ftest.host%2F'
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 end
end
def test_user_session_with_valid_ctime_should_not_be_reset_if_lifetime_enabled
with_settings :session_timeout => '720' do
get :index, {}, {:user_id => 2, :atime => 3.hours.ago.utc.to_i}
assert_response :success
end
end
def test_user_session_without_atime_should_be_reset_if_timeout_enabled
with_settings :session_timeout => '60' do
get :index, {}, {:user_id => 2}
Jean-Philippe Lang
Set a back_url when forcing new login after session expiration (#19655)....
r13863 assert_redirected_to 'http://test.host/login?back_url=http%3A%2F%2Ftest.host%2F'
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 end
end
def test_user_session_with_expired_atime_should_be_reset_if_timeout_enabled
with_settings :session_timeout => '60' do
get :index, {}, {:user_id => 2, :atime => 4.hours.ago.utc.to_i}
Jean-Philippe Lang
Set a back_url when forcing new login after session expiration (#19655)....
r13863 assert_redirected_to 'http://test.host/login?back_url=http%3A%2F%2Ftest.host%2F'
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 end
end
def test_user_session_with_valid_atime_should_not_be_reset_if_timeout_enabled
with_settings :session_timeout => '60' do
get :index, {}, {:user_id => 2, :atime => 10.minutes.ago.utc.to_i}
assert_response :success
end
end
def test_expired_user_session_should_be_restarted_if_autologin
with_settings :session_lifetime => '720', :session_timeout => '60', :autologin => 7 do
token = Token.create!(:user_id => 2, :action => 'autologin', :created_on => 1.day.ago)
@request.cookies['autologin'] = token.value
created = 2.hours.ago.utc.to_i
get :index, {}, {:user_id => 2, :ctime => created, :atime => created}
assert_equal 2, session[:user_id]
assert_response :success
assert_not_equal created, session[:ctime]
assert session[:ctime] >= created
end
end
Jean-Philippe Lang
Fixed: The error flash message on session expiration is not in the language of the user but of the user of the previous request (#17023)....
r13028 def test_expired_user_session_should_set_locale
set_language_if_valid 'it'
user = User.find(2)
user.language = 'fr'
user.save!
with_settings :session_timeout => '60' do
get :index, {}, {:user_id => user.id, :atime => 4.hours.ago.utc.to_i}
Jean-Philippe Lang
Set a back_url when forcing new login after session expiration (#19655)....
r13863 assert_redirected_to 'http://test.host/login?back_url=http%3A%2F%2Ftest.host%2F'
Jean-Philippe Lang
Fixed: The error flash message on session expiration is not in the language of the user but of the user of the previous request (#17023)....
r13028 assert_include "Veuillez vous reconnecter", flash[:error]
assert_equal :fr, current_language
end
end
Jean-Philippe Lang
Configurable session lifetime and timeout (#6597)....
r9614 def test_anonymous_session_should_not_be_reset
with_settings :session_lifetime => '720', :session_timeout => '60' do
get :index
assert_response :success
end
end
end