2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-12-19 14:47:15 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Authentication', type: :system do
|
2020-06-18 11:51:25 +00:00
|
|
|
it 'Login', authenticated_as: false do
|
2018-12-19 14:47:15 +00:00
|
|
|
login(
|
2021-08-17 12:10:02 +00:00
|
|
|
username: 'admin@example.com',
|
2018-12-19 14:47:15 +00:00
|
|
|
password: 'test',
|
|
|
|
)
|
|
|
|
|
2019-01-14 15:31:31 +00:00
|
|
|
expect_current_route 'dashboard'
|
2021-10-12 14:02:34 +00:00
|
|
|
|
|
|
|
refresh
|
|
|
|
|
|
|
|
# Check that cookies is temporary.
|
|
|
|
cookie = cookie('^_zammad.+?')
|
|
|
|
expect(cookie[:expires]).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'Login with remember me', authenticated_as: false do
|
|
|
|
login(
|
|
|
|
username: 'admin@example.com',
|
|
|
|
password: 'test',
|
|
|
|
remember_me: true
|
|
|
|
)
|
|
|
|
|
|
|
|
expect_current_route 'dashboard'
|
|
|
|
|
|
|
|
refresh
|
|
|
|
|
|
|
|
# Check that cookies has a expire date.
|
|
|
|
cookie = cookie('^_zammad.+?')
|
|
|
|
expect(cookie[:expires]).to be_truthy
|
|
|
|
|
|
|
|
logout
|
|
|
|
expect_current_route 'login', wait: 10
|
|
|
|
|
|
|
|
# Check that cookies has no longer a expire date after logout.
|
|
|
|
cookie = cookie('^_zammad.+?')
|
|
|
|
expect(cookie[:expires]).to eq(nil)
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
it 'Logout' do
|
2018-12-19 14:47:15 +00:00
|
|
|
logout
|
2021-06-15 06:26:52 +00:00
|
|
|
expect_current_route 'login', wait: 10
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|
2020-03-25 10:46:19 +00:00
|
|
|
|
|
|
|
it 'will unset user attributes after logout' do
|
|
|
|
logout
|
2021-06-15 06:26:52 +00:00
|
|
|
expect_current_route 'login', wait: 10
|
2020-03-25 10:46:19 +00:00
|
|
|
|
|
|
|
visit '/#signup'
|
|
|
|
|
|
|
|
# check wrong displayed fields in registration form after logout. #2989
|
2020-04-14 13:24:17 +00:00
|
|
|
expect(page).to have_no_selector('select[name=organization_id]')
|
2020-03-25 10:46:19 +00:00
|
|
|
end
|
2021-02-25 16:27:17 +00:00
|
|
|
|
|
|
|
it 'Login and redirect to requested url', authenticated_as: false do
|
|
|
|
visit 'ticket/zoom/1'
|
|
|
|
|
2021-06-15 06:26:52 +00:00
|
|
|
expect_current_route 'login', wait: 10
|
2021-02-25 16:27:17 +00:00
|
|
|
|
|
|
|
login(
|
2021-08-17 12:10:02 +00:00
|
|
|
username: 'admin@example.com',
|
2021-02-25 16:27:17 +00:00
|
|
|
password: 'test',
|
|
|
|
)
|
|
|
|
|
2021-06-15 06:26:52 +00:00
|
|
|
expect_current_route 'ticket/zoom/1', wait: 10
|
2021-02-25 16:27:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'Login and redirect to requested url via external authentication', authenticated_as: false do
|
|
|
|
visit 'ticket/zoom/1'
|
|
|
|
|
2021-06-15 06:26:52 +00:00
|
|
|
expect_current_route 'login', wait: 10
|
2021-02-25 16:27:17 +00:00
|
|
|
|
|
|
|
# simulate jump to external ressource
|
|
|
|
visit 'https://www.zammad.org'
|
|
|
|
|
|
|
|
# simulate successful login via third party
|
2021-08-17 12:10:02 +00:00
|
|
|
user = User.find_by(login: 'admin@example.com')
|
2021-02-25 16:27:17 +00:00
|
|
|
ActiveRecord::SessionStore::Session.all.each do |session|
|
|
|
|
session.data[:user_id] = user.id
|
|
|
|
session.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
# jump back and check if origin requested url is shown
|
|
|
|
visit ''
|
|
|
|
|
2021-06-15 06:26:52 +00:00
|
|
|
expect_current_route 'ticket/zoom/1', wait: 10
|
2021-02-25 16:27:17 +00:00
|
|
|
|
2021-08-17 12:10:02 +00:00
|
|
|
expect(current_login).to eq('admin@example.com')
|
2021-02-25 16:27:17 +00:00
|
|
|
end
|
|
|
|
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|