diff --git a/app/controllers/application_controller/authenticates.rb b/app/controllers/application_controller/authenticates.rb index 503649b2f..54a72668a 100644 --- a/app/controllers/application_controller/authenticates.rb +++ b/app/controllers/application_controller/authenticates.rb @@ -43,6 +43,10 @@ module ApplicationController::Authenticates end def authentication_check_only(auth_param = {}) + if Rails.env.test? && ENV['FAKE_SELENIUM_LOGIN_USER_ID'].present? && session[:user_id].blank? + session[:user_id] = ENV['FAKE_SELENIUM_LOGIN_USER_ID'].to_i + end + # logger.debug 'authentication_check' # logger.debug params.inspect # logger.debug session.inspect diff --git a/spec/support/capybara/authenticated.rb b/spec/support/capybara/authenticated.rb index 020ffabe2..bf60a0bf3 100644 --- a/spec/support/capybara/authenticated.rb +++ b/spec/support/capybara/authenticated.rb @@ -12,12 +12,28 @@ RSpec.configure do |config| config.before(:each, type: :system) do |example| + ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil + # there is no way to authenticated in a not set up system next if !example.metadata.fetch(:set_up, true) authenticated = example.metadata.fetch(:authenticated_as, true) - credentials = authenticated_as_get_user(authenticated, return_type: :credentials) + credentials = authenticated_as_get_user(authenticated, return_type: :credentials) - login(**credentials) if credentials + authentication_type = example.metadata.fetch(:authentication_type, :auto) + + next if credentials.nil? + + if authentication_type == :form + login(**credentials) + else + ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = User.find_by(email: credentials[:username]).id.to_s + + visit '/' + + wait(4).until_exists do + current_login + end + end end end diff --git a/spec/support/capybara/common_actions.rb b/spec/support/capybara/common_actions.rb index 309b422c5..f920d5914 100644 --- a/spec/support/capybara/common_actions.rb +++ b/spec/support/capybara/common_actions.rb @@ -22,6 +22,8 @@ module CommonActions # # return [nil] def login(username:, password:, remember_me: false) + ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil + visit '/' within('#login') do @@ -91,6 +93,7 @@ module CommonActions # logout # def logout + ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil visit('logout') wait.until_disappears { find('.user-menu .user a', wait: false) } diff --git a/spec/support/capybara/selenium_driver.rb b/spec/support/capybara/selenium_driver.rb index 12612609c..3ee2d5efe 100644 --- a/spec/support/capybara/selenium_driver.rb +++ b/spec/support/capybara/selenium_driver.rb @@ -27,6 +27,8 @@ Capybara.register_driver(:zammad_chrome) do |app| options[:url] = ENV['REMOTE_URL'] end + ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil + Capybara::Selenium::Driver.new(app, **options).tap do |driver| # Selenium 4 installs a default file_detector which finds wrong files/directories such as zammad/test. driver.browser.file_detector = nil if ENV['REMOTE_URL'].present? @@ -51,6 +53,8 @@ Capybara.register_driver(:zammad_firefox) do |app| options[:url] = ENV['REMOTE_URL'] end + ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil + Capybara::Selenium::Driver.new(app, **options).tap do |driver| # Selenium 4 installs a default file_detector which finds wrong files/directories such as zammad/test. driver.browser.file_detector = nil if ENV['REMOTE_URL'].present? diff --git a/spec/system/knowledge_base_public/editor_spec.rb b/spec/system/knowledge_base_public/editor_spec.rb index f215e8e2e..87d630ceb 100644 --- a/spec/system/knowledge_base_public/editor_spec.rb +++ b/spec/system/knowledge_base_public/editor_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe 'Public Knowledge Base for editor', type: :system do +RSpec.describe 'Public Knowledge Base for editor', authentication_type: :form, type: :system do include_context 'basic Knowledge Base' before do diff --git a/spec/system/manage/users_spec.rb b/spec/system/manage/users_spec.rb index bb3324f0d..aeec624f4 100644 --- a/spec/system/manage/users_spec.rb +++ b/spec/system/manage/users_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe 'Manage > Users', type: :system do - describe 'switching to an alternative user', authenticated_as: -> { original_user } do + describe 'switching to an alternative user', authentication_type: :form, authenticated_as: -> { original_user } do let(:original_user) { create(:admin) } let(:alternative_one_user) { create(:admin) } let(:alternative_two_user) { create(:admin) } diff --git a/spec/system/online_notification_spec.rb b/spec/system/online_notification_spec.rb index ca65801f6..6ebe81e2f 100644 --- a/spec/system/online_notification_spec.rb +++ b/spec/system/online_notification_spec.rb @@ -15,6 +15,8 @@ RSpec.describe 'Online notification', type: :system do context 'when pending time is reached soon' do before do visit "ticket/zoom/#{ticket.id}" + + wait.until_exists { find("a[data-key='Ticket-#{ticket.id}']", wait: 0) } end let(:ticket) { create(:ticket, owner: session_user, group: Group.first, state_name: 'pending reminder', pending_time: 4.seconds.from_now) } @@ -44,6 +46,8 @@ RSpec.describe 'Online notification', type: :system do before do ensure_websocket do visit "ticket/zoom/#{ticket.id}" + + wait.until_exists { find("a[data-key='Ticket-#{ticket.id}']", wait: 0) } end ticket.update! state: Ticket::State.lookup(name: 'pending reminder'), pending_time: 5.seconds.from_now