Commit 2fec78ea authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'if-6990-enforce_smartcard_session_for_git_and_api' into 'master'

CE port of "Require session with smartcard login for Git access"

See merge request gitlab-org/gitlab-ce!30384
parents 2e746803 b9b3ec83
...@@ -4,19 +4,24 @@ module Gitlab ...@@ -4,19 +4,24 @@ module Gitlab
class NamespacedSessionStore class NamespacedSessionStore
delegate :[], :[]=, to: :store delegate :[], :[]=, to: :store
def initialize(key) def initialize(key, session = Session.current)
@key = key @key = key
@session = session
end end
def initiated? def initiated?
!Session.current.nil? !session.nil?
end end
def store def store
return unless Session.current return unless session
Session.current[@key] ||= {} session[@key] ||= {}
Session.current[@key] session[@key]
end end
private
attr_reader :session
end end
end end
...@@ -4,6 +4,8 @@ require 'spec_helper' ...@@ -4,6 +4,8 @@ require 'spec_helper'
describe Gitlab::NamespacedSessionStore do describe Gitlab::NamespacedSessionStore do
let(:key) { :some_key } let(:key) { :some_key }
context 'current session' do
subject { described_class.new(key) } subject { described_class.new(key) }
it 'stores data under the specified key' do it 'stores data under the specified key' do
...@@ -19,4 +21,16 @@ describe Gitlab::NamespacedSessionStore do ...@@ -19,4 +21,16 @@ describe Gitlab::NamespacedSessionStore do
expect(subject[:existing_data]).to eq 123 expect(subject[:existing_data]).to eq 123
end end
end
context 'passed in session' do
let(:data) { { 'data' => 42 } }
let(:session) { { 'some_key' => data } }
subject { described_class.new(key, session.with_indifferent_access) }
it 'retrieves data from the given key' do
expect(subject['data']).to eq 42
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment