|
| 1 | +#-- copyright |
| 2 | +# OpenProject is a project management system. |
| 3 | +# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
| 4 | +# |
| 5 | +# This program is free software; you can redistribute it and/or |
| 6 | +# modify it under the terms of the GNU General Public License version 3. |
| 7 | +# |
| 8 | +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
| 9 | +# Copyright (C) 2006-2017 Jean-Philippe Lang |
| 10 | +# Copyright (C) 2010-2013 the ChiliProject Team |
| 11 | +# |
| 12 | +# This program is free software; you can redistribute it and/or |
| 13 | +# modify it under the terms of the GNU General Public License |
| 14 | +# as published by the Free Software Foundation; either version 2 |
| 15 | +# of the License, or (at your option) any later version. |
| 16 | +# |
| 17 | +# This program is distributed in the hope that it will be useful, |
| 18 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | +# GNU General Public License for more details. |
| 21 | +# |
| 22 | +# You should have received a copy of the GNU General Public License |
| 23 | +# along with this program; if not, write to the Free Software |
| 24 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 25 | +# |
| 26 | +# See doc/COPYRIGHT.rdoc for more details. |
| 27 | +#++ |
| 28 | + |
| 29 | +require 'spec_helper' |
| 30 | + |
| 31 | +describe 'Session TTL', |
| 32 | + with_settings: {session_ttl_enabled?: true, session_ttl: '10'}, |
| 33 | + type: :feature do |
| 34 | + let!(:user) {FactoryGirl.create :admin} |
| 35 | + let!(:work_package) {FactoryGirl.create :work_package} |
| 36 | + |
| 37 | + before do |
| 38 | + login_with(user.login, user.password) |
| 39 | + end |
| 40 | + |
| 41 | + def expire! |
| 42 | + page.set_rack_session(updated_at: Time.now - 1.hour) |
| 43 | + end |
| 44 | + |
| 45 | + describe 'outdated TTL on Rails request' do |
| 46 | + it 'expires on the next Rails request' do |
| 47 | + visit '/my/account' |
| 48 | + expect(page).to have_selector('.form--field-container', text: user.login) |
| 49 | + |
| 50 | + # Expire the session |
| 51 | + expire! |
| 52 | + |
| 53 | + visit '/' |
| 54 | + expect(page).to have_selector('.action-login') |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + describe 'outdated TTL on API request' do |
| 59 | + it 'expires on the next APIv3 request' do |
| 60 | + visit "/api/v3/work_packages/#{work_package.id}" |
| 61 | + |
| 62 | + body = JSON.parse(page.body) |
| 63 | + expect(body['id']).to eq(work_package.id) |
| 64 | + |
| 65 | + # Expire the session |
| 66 | + expire! |
| 67 | + visit "/api/v3/work_packages/#{work_package.id}" |
| 68 | + |
| 69 | + expect(page.body).to eq('unauthorized') |
| 70 | + end |
| 71 | + end |
| 72 | +end |
0 commit comments