2009-11-23 00:19:29 +00:00
|
|
|
require 'test/test_helper'
|
|
|
|
|
|
|
|
class SessionTimeoutTest < ActionController::IntegrationTest
|
|
|
|
|
|
|
|
def last_request_at
|
|
|
|
@controller.user_session['last_request_at']
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'set last request at in user session after each request' do
|
|
|
|
sign_in_as_user
|
|
|
|
old_last_request = last_request_at
|
|
|
|
assert_not_nil last_request_at
|
2009-11-24 13:00:35 +00:00
|
|
|
|
2009-11-23 00:19:29 +00:00
|
|
|
get users_path
|
|
|
|
assert_not_nil last_request_at
|
|
|
|
assert_not_equal old_last_request, last_request_at
|
|
|
|
end
|
|
|
|
|
2009-11-24 00:56:04 +00:00
|
|
|
test 'not time out user session before default limit time' do
|
2009-11-24 13:52:13 +00:00
|
|
|
sign_in_as_user
|
|
|
|
assert_response :success
|
|
|
|
assert warden.authenticated?(:user)
|
2009-11-23 00:19:29 +00:00
|
|
|
|
|
|
|
get users_path
|
2009-11-24 00:56:04 +00:00
|
|
|
assert_response :success
|
|
|
|
assert warden.authenticated?(:user)
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|
|
|
|
|
2009-11-24 00:56:04 +00:00
|
|
|
test 'time out user session after default limit time' do
|
2009-11-24 13:52:13 +00:00
|
|
|
user = sign_in_as_user
|
|
|
|
get expire_user_path(user)
|
2009-11-23 00:19:29 +00:00
|
|
|
assert_not_nil last_request_at
|
|
|
|
|
|
|
|
get users_path
|
2009-11-24 00:56:04 +00:00
|
|
|
assert_redirected_to new_user_session_path(:timeout => true)
|
|
|
|
assert_not warden.authenticated?(:user)
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|
|
|
|
|
2009-11-23 00:33:19 +00:00
|
|
|
test 'user configured timeout limit' do
|
2009-11-25 02:11:49 +00:00
|
|
|
swap Devise, :timeout_in => 8.minutes do
|
2009-11-23 00:33:19 +00:00
|
|
|
user = sign_in_as_user
|
|
|
|
|
2009-11-24 13:52:13 +00:00
|
|
|
get users_path
|
2009-11-23 00:33:19 +00:00
|
|
|
assert_not_nil last_request_at
|
|
|
|
assert_response :success
|
|
|
|
assert warden.authenticated?(:user)
|
|
|
|
|
2009-11-24 13:52:13 +00:00
|
|
|
get expire_user_path(user)
|
2009-11-23 00:33:19 +00:00
|
|
|
get users_path
|
|
|
|
assert_redirected_to new_user_session_path(:timeout => true)
|
|
|
|
assert_not warden.authenticated?(:user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-24 00:56:04 +00:00
|
|
|
test 'error message with i18n' do
|
|
|
|
store_translations :en, :devise => {
|
|
|
|
:sessions => { :user => { :timeout => 'Session expired!' } }
|
|
|
|
} do
|
2009-11-24 13:52:13 +00:00
|
|
|
user = sign_in_as_user
|
2009-11-24 13:00:35 +00:00
|
|
|
|
2009-11-24 13:52:13 +00:00
|
|
|
get expire_user_path(user)
|
2009-11-24 00:56:04 +00:00
|
|
|
get users_path
|
|
|
|
follow_redirect!
|
|
|
|
assert_contain 'Session expired!'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|