@@ -1,113 +1,117 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class SessionStartTest < ActionController::TestCase |
|
20 | class SessionStartTest < ActionController::TestCase | |
21 | tests AccountController |
|
21 | tests AccountController | |
22 |
|
22 | |||
|
23 | fixtures :users | |||
|
24 | ||||
23 | def test_login_should_set_session_timestamps |
|
25 | def test_login_should_set_session_timestamps | |
24 | post :login, :username => 'jsmith', :password => 'jsmith' |
|
26 | post :login, :username => 'jsmith', :password => 'jsmith' | |
25 | assert_response 302 |
|
27 | assert_response 302 | |
26 | assert_equal 2, session[:user_id] |
|
28 | assert_equal 2, session[:user_id] | |
27 | assert_not_nil session[:ctime] |
|
29 | assert_not_nil session[:ctime] | |
28 | assert_not_nil session[:atime] |
|
30 | assert_not_nil session[:atime] | |
29 | end |
|
31 | end | |
30 | end |
|
32 | end | |
31 |
|
33 | |||
32 | class SessionsTest < ActionController::TestCase |
|
34 | class SessionsTest < ActionController::TestCase | |
33 | tests WelcomeController |
|
35 | tests WelcomeController | |
34 |
|
36 | |||
|
37 | fixtures :users | |||
|
38 | ||||
35 | def test_atime_from_user_session_should_be_updated |
|
39 | def test_atime_from_user_session_should_be_updated | |
36 | created = 2.hours.ago.utc.to_i |
|
40 | created = 2.hours.ago.utc.to_i | |
37 | get :index, {}, {:user_id => 2, :ctime => created, :atime => created} |
|
41 | get :index, {}, {:user_id => 2, :ctime => created, :atime => created} | |
38 | assert_response :success |
|
42 | assert_response :success | |
39 | assert_equal created, session[:ctime] |
|
43 | assert_equal created, session[:ctime] | |
40 | assert_not_equal created, session[:atime] |
|
44 | assert_not_equal created, session[:atime] | |
41 | assert session[:atime] > created |
|
45 | assert session[:atime] > created | |
42 | end |
|
46 | end | |
43 |
|
47 | |||
44 | def test_user_session_should_not_be_reset_if_lifetime_and_timeout_disabled |
|
48 | def test_user_session_should_not_be_reset_if_lifetime_and_timeout_disabled | |
45 | with_settings :session_lifetime => '0', :session_timeout => '0' do |
|
49 | with_settings :session_lifetime => '0', :session_timeout => '0' do | |
46 | get :index, {}, {:user_id => 2} |
|
50 | get :index, {}, {:user_id => 2} | |
47 | assert_response :success |
|
51 | assert_response :success | |
48 | end |
|
52 | end | |
49 | end |
|
53 | end | |
50 |
|
54 | |||
51 | def test_user_session_without_ctime_should_be_reset_if_lifetime_enabled |
|
55 | def test_user_session_without_ctime_should_be_reset_if_lifetime_enabled | |
52 | with_settings :session_lifetime => '720' do |
|
56 | with_settings :session_lifetime => '720' do | |
53 | get :index, {}, {:user_id => 2} |
|
57 | get :index, {}, {:user_id => 2} | |
54 | assert_redirected_to '/login' |
|
58 | assert_redirected_to '/login' | |
55 | end |
|
59 | end | |
56 | end |
|
60 | end | |
57 |
|
61 | |||
58 | def test_user_session_with_expired_ctime_should_be_reset_if_lifetime_enabled |
|
62 | def test_user_session_with_expired_ctime_should_be_reset_if_lifetime_enabled | |
59 | with_settings :session_timeout => '720' do |
|
63 | with_settings :session_timeout => '720' do | |
60 | get :index, {}, {:user_id => 2, :atime => 2.days.ago.utc.to_i} |
|
64 | get :index, {}, {:user_id => 2, :atime => 2.days.ago.utc.to_i} | |
61 | assert_redirected_to '/login' |
|
65 | assert_redirected_to '/login' | |
62 | end |
|
66 | end | |
63 | end |
|
67 | end | |
64 |
|
68 | |||
65 | def test_user_session_with_valid_ctime_should_not_be_reset_if_lifetime_enabled |
|
69 | def test_user_session_with_valid_ctime_should_not_be_reset_if_lifetime_enabled | |
66 | with_settings :session_timeout => '720' do |
|
70 | with_settings :session_timeout => '720' do | |
67 | get :index, {}, {:user_id => 2, :atime => 3.hours.ago.utc.to_i} |
|
71 | get :index, {}, {:user_id => 2, :atime => 3.hours.ago.utc.to_i} | |
68 | assert_response :success |
|
72 | assert_response :success | |
69 | end |
|
73 | end | |
70 | end |
|
74 | end | |
71 |
|
75 | |||
72 | def test_user_session_without_atime_should_be_reset_if_timeout_enabled |
|
76 | def test_user_session_without_atime_should_be_reset_if_timeout_enabled | |
73 | with_settings :session_timeout => '60' do |
|
77 | with_settings :session_timeout => '60' do | |
74 | get :index, {}, {:user_id => 2} |
|
78 | get :index, {}, {:user_id => 2} | |
75 | assert_redirected_to '/login' |
|
79 | assert_redirected_to '/login' | |
76 | end |
|
80 | end | |
77 | end |
|
81 | end | |
78 |
|
82 | |||
79 | def test_user_session_with_expired_atime_should_be_reset_if_timeout_enabled |
|
83 | def test_user_session_with_expired_atime_should_be_reset_if_timeout_enabled | |
80 | with_settings :session_timeout => '60' do |
|
84 | with_settings :session_timeout => '60' do | |
81 | get :index, {}, {:user_id => 2, :atime => 4.hours.ago.utc.to_i} |
|
85 | get :index, {}, {:user_id => 2, :atime => 4.hours.ago.utc.to_i} | |
82 | assert_redirected_to '/login' |
|
86 | assert_redirected_to '/login' | |
83 | end |
|
87 | end | |
84 | end |
|
88 | end | |
85 |
|
89 | |||
86 | def test_user_session_with_valid_atime_should_not_be_reset_if_timeout_enabled |
|
90 | def test_user_session_with_valid_atime_should_not_be_reset_if_timeout_enabled | |
87 | with_settings :session_timeout => '60' do |
|
91 | with_settings :session_timeout => '60' do | |
88 | get :index, {}, {:user_id => 2, :atime => 10.minutes.ago.utc.to_i} |
|
92 | get :index, {}, {:user_id => 2, :atime => 10.minutes.ago.utc.to_i} | |
89 | assert_response :success |
|
93 | assert_response :success | |
90 | end |
|
94 | end | |
91 | end |
|
95 | end | |
92 |
|
96 | |||
93 | def test_expired_user_session_should_be_restarted_if_autologin |
|
97 | def test_expired_user_session_should_be_restarted_if_autologin | |
94 | with_settings :session_lifetime => '720', :session_timeout => '60', :autologin => 7 do |
|
98 | with_settings :session_lifetime => '720', :session_timeout => '60', :autologin => 7 do | |
95 | token = Token.create!(:user_id => 2, :action => 'autologin', :created_on => 1.day.ago) |
|
99 | token = Token.create!(:user_id => 2, :action => 'autologin', :created_on => 1.day.ago) | |
96 | @request.cookies['autologin'] = token.value |
|
100 | @request.cookies['autologin'] = token.value | |
97 | created = 2.hours.ago.utc.to_i |
|
101 | created = 2.hours.ago.utc.to_i | |
98 |
|
102 | |||
99 | get :index, {}, {:user_id => 2, :ctime => created, :atime => created} |
|
103 | get :index, {}, {:user_id => 2, :ctime => created, :atime => created} | |
100 | assert_equal 2, session[:user_id] |
|
104 | assert_equal 2, session[:user_id] | |
101 | assert_response :success |
|
105 | assert_response :success | |
102 | assert_not_equal created, session[:ctime] |
|
106 | assert_not_equal created, session[:ctime] | |
103 | assert session[:ctime] >= created |
|
107 | assert session[:ctime] >= created | |
104 | end |
|
108 | end | |
105 | end |
|
109 | end | |
106 |
|
110 | |||
107 | def test_anonymous_session_should_not_be_reset |
|
111 | def test_anonymous_session_should_not_be_reset | |
108 | with_settings :session_lifetime => '720', :session_timeout => '60' do |
|
112 | with_settings :session_lifetime => '720', :session_timeout => '60' do | |
109 | get :index |
|
113 | get :index | |
110 | assert_response :success |
|
114 | assert_response :success | |
111 | end |
|
115 | end | |
112 | end |
|
116 | end | |
113 | end |
|
117 | end |
General Comments 0
You need to be logged in to leave comments.
Login now