Maintenance: Ported auth test to capybara.

This commit is contained in:
Dominik Klein 2021-10-12 16:02:34 +02:00 committed by Thorsten Eckel
parent 55e99d7aa8
commit 3036453a0f
5 changed files with 55 additions and 96 deletions

View file

@ -43,7 +43,6 @@ if [ "$LEVEL" == '1' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb rm test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_manage_test.rb
rm test/browser/agent_user_profile_test.rb rm test/browser/agent_user_profile_test.rb
# test/browser/auth_test.rb
rm test/browser/customer_ticket_create_test.rb rm test/browser/customer_ticket_create_test.rb
rm test/browser/first_steps_test.rb rm test/browser/first_steps_test.rb
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
@ -96,7 +95,6 @@ elif [ "$LEVEL" == '2' ]; then
# test/browser/agent_ticket_zoom_hide_test.rb # test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_manage_test.rb
rm test/browser/agent_user_profile_test.rb rm test/browser/agent_user_profile_test.rb
rm test/browser/auth_test.rb
rm test/browser/customer_ticket_create_test.rb rm test/browser/customer_ticket_create_test.rb
rm test/browser/first_steps_test.rb rm test/browser/first_steps_test.rb
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
@ -148,7 +146,6 @@ elif [ "$LEVEL" == '3' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb rm test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_manage_test.rb
rm test/browser/agent_user_profile_test.rb rm test/browser/agent_user_profile_test.rb
rm test/browser/auth_test.rb
rm test/browser/customer_ticket_create_test.rb rm test/browser/customer_ticket_create_test.rb
rm test/browser/first_steps_test.rb rm test/browser/first_steps_test.rb
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
@ -200,7 +197,6 @@ elif [ "$LEVEL" == '4' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb rm test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_manage_test.rb
rm test/browser/agent_user_profile_test.rb rm test/browser/agent_user_profile_test.rb
rm test/browser/auth_test.rb
# test/browser/customer_ticket_create_test.rb # test/browser/customer_ticket_create_test.rb
rm test/browser/first_steps_test.rb rm test/browser/first_steps_test.rb
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
@ -251,7 +247,6 @@ elif [ "$LEVEL" == '5' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb rm test/browser/agent_ticket_zoom_hide_test.rb
# test/browser/agent_user_manage_test.rb # test/browser/agent_user_manage_test.rb
# test/browser/agent_user_profile_test.rb # test/browser/agent_user_profile_test.rb
rm test/browser/auth_test.rb
rm test/browser/customer_ticket_create_test.rb rm test/browser/customer_ticket_create_test.rb
rm test/browser/first_steps_test.rb rm test/browser/first_steps_test.rb
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
@ -305,7 +300,6 @@ elif [ "$LEVEL" == '6' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb rm test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_manage_test.rb
rm test/browser/agent_user_profile_test.rb rm test/browser/agent_user_profile_test.rb
rm test/browser/auth_test.rb
rm test/browser/customer_ticket_create_test.rb rm test/browser/customer_ticket_create_test.rb
# test/browser/first_steps_test.rb # test/browser/first_steps_test.rb
# test/browser/integration_test.rb # test/browser/integration_test.rb

View file

@ -32,6 +32,21 @@ module BrowserTestHelper
sleep wait_time sleep wait_time
end end
# Get the current cookies from the browser with the driver object.
#
def cookies
page.driver.browser.manage.all_cookies
end
# Get a single cookie by the given name (regex possible)
#
# @example
# cookie('cookie-name')
#
def cookie(name)
cookies.find { |cookie| cookie[:name].match?(name) }
end
# Finds an element and clicks it - wrapped in one method. # Finds an element and clicks it - wrapped in one method.
# #
# @example # @example

View file

@ -3,7 +3,6 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe 'Authentication', type: :system do RSpec.describe 'Authentication', type: :system do
it 'Login', authenticated_as: false do it 'Login', authenticated_as: false do
login( login(
username: 'admin@example.com', username: 'admin@example.com',
@ -11,6 +10,35 @@ RSpec.describe 'Authentication', type: :system do
) )
expect_current_route 'dashboard' expect_current_route 'dashboard'
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)
end end
it 'Logout' do it 'Logout' do

View file

@ -10,4 +10,15 @@ RSpec.describe 'Login', type: :system, authenticated_as: false do
it 'fqdn is visible on login page' do it 'fqdn is visible on login page' do
expect(page).to have_css('.login p', text: Setting.get('fqdn')) expect(page).to have_css('.login p', text: Setting.get('fqdn'))
end end
it 'Login with wrong credentials' do
within('#login') do
fill_in 'username', with: 'admin@example.com'
fill_in 'password', with: 'wrong'
click_button
end
expect(page).to have_css('#login .alert')
end
end end

View file

@ -1,89 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'browser_test_helper'
class AuthTest < TestCase
def test_authentication
@browser = browser_instance
location(url: browser_url)
match(
css: '#login',
value: 'username',
)
click(css: '#login button')
sleep 4
match(
css: '#login',
value: 'username',
)
# login with username/password
login(
username: 'nicole.braun@zammad.org',
password: 'test',
)
tasks_close_all
# reload page
reload
# check if cookie is temporarily
watch_for(
css: 'body',
value: 'Overviews',
)
# verify session cookie
cookie(
name: '^_zammad.+?',
value: '.+?',
expires: '',
)
end
def test_authentication_new_browser_without_permanent_cookie_no_session_should_be
@browser = browser_instance
location(url: browser_url)
match(
css: '#login',
value: 'username',
)
end
def test_new_browser_with_permanent_cookie_login
@browser = browser_instance
location(url: browser_url)
# login with username/password
login(
username: 'nicole.braun@zammad.org',
password: 'test',
remember_me: true,
)
# check if cookie is temporarily
watch_for(
css: 'body',
value: 'Overviews',
)
# verify session cookie
cookie(
name: '^_zammad.+?',
value: '.+?',
expires: '\d{4}-\d{1,2}-\d{1,2}.+?',
)
logout
# verify session cookie
sleep 2
cookie(
name: '^_zammad.+?',
value: '.+?',
expires: '',
)
end
end