Skip to content

Commit

Permalink
Maintenance: Ported auth test to capybara.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikklein authored and thorsteneckel committed Oct 12, 2021
1 parent 55e99d7 commit 3036453
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 96 deletions.
6 changes: 0 additions & 6 deletions script/build/test_slice_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ if [ "$LEVEL" == '1' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_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/first_steps_test.rb
rm test/browser/integration_test.rb
Expand Down Expand Up @@ -96,7 +95,6 @@ elif [ "$LEVEL" == '2' ]; then
# test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_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/first_steps_test.rb
rm test/browser/integration_test.rb
Expand Down Expand Up @@ -148,7 +146,6 @@ elif [ "$LEVEL" == '3' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_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/first_steps_test.rb
rm test/browser/integration_test.rb
Expand Down Expand Up @@ -200,7 +197,6 @@ elif [ "$LEVEL" == '4' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_test.rb
rm test/browser/agent_user_profile_test.rb
rm test/browser/auth_test.rb
# test/browser/customer_ticket_create_test.rb
rm test/browser/first_steps_test.rb
rm test/browser/integration_test.rb
Expand Down Expand Up @@ -251,7 +247,6 @@ elif [ "$LEVEL" == '5' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb
# test/browser/agent_user_manage_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/first_steps_test.rb
rm test/browser/integration_test.rb
Expand Down Expand Up @@ -305,7 +300,6 @@ elif [ "$LEVEL" == '6' ]; then
rm test/browser/agent_ticket_zoom_hide_test.rb
rm test/browser/agent_user_manage_test.rb
rm test/browser/agent_user_profile_test.rb
rm test/browser/auth_test.rb
rm test/browser/customer_ticket_create_test.rb
# test/browser/first_steps_test.rb
# test/browser/integration_test.rb
Expand Down
15 changes: 15 additions & 0 deletions spec/support/capybara/browser_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ def retry_on_stale(retries: 3)
sleep wait_time
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.
#
# @example
Expand Down
30 changes: 29 additions & 1 deletion spec/system/basic/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,42 @@
require 'rails_helper'

RSpec.describe 'Authentication', type: :system do

it 'Login', authenticated_as: false do
login(
username: '[email protected]',
password: 'test',
)

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: '[email protected]',
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

it 'Logout' do
Expand Down
11 changes: 11 additions & 0 deletions spec/system/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@
it 'fqdn is visible on login page' do
expect(page).to have_css('.login p', text: Setting.get('fqdn'))
end

it 'Login with wrong credentials' do
within('#login') do
fill_in 'username', with: '[email protected]'
fill_in 'password', with: 'wrong'

click_button
end

expect(page).to have_css('#login .alert')
end
end
89 changes: 0 additions & 89 deletions test/browser/auth_test.rb

This file was deleted.

0 comments on commit 3036453

Please sign in to comment.