authenticated.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # This file registers a hook before each system test
  3. # which logs in with/authenticates the admin@example.com account.
  4. # we need to make sure that Capybara is configured/started before
  5. # this hook. Otherwise a login try is performed while the app/puma
  6. # hasn't started yet.
  7. require_relative 'driven_by'
  8. RSpec.configure do |config|
  9. config.before(:each, type: :system) do |example|
  10. ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
  11. ENV['FAKE_SELENIUM_LOGIN_PENDING'] = nil
  12. # there is no way to authenticated in a not set up system
  13. next if !example.metadata.fetch(:set_up, true)
  14. authenticated = example.metadata.fetch(:authenticated_as, true)
  15. credentials = authenticated_as_get_user(authenticated, return_type: :credentials)
  16. authentication_type = example.metadata.fetch(:authentication_type, :auto)
  17. next if credentials.nil?
  18. if authentication_type == :form
  19. login(**credentials, app: example.metadata[:app])
  20. else
  21. ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = User.find_by(email: credentials[:username]).id.to_s
  22. if %i[desktop_view mobile].exclude?(example.metadata[:app])
  23. ENV['FAKE_SELENIUM_LOGIN_PENDING'] = 'true'
  24. end
  25. end
  26. end
  27. end