authentication_spec.rb 1.5 KB

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