authentication_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://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. refresh
  11. # Check that cookies is temporary.
  12. cookie = cookie('^_zammad.+?')
  13. expect(cookie[:expires]).to be_nil
  14. end
  15. it 'Login with remember me', authenticated_as: false do
  16. login(
  17. username: 'admin@example.com',
  18. password: 'test',
  19. remember_me: true
  20. )
  21. expect_current_route 'dashboard'
  22. refresh
  23. # Check that cookies has a expire date.
  24. cookie = cookie('^_zammad.+?')
  25. expect(cookie[:expires]).to be_truthy
  26. logout
  27. expect_current_route 'login'
  28. # Check that cookies has no longer a expire date after logout.
  29. cookie = cookie('^_zammad.+?')
  30. expect(cookie[:expires]).to be_nil
  31. end
  32. it 'Logout' do
  33. logout
  34. expect_current_route 'login'
  35. end
  36. it 'unsets user attributes after logout' do
  37. logout
  38. expect_current_route 'login'
  39. visit '/#signup'
  40. # check wrong displayed fields in registration form after logout. #2989
  41. expect(page).to have_no_select('organization_id')
  42. end
  43. it 'Login and redirect to requested url', authenticated_as: false do
  44. visit 'ticket/zoom/1'
  45. expect_current_route 'login'
  46. login(
  47. username: 'admin@example.com',
  48. password: 'test',
  49. )
  50. expect_current_route 'ticket/zoom/1'
  51. end
  52. it 'Login and redirect to requested url via external authentication', authenticated_as: false do
  53. visit 'ticket/zoom/1'
  54. expect_current_route 'login'
  55. # simulate jump to external ressource
  56. visit 'https://www.zammad.org'
  57. # simulate successful login via third party
  58. user = User.find_by(login: 'admin@example.com')
  59. ActiveRecord::SessionStore::Session.all.each do |session|
  60. session.data[:user_id] = user.id
  61. session.save!
  62. end
  63. # jump back and check if origin requested url is shown
  64. visit ''
  65. expect_current_route 'ticket/zoom/1'
  66. expect(current_login).to eq('admin@example.com')
  67. end
  68. end