Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f4756e90
Commit
f4756e90
authored
3 years ago
by
nmilojevic1
Committed by
Nikola Milojevic
3 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initialize redis stoer and use it for session_store
- Add specs and ENV variable
parent
2b63a368
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
13 deletions
+109
-13
config/initializers/session_store.rb
config/initializers/session_store.rb
+29
-12
lib/gitlab/redis/wrapper.rb
lib/gitlab/redis/wrapper.rb
+5
-1
spec/initializers/session_store_spec.rb
spec/initializers/session_store_spec.rb
+38
-0
spec/support/redis/redis_shared_examples.rb
spec/support/redis/redis_shared_examples.rb
+37
-0
No files found.
config/initializers/session_store.rb
View file @
f4756e90
...
...
@@ -18,16 +18,33 @@ cookie_key = if Rails.env.development?
else
"_gitlab_session"
end
if
Gitlab
::
Utils
.
to_boolean
(
ENV
[
'GITLAB_LEGACY_SESSION_STORE'
],
default:
false
)
sessions_config
=
Gitlab
::
Redis
::
SharedState
.
params
sessions_config
[
:namespace
]
=
Gitlab
::
Redis
::
SharedState
::
SESSION_NAMESPACE
Gitlab
::
Application
.
config
.
session_store
(
:redis_store
,
# Using the cookie_store would enable session replay attacks.
servers:
sessions_config
,
key:
cookie_key
,
secure:
Gitlab
.
config
.
gitlab
.
https
,
httponly:
true
,
expires_in:
Settings
.
gitlab
[
'session_expire_delay'
]
*
60
,
path:
Rails
.
application
.
config
.
relative_url_root
.
presence
||
'/'
)
else
store
=
Gitlab
::
Redis
::
SharedState
.
store
(
namespace:
Gitlab
::
Redis
::
SharedState
::
SESSION_NAMESPACE
)
Gitlab
::
Application
.
config
.
session_store
(
:redis_store
,
# Using the cookie_store would enable session replay attacks.
redis_store:
store
,
key:
cookie_key
,
expires_in:
Settings
.
gitlab
[
'session_expire_delay'
]
*
60
,
httponly:
true
,
secure:
Gitlab
.
config
.
gitlab
.
https
)
end
sessions_config
=
Gitlab
::
Redis
::
SharedState
.
params
sessions_config
[
:namespace
]
=
Gitlab
::
Redis
::
SharedState
::
SESSION_NAMESPACE
Gitlab
::
Application
.
config
.
session_store
(
:redis_store
,
# Using the cookie_store would enable session replay attacks.
servers:
sessions_config
,
key:
cookie_key
,
secure:
Gitlab
.
config
.
gitlab
.
https
,
httponly:
true
,
expires_in:
Settings
.
gitlab
[
'session_expire_delay'
]
*
60
,
path:
Rails
.
application
.
config
.
relative_url_root
.
presence
||
'/'
)
This diff is collapsed.
Click to expand it.
lib/gitlab/redis/wrapper.rb
View file @
f4756e90
...
...
@@ -17,7 +17,7 @@ module Gitlab
module
Redis
class
Wrapper
class
<<
self
delegate
:params
,
:url
,
to: :new
delegate
:params
,
:url
,
:store
,
to: :new
def
with
pool
.
with
{
|
redis
|
yield
redis
}
...
...
@@ -126,6 +126,10 @@ module Gitlab
sentinels
&&
!
sentinels
.
empty?
end
def
store
(
extras
=
{})
::
Redis
::
Store
::
Factory
.
create
(
redis_store_options
.
merge
(
extras
))
end
private
def
redis_store_options
...
...
This diff is collapsed.
Click to expand it.
spec/initializers/session_store_spec.rb
0 → 100644
View file @
f4756e90
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Session initializer for GitLab'
do
subject
{
Gitlab
::
Application
.
config
}
let
(
:load_session_store
)
do
load
Rails
.
root
.
join
(
'config/initializers/session_store.rb'
)
end
describe
'config#session_store'
do
context
'when the GITLAB_LEGACY_SESSION_STORE env is enabled'
do
before
do
stub_env
(
'GITLAB_LEGACY_SESSION_STORE'
,
true
)
end
it
'returns the regular cookie without a suffix'
do
expect
(
subject
).
to
receive
(
:session_store
).
with
(
:redis_store
,
a_hash_including
(
servers:
kind_of
(
Hash
)))
load_session_store
end
end
context
'when the GITLAB_LEGACY_SESSION_STORE env is not set'
do
before
do
stub_env
(
'GITLAB_LEGACY_SESSION_STORE'
,
nil
)
end
it
'returns the regular cookie without a suffix'
do
expect
(
subject
).
to
receive
(
:session_store
).
with
(
:redis_store
,
a_hash_including
(
redis_store:
kind_of
(
::
Redis
::
Store
)))
load_session_store
end
end
end
end
This diff is collapsed.
Click to expand it.
spec/support/redis/redis_shared_examples.rb
View file @
f4756e90
...
...
@@ -87,6 +87,43 @@ RSpec.shared_examples "redis_shared_examples" do
end
end
describe
'.store'
do
let
(
:rails_env
)
{
'development'
}
subject
{
described_class
.
new
(
rails_env
).
store
}
shared_examples
'redis store'
do
it
'instantiates Redis::Store'
do
is_expected
.
to
be_a
(
::
Redis
::
Store
)
expect
(
subject
.
to_s
).
to
eq
(
"Redis Client connected to
#{
host
}
against DB
#{
redis_database
}
"
)
end
context
'with the namespace'
do
let
(
:namespace
)
{
'namespace_name'
}
subject
{
described_class
.
new
(
rails_env
).
store
(
namespace:
namespace
)
}
it
"uses specified namespace"
do
expect
(
subject
.
to_s
).
to
eq
(
"Redis Client connected to
#{
host
}
against DB
#{
redis_database
}
with namespace
#{
namespace
}
"
)
end
end
end
context
'with old format'
do
it_behaves_like
'redis store'
do
let
(
:config_file_name
)
{
config_old_format_host
}
let
(
:host
)
{
"localhost:
#{
redis_port
}
"
}
end
end
context
'with new format'
do
it_behaves_like
'redis store'
do
let
(
:config_file_name
)
{
config_new_format_host
}
let
(
:host
)
{
"development-host:
#{
redis_port
}
"
}
end
end
end
describe
'.params'
do
subject
{
described_class
.
new
(
rails_env
).
params
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment