2021-09-16 14:11:32 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SessionHelpers
|
|
|
|
def expect_single_session_with_authenticated_ttl
|
|
|
|
expect_single_session_with_expiration(Settings.gitlab['session_expire_delay'] * 60)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_single_session_with_short_ttl
|
|
|
|
expect_single_session_with_expiration(Settings.gitlab['unauthenticated_session_expire_delay'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_single_session_with_expiration(expiration)
|
|
|
|
session_keys = get_session_keys
|
|
|
|
|
|
|
|
expect(session_keys.size).to eq(1)
|
2021-09-17 05:09:24 -04:00
|
|
|
expect(get_ttl(session_keys.first)).to be_within(5).of(expiration)
|
2021-09-16 14:11:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_session_keys
|
2021-11-24 13:14:31 -05:00
|
|
|
Gitlab::Redis::Sessions.with { |redis| redis.scan_each(match: 'session:gitlab:*').to_a }
|
2021-09-16 14:11:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_ttl(key)
|
2021-11-24 13:14:31 -05:00
|
|
|
Gitlab::Redis::Sessions.with { |redis| redis.ttl(key) }
|
2021-09-16 14:11:32 -04:00
|
|
|
end
|
|
|
|
end
|