BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
bd50b152
Commit
bd50b152
authored
Jul 11, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'rs-issue-34941' into 'master'
Make `Redis::Wrapper#_raw_config` and `#fetch_config` more resilient Closes #34941 See merge request !12797
parents
d3eff572
b904a7db
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
17 deletions
+33
-17
wrapper.rb
lib/gitlab/redis/wrapper.rb
+20
-8
redis_shared_examples.rb
spec/support/redis/redis_shared_examples.rb
+13
-9
No files found.
lib/gitlab/redis/wrapper.rb
View file @
bd50b152
...
...
@@ -33,13 +33,16 @@ module Gitlab
def
_raw_config
return
@_raw_config
if
defined?
(
@_raw_config
)
begin
@_raw_config
=
ERB
.
new
(
File
.
read
(
config_file_name
)).
result
.
freeze
rescue
Errno
::
ENOENT
@_raw_config
=
false
end
@_raw_config
@_raw_config
=
begin
if
filename
=
config_file_name
ERB
.
new
(
File
.
read
(
filename
)).
result
.
freeze
else
false
end
rescue
Errno
::
ENOENT
false
end
end
def
default_url
...
...
@@ -116,7 +119,16 @@ module Gitlab
end
def
fetch_config
self
.
class
.
_raw_config
?
YAML
.
load
(
self
.
class
.
_raw_config
)[
@rails_env
]
:
false
return
false
unless
self
.
class
.
_raw_config
yaml
=
YAML
.
load
(
self
.
class
.
_raw_config
)
# If the file has content but it's invalid YAML, `load` returns false
if
yaml
yaml
.
fetch
(
@rails_env
,
false
)
else
false
end
end
end
end
...
...
spec/support/redis/redis_shared_examples.rb
View file @
bd50b152
...
...
@@ -65,14 +65,6 @@ RSpec.shared_examples "redis_shared_examples" do
end
describe
'.url'
do
it
'withstands mutation'
do
url1
=
described_class
.
url
url2
=
described_class
.
url
url1
<<
'foobar'
expect
(
url2
).
not_to
end_with
(
'foobar'
)
end
context
'when yml file with env variable'
do
let
(
:config_file_name
)
{
config_with_environment_variable_inside
}
...
...
@@ -97,6 +89,12 @@ RSpec.shared_examples "redis_shared_examples" do
it
'returns false when the file does not exist'
do
expect
(
subject
).
to
eq
(
false
)
end
it
"returns false when the filename can't be determined"
do
expect
(
described_class
).
to
receive
(
:config_file_name
).
and_return
(
nil
)
expect
(
subject
).
to
eq
(
false
)
end
end
describe
'.with'
do
...
...
@@ -192,7 +190,13 @@ RSpec.shared_examples "redis_shared_examples" do
it
'returns false when no config file is present'
do
allow
(
described_class
).
to
receive
(
:_raw_config
)
{
false
}
expect
(
subject
.
send
(
:fetch_config
)).
to
be_falsey
expect
(
subject
.
send
(
:fetch_config
)).
to
eq
false
end
it
'returns false when config file is present but has invalid YAML'
do
allow
(
described_class
).
to
receive
(
:_raw_config
)
{
"# development: true"
}
expect
(
subject
.
send
(
:fetch_config
)).
to
eq
false
end
end
...
...
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