authentication_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Authentication', type: :system do
  4. it 'Login', authenticated_as: false do
  5. login(
  6. username: 'admin@example.com',
  7. password: 'test',
  8. )
  9. expect_current_route 'dashboard'
  10. end
  11. it 'Logout' do
  12. logout
  13. expect_current_route 'login', wait: 10
  14. end
  15. it 'will unset user attributes after logout' do
  16. logout
  17. expect_current_route 'login', wait: 10
  18. visit '/#signup'
  19. # check wrong displayed fields in registration form after logout. #2989
  20. expect(page).to have_no_selector('select[name=organization_id]')
  21. end
  22. it 'Login and redirect to requested url', authenticated_as: false do
  23. visit 'ticket/zoom/1'
  24. expect_current_route 'login', wait: 10
  25. login(
  26. username: 'admin@example.com',
  27. password: 'test',
  28. )
  29. expect_current_route 'ticket/zoom/1', wait: 10
  30. end
  31. it 'Login and redirect to requested url via external authentication', authenticated_as: false do
  32. visit 'ticket/zoom/1'
  33. expect_current_route 'login', wait: 10
  34. # simulate jump to external ressource
  35. visit 'https://www.zammad.org'
  36. # simulate successful login via third party
  37. user = User.find_by(login: 'admin@example.com')
  38. ActiveRecord::SessionStore::Session.all.each do |session|
  39. session.data[:user_id] = user.id
  40. session.save!
  41. end
  42. # jump back and check if origin requested url is shown
  43. visit ''
  44. expect_current_route 'ticket/zoom/1', wait: 10
  45. expect(current_login).to eq('admin@example.com')
  46. end
  47. end