OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Rework autologin cookie to not be unique
Oliver Günther885836184a16
diff --git a/app/controllers/concerns/accounts/authentication_stages.rb b/app/controllers/concerns/accounts/authentication_stages.rbindex e07cdcc8b3f..1ddb7bf5fbd 100644--- a/app/controllers/concerns/accounts/authentication_stages.rb+++ b/app/controllers/concerns/accounts/authentication_stages.rb@@ -91,7 +91,7 @@ module Accounts::AuthenticationStagessession[:back_url] ||= params[:back_url]# Remember the autologin cookie decision- session[:autologin_requested] = params[:autologin]+ session[:autologin_requested] = params[:autologin] == '1'stagesenddiff --git a/app/controllers/concerns/accounts/current_user.rb b/app/controllers/concerns/accounts/current_user.rbindex b94bd6da037..55103fb01b2 100644--- a/app/controllers/concerns/accounts/current_user.rb+++ b/app/controllers/concerns/accounts/current_user.rb@@ -67,22 +67,57 @@ module Accounts::CurrentUser# Returns the current user or nil if no user is logged in# and starts a session if neededdef find_current_user- if session[:user_id]- # existing session- User.active.find_by(id: session[:user_id])- elsif cookies[OpenProject::Configuration['autologin_cookie_name']] && Setting::Autologin.enabled?- # auto-login feature starts a new session- user = User.try_to_autologin(cookies[OpenProject::Configuration['autologin_cookie_name']])- session[:user_id] = user.id if user+ %i[+ current_session_user+ current_autologin_user+ current_rss_key_user+ current_api_key_user+ ].each do |method|+ user = send(method)+ return user if user&.logged? && user&.active?+ end++ nil+ end++ def current_session_user+ return if session[:user_id].nil?++ User.active.find_by(id: session[:user_id])+ end++ def current_autologin_user+ return unless Setting::Autologin.enabled?++ autologin_cookie_name = OpenProject::Configuration['autologin_cookie_name']+ autologin_token = cookies[autologin_cookie_name]+ return unless autologin_token++ user = User.try_to_autologin(autologin_token)++ if user+ login_user(user)user- elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])+ else+ cookies.delete(autologin_cookie_name)+ nil+ end+ end++ def current_rss_key_user+ if params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])# RSS key authentication does not start a sessionUser.find_by_rss_key(params[:key])- elsif Setting.rest_api_enabled? && api_request?- if (key = api_key_from_request) && accept_key_auth_actions.include?(params[:action])- # Use API key- User.find_by_api_key(key)- end+ end+ end++ def current_api_key_user+ return unless Setting.rest_api_enabled? && api_request?+ key = api_key_from_request++ if key && accept_key_auth_actions.include?(params[:action])+ # Use API key+ User.find_by_api_key(key)endend@@ -127,8 +162,8 @@ module Accounts::CurrentUser# Login the current userdef login_user(user)::Users::LoginService- .new(controller: self, request:)- .call(user)+ .new(user:, controller: self, request:)+ .call!enddef require_logindiff --git a/app/controllers/concerns/accounts/user_login.rb b/app/controllers/concerns/accounts/user_login.rbindex 0fb1faf7a3a..698f8280588 100644--- a/app/controllers/concerns/accounts/user_login.rb+++ b/app/controllers/concerns/accounts/user_login.rb@@ -3,11 +3,6 @@ module Accounts::UserLogininclude ::Accounts::RedirectAfterLogindef login_user!(user)- # generate a key and set cookie if autologin- if Setting::Autologin.enabled? && (params[:autologin] || session.delete(:autologin_requested))- set_autologin_cookie(user)- end-# Set the logged user, resetting their sessionself.logged_user = user@@ -15,16 +10,4 @@ module Accounts::UserLoginredirect_after_login(user)end-- def set_autologin_cookie(user)- token = Token::AutoLogin.create(user:)- cookie_options = {- value: token.plain_value,- expires: 1.year.from_now,- path: OpenProject::Configuration['autologin_cookie_path'],- secure: OpenProject::Configuration['autologin_cookie_secure'],- httponly: true- }- cookies[OpenProject::Configuration['autologin_cookie_name']] = cookie_options- endenddiff --git a/app/models/sessions/sql_bypass.rb b/app/models/sessions/sql_bypass.rbindex dd9147154c5..41b513e135d 100644--- a/app/models/sessions/sql_bypass.rb+++ b/app/models/sessions/sql_bypass.rb@@ -71,13 +71,6 @@ module Sessionsendend- ##- # Also destroy any other session when this one is actively destroyed- def destroy- delete_user_sessions- super- end-privatedef user_id@@ -109,12 +102,5 @@ module SessionsWHERE session_id=#{connection.quote(@retrieved_by)}SQLend-- def delete_user_sessions- uid = user_id- return unless uid && OpenProject::Configuration.drop_old_sessions_on_logout?-- ::Sessions::UserSession.for_user(uid).delete_all- endendenddiff --git a/app/models/token/auto_login.rb b/app/models/token/auto_login.rbindex a1dea79ce9f..9449acd6c84 100644--- a/app/models/token/auto_login.rb+++ b/app/models/token/auto_login.rb@@ -28,5 +28,12 @@module Tokenclass AutoLogin < HashedToken+ protected++ ##+ # Autologin tokens might have multiple data+ def single_value?+ false+ endendenddiff --git a/app/models/user.rb b/app/models/user.rbindex a5b7d65b388..2742dfc7c22 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -259,7 +259,6 @@ class User < Principaltoken = Token::AutoLogin.find_by_plaintext_value(key)# Make sure there's only 1 token that matches the keyif token && ((token.created_at > Setting.autologin.to_i.day.ago) && token.user && token.user.active?)- token.user.log_successful_logintoken.userendenddiff --git a/app/services/sessions/initialize_session_service.rb b/app/services/sessions/initialize_session_service.rbdeleted file mode 100644index 69a49a004fe..00000000000--- a/app/services/sessions/initialize_session_service.rb+++ /dev/null@@ -1,57 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2023 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# 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.-#-# See COPYRIGHT and LICENSE files for more details.-#++-module Sessions- class InitializeSessionService- class << self- ##- # Initializes a new session for the given user.- # This services provides very little for what it is called,- # mainly caused due to the many ways a user can login.- def call(user, session)- session[:user_id] = user.id- session[:updated_at] = Time.now-- if drop_old_sessions?- Rails.logger.info { "Deleting all other sessions for #{user}." }- ::Sessions::UserSession.for_user(user).delete_all- end-- ServiceResult.success(result: session)- end-- private-- ##- # We can only drop old sessions if they're stored in the database- # and enabled by configuration.- def drop_old_sessions?- OpenProject::Configuration.drop_old_sessions_on_login?- end- end- end-enddiff --git a/app/services/users/login_service.rb b/app/services/users/login_service.rbindex 26d6ba609b6..11b00d2481d 100644--- a/app/services/users/login_service.rb+++ b/app/services/users/login_service.rb@@ -28,42 +28,82 @@module Usersclass LoginService- attr_accessor :controller, :request, :browser+ attr_accessor :controller, :request, :browser, :user, :cookiesdelegate :session, to: :controller- def initialize(controller:, request:)+ def initialize(user:, controller:, request:)+ self.user = userself.controller = controllerself.request = requestself.browser = controller.send(:browser)+ self.cookies = controller.send(:cookies)end- def call(user)- # retain custom session values- retained_values = retain_sso_session_values!+ def call!+ autologin_requested = session.delete(:autologin_requested)+ retain_session_values do+ reset_session!- # retain flash values- flash_values = controller.flash.to_h+ User.current = user- controller.reset_session-- flash_values.each { |k, v| controller.flash[k] = v }+ set_autologin_cookie if autologin_requested- User.current = user+ successful_login+ end+ end- ::Sessions::InitializeSessionService.call(user, session)+ private- session.merge!(retained_values) if retained_values- session.merge!(session_identification)+ def set_autologin_cookie+ return unless Setting::Autologin.enabled?++ # generate a key and set cookie if autologin+ token = Token::AutoLogin.create(user:, data: session_identification)+ cookie_options = {+ value: token.plain_value,+ # The autologin expiry is checked on validating the token+ # but still expire the cookie to avoid unnecessary retries+ expires: Setting.autologin.days.from_now.beginning_of_day,+ path: OpenProject::Configuration['autologin_cookie_path'],+ secure: OpenProject::Configuration.https?,+ httponly: true+ }+ cookies[OpenProject::Configuration['autologin_cookie_name']] = cookie_options+ end+ def successful_loginuser.log_successful_login- after_login_hook(user)+ context = { user:, request:, session: }+ OpenProject::Hook.call_hook(:user_logged_in, context)+ end- ServiceResult.success(result: user)+ def reset_session!+ Sessions::DropAllSessionsService.call(user) if drop_old_sessions?+ controller.reset_sessionend- private+ def retain_session_values+ # retain flash values+ flash_values = controller.flash.to_h++ # retain session values+ retained_session = retained_session_values || {}++ yield++ flash_values.each { |k, v| controller.flash[k] = v }++ session.merge!(retained_session)+ session.merge!(session_identification)+ apply_default_values(session)+ end++ def apply_default_values(session)+ session[:user_id] = user.id+ session[:updated_at] = Time.zone.now+ enddef session_identification{@@ -73,13 +113,7 @@ module Users}end- def after_login_hook(user)- context = { user:, request:, session: }-- OpenProject::Hook.call_hook(:user_logged_in, context)- end-- def retain_sso_session_values!+ def retained_session_valuesprovider_name = session[:omniauth_provider]return unless provider_name@@ -89,5 +123,12 @@ module Usersretained_keys = provider[:retain_from_session] + ['omniauth_provider']controller.session.to_h.slice(*retained_keys)end++ ##+ # We can only drop old sessions if they're stored in the database+ # and enabled by configuration.+ def drop_old_sessions?+ OpenProject::Configuration.drop_old_sessions_on_login?+ endendenddiff --git a/app/services/users/logout_service.rb b/app/services/users/logout_service.rbindex a45b9e91e8c..9802138bd9a 100644--- a/app/services/users/logout_service.rb+++ b/app/services/users/logout_service.rb@@ -35,19 +35,25 @@ module Usersenddef call(user)+ OpenProject.logger.info { "Logging out ##{user.id}" }controller.reset_session- if user.logged?- remove_cookies! controller.send(:cookies)+ remove_cookies! controller.send(:cookies)++ if OpenProject::Configuration.drop_old_sessions_on_logout?remove_tokens! user+ remove_sessions! userendUser.current = User.anonymous- ServiceResult.failure(result: User.anonymous)endprivate+ def remove_sessions!(user)+ ::Sessions::UserSession.for_user(user.id).delete_all+ end+def remove_tokens!(user)Token::AutoLogin.where(user_id: user.id).delete_allenddiff --git a/app/views/account/_login.html.erb b/app/views/account/_login.html.erbindex 8049d825213..e43dc895778 100644--- a/app/views/account/_login.html.erb+++ b/app/views/account/_login.html.erb@@ -40,8 +40,10 @@ See COPYRIGHT and LICENSE files for more details.</div><div class="form--field-extra-actions"><% if Setting::Autologin.enabled? %>- <label class="form--label-with-check-box">- <%= styled_check_box_tag 'autologin', 1, false, id: 'autologin-pulldown' %> <%= t(:label_stay_logged_in) %></label>+ <label class="form--label-with-check-box -no-ellipsis">+ <%= styled_check_box_tag 'autologin', 1, false, id: 'autologin-pulldown' %>+ <%= t('users.autologins.prompt', num_days: I18n.t('datetime.distance_in_words.x_days', count: Setting.autologin)) %>+ </label><% elsif Setting::SelfRegistration.enabled? %><%# show here if autologin is disabled, otherwise below lost_password link %><%= link_to t(:label_register),diff --git a/app/views/account/_password_login_form.html.erb b/app/views/account/_password_login_form.html.erbindex 6b182c98678..47d803b0861 100644--- a/app/views/account/_password_login_form.html.erb+++ b/app/views/account/_password_login_form.html.erb@@ -49,7 +49,7 @@ See COPYRIGHT and LICENSE files for more details.<div class="form--field-container"><label class="form--label-with-check-box"><%= styled_check_box_tag 'autologin', 1, false %>- <%= t(:label_stay_logged_in) %>+ <%= t('users.autologins.prompt', num_days: I18n.t('datetime.distance_in_words.x_days', count: Setting.autologin)) %></label></div></div>diff --git a/app/views/admin/settings/authentication_settings/show.html.erb b/app/views/admin/settings/authentication_settings/show.html.erbindex 7183f9f511b..a8d1a572caa 100644--- a/app/views/admin/settings/authentication_settings/show.html.erb+++ b/app/views/admin/settings/authentication_settings/show.html.erb@@ -107,7 +107,7 @@ See COPYRIGHT and LICENSE files for more details.<legend class="form--fieldset-legend"><%= I18n.t(:session, scope: [:settings]) %></legend><div class="form--field -wide-label"><%= setting_select :autologin,([[t(:label_disabled), 0]] +- [1, 7, 30, 365].collect do |days|+ Settings::Definition[:autologin].allowed.collect do |days|[t('datetime.distance_in_words.x_days', count: days),days.to_s]end),diff --git a/app/views/my/sessions/index.html.erb b/app/views/my/sessions/index.html.erbindex 14fd61e528f..87e6d462081 100644--- a/app/views/my/sessions/index.html.erb+++ b/app/views/my/sessions/index.html.erb@@ -30,6 +30,13 @@ See COPYRIGHT and LICENSE files for more details.<%= toolbar title: t('users.sessions.title') -%>-<p><%= t('users.sessions.instructions')%></p>+<p><%= t('users.sessions.instructions') %></p>-<%= render ::Users::Sessions::TableComponent.new(rows: @sessions, current_session: session) %>+<%= render ::Users::Sessions::TableComponent.new(rows: @sessions, current_session: session) %>++<h2></h2>++<% ::Token::AutoLogin.where(user: User.current).find_each do |token| %>+ <%= token.data.inspect %>+ <br/>+<% end %>diff --git a/config/configuration.yml.example b/config/configuration.yml.exampleindex 47154aaea3d..74c5c794e92 100644--- a/config/configuration.yml.example+++ b/config/configuration.yml.example@@ -221,10 +221,8 @@ default:# Configuration of the autologin cookie.# autologin_cookie_name: the name of the cookie (default: autologin)# autologin_cookie_path: the cookie path (default: /)- # autologin_cookie_secure: true sets the cookie secure flag (default: false)# autologin_cookie_name:# autologin_cookie_path:- # autologin_cookie_secure:# Configuration of the session cookie# session_cookie_name: the name of the OpenProject cookie (default: _open_project_session)diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 4c9f031867a..fb177611ea5 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -121,7 +121,9 @@ module Settings# autologin duration in days# 0 means autologin is disabledautologin: {- default: 0+ format: :integer,+ default: 0,+ allowed: [1, 7, 14, 30, 60, 90, 365]},autologin_cookie_name: {description: 'Cookie name for autologin cookie',@@ -133,11 +135,6 @@ module Settingsdefault: '/',writable: false},- autologin_cookie_secure: {- description: 'Cookie secure mode for autologin cookie',- default: false,- writable: false- },available_languages: {format: :array,default: %w[en de fr es pt it zh-CN ko ru].freeze,diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 03390659f47..5ec2ee16e12 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -321,6 +321,9 @@ en:no_results_content_text: Add a news itemusers:+ autologins:+ prompt: "Stay logged in for %{num_days}"+ title: "Remembered devices"sessions:session_name: "%{browser_name} %{browser_version} on %{os_name}"browser: "Browser"@@ -2143,7 +2146,6 @@ en:label_start_to_start: "start to start"label_statistics: "Statistics"label_status: "Status"- label_stay_logged_in: "Stay logged in"label_storage_free_space: "Remaining disk space"label_storage_used_space: "Used disk space"label_storage_group: "Storage filesystem %{identifier}"diff --git a/db/migrate/20231105194747_add_data_to_tokens.rb b/db/migrate/20231105194747_add_data_to_tokens.rbnew file mode 100644index 00000000000..fd828475cb9--- /dev/null+++ b/db/migrate/20231105194747_add_data_to_tokens.rb@@ -0,0 +1,5 @@+class AddDataToTokens < ActiveRecord::Migration[7.0]+ def change+ add_column :tokens, :data, :json, null: true+ end+enddiff --git a/docs/installation-and-operations/configuration/README.md b/docs/installation-and-operations/configuration/README.mdindex 35744345ef3..d4943a9ce87 100644--- a/docs/installation-and-operations/configuration/README.md+++ b/docs/installation-and-operations/configuration/README.md@@ -263,7 +263,6 @@ When a filter is defined, synchronization happens directly during seeding for en* `attachments_storage_path`* `autologin_cookie_name` (default: 'autologin'),* `autologin_cookie_path` (default: '/')-* `autologin_cookie_secure` (default: false)* `database_cipher_key` (default: nil)* `scm_git_command` (default: 'git')* `scm_subversion_command` (default: 'svn')diff --git a/spec/features/auth/consent_auth_stage_spec.rb b/spec/features/auth/consent_auth_stage_spec.rbindex 2c2da632d0f..cf3de8bbb5b 100644--- a/spec/features/auth/consent_auth_stage_spec.rb+++ b/spec/features/auth/consent_auth_stage_spec.rb@@ -53,7 +53,8 @@ RSpec.describe 'Authentication Stages' do.and_return(consent_required)end- def expect_logged_in+ def expect_logged_in(path = my_page_path)+ expect(page).to have_current_path(path)visit my_account_pathexpect(page).to have_selector('.form--field-container', text: user.login)end@@ -73,7 +74,7 @@ RSpec.describe 'Authentication Stages' doendit 'keeps the autologin request (Regression #33696)',- with_settings: { autologin: '1' } do+ with_settings: { autologin: 1 } doexpect(Setting::Autologin.enabled?).to be truelogin_with user.login, user_password, autologin: true@@ -104,8 +105,11 @@ RSpec.describe 'Authentication Stages' dowith_settings: { consent_info: { de: '# Einwilligung', en: '# Consent header!' } } dolet(:consent_required) { true }- before do+ around do |example|Capybara.current_session.driver.header('Accept-Language', 'de')+ example.call+ ensure+ Capybara.current_session.driver.header('Accept-Language', 'en')endit 'shows localized consent as defined by the accept language header (ignoring users language)' do@@ -116,7 +120,9 @@ RSpec.describe 'Authentication Stages' doendend- context 'when enabled, but consent exists', js: true, with_settings: { consent_info: { en: '# Consent header!' } } do+ context 'when enabled, but consent exists',+ :js,+ with_settings: { consent_info: { en: '# Consent header!' } } dolet(:consent_required) { true }after do@@ -206,11 +212,11 @@ RSpec.describe 'Authentication Stages' doclick_on I18n.t(:button_create)expect(page).to have_selector('.op-toast.-success')- expect_logged_in+ expect_logged_in('/?first_time_user=true')endit 'keeps the autologin request (Regression #33696)',- with_settings: { autologin: '1' } do+ with_settings: { autologin: 1 } doexpect(Setting::Autologin.enabled?).to be truelogin_with user.login, user_password, autologin: true@@ -228,8 +234,8 @@ RSpec.describe 'Authentication Stages' domanager = page.driver.browser.manageautologin_cookie = manager.cookie_named('autologin')expect(autologin_cookie[:name]).to eq 'autologin'- # Cookie always expires in 1 year, check is made with the token expiry date- expect(autologin_cookie[:expires].to_date).to eq (Date.today + 1.year)+ # Cookie is set to expire at the given day+ expect(autologin_cookie[:expires].to_date).to eq (Date.today + 1.day)endcontext 'with contact mail address', with_settings: { consent_decline_mail: '[email protected]' } dodiff --git a/spec/services/users/login_service_spec.rb b/spec/services/users/login_service_spec.rbindex 3dcbb09d18d..5c43e9276d7 100644--- a/spec/services/users/login_service_spec.rb+++ b/spec/services/users/login_service_spec.rb@@ -29,7 +29,7 @@require 'spec_helper'RSpec.describe Users::LoginService, type: :model do- let(:input_user) { build_stubbed(:user) }+ shared_let(:input_user) { create(:user) }let(:request) { {} }let(:session) { {} }let(:browser) do@@ -38,12 +38,24 @@ RSpec.describe Users::LoginService, type: :model doversion: '13.2',platform: instance_double(Browser::Platform::Linux, name: 'Linux'))end- let(:controller) { double(ApplicationController, browser:) } # rubocop:disable RSpec/VerifiedDoubles+ let(:cookies) { {} }let(:flash) { ActionDispatch::Flash::FlashHash.new }+ let(:controller) { instance_double(ApplicationController, browser:, cookies:, session:, flash:) }- let(:instance) { described_class.new(controller:, request:) }+ let(:instance) { described_class.new(user: input_user, controller:, request:) }- subject { instance.call(input_user) }+ subject { instance.call! }++ before do+ allow(controller)+ .to(receive(:reset_session)) do+ session.clear+ flash.clear+ end++ allow(input_user)+ .to receive(:log_successful_login)+ enddescribe 'session' docontext 'with an SSO provider' do@@ -59,23 +71,6 @@ RSpec.describe Users::LoginService, type: :model do.to(receive(:find_provider_by_name)).with('provider_name').and_return sso_provider-- allow(controller)- .to(receive(:session))- .and_return session-- allow(controller)- .to(receive(:flash))- .and_return flash-- allow(controller)- .to(receive(:reset_session)) do- session.clear- flash.clear- end-- allow(input_user)- .to receive(:log_successful_login)endcontext 'if provider retains session values' do@@ -103,4 +98,71 @@ RSpec.describe Users::LoginService, type: :model doendendend++ describe 'autologin cookie' do+ before do+ session[:autologin_requested] = true if autologin_requested+ end++ shared_examples 'does not set autologin cookie' do+ it 'does not set a cookie' do+ subject++ expect(Token::AutoLogin.exists?(user: input_user)).to be false+ expect(cookies[OpenProject::Configuration['autologin_cookie_name']]).to be_nil+ end+ end++ context 'when not requested and disabled', with_settings: { autologin: 0 } do+ let(:autologin_requested) { false }++ it_behaves_like 'does not set autologin cookie'+ end++ context 'when not requested and enabled', with_settings: { autologin: 1 } do+ let(:autologin_requested) { false }++ it_behaves_like 'does not set autologin cookie'+ end++ context 'when requested, but disabled', with_settings: { autologin: 0 } do+ let(:autologin_requested) { true }++ it_behaves_like 'does not set autologin cookie'+ end++ context 'when requested and enabled', with_settings: { autologin: 1 } do+ let(:autologin_requested) { true }++ it 'sets a cookie' do+ subject++ tokens = Token::AutoLogin.where(user: input_user)+ expect(tokens.count).to eq 1+ expect(tokens.first.user_id).to eq input_user.id++ autologin_cookie = cookies[OpenProject::Configuration['autologin_cookie_name']]+ expect(autologin_cookie).to be_present+ expect(autologin_cookie[:value]).to be_present+ expect(autologin_cookie[:expires]).to eq (Time.zone.today + 1.day).beginning_of_day+ expect(autologin_cookie[:path]).to eq '/'+ expect(autologin_cookie[:httponly]).to be true+ expect(autologin_cookie[:secure]).to eq Setting.https?+ expect(Token::AutoLogin.find_by_plaintext_value(autologin_cookie[:value])).to eq tokens.first+ end+ end++ context 'when requested and enabled with https',+ with_config: { https: true },+ with_settings: { autologin: 1 } do+ let(:autologin_requested) { true }++ it 'sets a secure cookie' do+ subject++ autologin_cookie = cookies[OpenProject::Configuration['autologin_cookie_name']]+ expect(autologin_cookie[:secure]).to be true+ end+ end+ endenddiff --git a/spec/support/authentication_helpers.rb b/spec/support/authentication_helpers.rbindex 4cfbc9d8e88..1f85ce3d42a 100644--- a/spec/support/authentication_helpers.rb+++ b/spec/support/authentication_helpers.rb@@ -58,7 +58,11 @@ module AuthenticationHelperswithin('.user-login--form') dofill_in 'username', with: loginfill_in 'password', with: password- check I18n.t(:label_stay_logged_in) if autologin+ if autologin+ autologin_label = I18n.t('users.autologins.prompt',+ num_days: I18n.t('datetime.distance_in_words.x_days', count: Setting.autologin))+ check autologin_label+ endclick_button I18n.t(:button_login)endend