summaryrefslogtreecommitdiff
path: root/spec/features/users/anonymous_sessions_spec.rb
blob: 83473964d6b36d7d43faf8287e7fcad6dcadfac4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Session TTLs', :clean_gitlab_redis_shared_state, feature_category: :system_access do
  include SessionHelpers

  it 'creates a session with a short TTL when login fails' do
    visit new_user_session_path
    # The session key only gets created after a post
    fill_in 'user_login', with: 'non-existant@gitlab.org'
    fill_in 'user_password', with: '12345678'
    click_button 'Sign in'

    expect(page).to have_content('Invalid login or password')

    expect_single_session_with_short_ttl
  end

  it 'increases the TTL when the login succeeds' do
    user = create(:user)
    gitlab_sign_in(user)

    expect(page).to have_content(user.name)

    expect_single_session_with_authenticated_ttl
  end

  context 'with an unauthorized project' do
    let_it_be(:project) { create(:project, :repository) }

    it 'creates a session with a short TTL' do
      visit project_raw_path(project, 'master/README.md')

      expect_single_session_with_short_ttl
      expect(page).to have_current_path(new_user_session_path)
    end
  end
end