summaryrefslogtreecommitdiffstats
path: root/test/functional/sessions_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-06-10 13:16:56 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-06-10 13:16:56 +0000
commit74645eb017f2f8a0f9e7ce669c50c3827488b801 (patch)
treea551422f1783886028107abd2874b4c9cdc35ee9 /test/functional/sessions_test.rb
parent26ff9e1c260b6cbb02371f72047e3108a93aee75 (diff)
downloadredmine-74645eb017f2f8a0f9e7ce669c50c3827488b801.tar.gz
redmine-74645eb017f2f8a0f9e7ce669c50c3827488b801.zip
Configurable session lifetime and timeout (#6597).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9797 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional/sessions_test.rb')
-rw-r--r--test/functional/sessions_test.rb113
1 files changed, 113 insertions, 0 deletions
diff --git a/test/functional/sessions_test.rb b/test/functional/sessions_test.rb
new file mode 100644
index 000000000..d469f5050
--- /dev/null
+++ b/test/functional/sessions_test.rb
@@ -0,0 +1,113 @@
+# Redmine - project management software
+# Copyright (C) 2006-2012 Jean-Philippe Lang
+#
+# 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
+
+ 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
+ tests WelcomeController
+
+ 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}
+ assert_redirected_to '/login'
+ 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}
+ assert_redirected_to '/login'
+ 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}
+ assert_redirected_to '/login'
+ 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}
+ assert_redirected_to '/login'
+ 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
+
+ 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