Maintenance: Simulate login instead of using the real login form all the time.

This commit is contained in:
Dominik Klein 2021-11-04 14:40:58 +01:00
parent 44703499e3
commit dc5ba3cbaa
7 changed files with 35 additions and 4 deletions

View file

@ -43,6 +43,10 @@ module ApplicationController::Authenticates
end end
def authentication_check_only(auth_param = {}) 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 'authentication_check'
# logger.debug params.inspect # logger.debug params.inspect
# logger.debug session.inspect # logger.debug session.inspect

View file

@ -12,12 +12,28 @@ RSpec.configure do |config|
config.before(:each, type: :system) do |example| 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 # there is no way to authenticated in a not set up system
next if !example.metadata.fetch(:set_up, true) next if !example.metadata.fetch(:set_up, true)
authenticated = example.metadata.fetch(:authenticated_as, 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
end end

View file

@ -22,6 +22,8 @@ module CommonActions
# #
# return [nil] # return [nil]
def login(username:, password:, remember_me: false) def login(username:, password:, remember_me: false)
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
visit '/' visit '/'
within('#login') do within('#login') do
@ -91,6 +93,7 @@ module CommonActions
# logout # logout
# #
def logout def logout
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
visit('logout') visit('logout')
end end

View file

@ -29,6 +29,8 @@ Capybara.register_driver(:zammad_chrome) do |app|
options[:url] = ENV['REMOTE_URL'] options[:url] = ENV['REMOTE_URL']
end end
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
Capybara::Selenium::Driver.new(app, **options) Capybara::Selenium::Driver.new(app, **options)
end end
@ -54,5 +56,7 @@ Capybara.register_driver(:zammad_firefox) do |app|
options[:url] = ENV['REMOTE_URL'] options[:url] = ENV['REMOTE_URL']
end end
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
Capybara::Selenium::Driver.new(app, **options) Capybara::Selenium::Driver.new(app, **options)
end end

View file

@ -2,7 +2,7 @@
require 'rails_helper' 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' include_context 'basic Knowledge Base'
before do before do

View file

@ -3,7 +3,7 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe 'Manage > Users', type: :system do 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(:original_user) { create(:admin) }
let(:alternative_one_user) { create(:admin) } let(:alternative_one_user) { create(:admin) }
let(:alternative_two_user) { create(:admin) } let(:alternative_two_user) { create(:admin) }

View file

@ -15,6 +15,8 @@ RSpec.describe 'Online notification', type: :system do
context 'when pending time is reached soon' do context 'when pending time is reached soon' do
before do before do
visit "ticket/zoom/#{ticket.id}" visit "ticket/zoom/#{ticket.id}"
wait.until_exists { find("a[data-key='Ticket-#{ticket.id}']", wait: 0) }
end end
let(:ticket) { create(:ticket, owner: session_user, group: Group.first, state_name: 'pending reminder', pending_time: 4.seconds.from_now) } 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 before do
ensure_websocket do ensure_websocket do
visit "ticket/zoom/#{ticket.id}" visit "ticket/zoom/#{ticket.id}"
wait.until_exists { find("a[data-key='Ticket-#{ticket.id}']", wait: 0) }
end end
ticket.update! state: Ticket::State.lookup(name: 'pending reminder'), pending_time: 5.seconds.from_now ticket.update! state: Ticket::State.lookup(name: 'pending reminder'), pending_time: 5.seconds.from_now