diff options
Diffstat (limited to 'spec/support/helpers/session_helpers.rb')
-rw-r--r-- | spec/support/helpers/session_helpers.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/support/helpers/session_helpers.rb b/spec/support/helpers/session_helpers.rb new file mode 100644 index 00000000000..4ef099a393e --- /dev/null +++ b/spec/support/helpers/session_helpers.rb @@ -0,0 +1,26 @@ +# 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) + expect(get_ttl(session_keys.first)).to be_within(5).of(expiration) + end + + def get_session_keys + Gitlab::Redis::SharedState.with { |redis| redis.scan_each(match: 'session:gitlab:*').to_a } + end + + def get_ttl(key) + Gitlab::Redis::SharedState.with { |redis| redis.ttl(key) } + end +end |