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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
4eb24c31
Commit
4eb24c31
authored
Mar 15, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verify config/mail_room.yml is interpretable Ruby
parent
b7166806
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
27 deletions
+40
-27
lib/gitlab/redis.rb
lib/gitlab/redis.rb
+5
-2
spec/config/mail_room_spec.rb
spec/config/mail_room_spec.rb
+35
-25
No files found.
lib/gitlab/redis.rb
View file @
4eb24c31
...
@@ -9,7 +9,6 @@ module Gitlab
...
@@ -9,7 +9,6 @@ module Gitlab
SIDEKIQ_NAMESPACE
=
'resque:gitlab'
.
freeze
SIDEKIQ_NAMESPACE
=
'resque:gitlab'
.
freeze
MAILROOM_NAMESPACE
=
'mail_room:gitlab'
.
freeze
MAILROOM_NAMESPACE
=
'mail_room:gitlab'
.
freeze
DEFAULT_REDIS_URL
=
'redis://localhost:6379'
.
freeze
DEFAULT_REDIS_URL
=
'redis://localhost:6379'
.
freeze
CONFIG_FILE
=
File
.
expand_path
(
'../../config/resque.yml'
,
__dir__
)
class
<<
self
class
<<
self
delegate
:params
,
:url
,
to: :new
delegate
:params
,
:url
,
to: :new
...
@@ -33,13 +32,17 @@ module Gitlab
...
@@ -33,13 +32,17 @@ module Gitlab
return
@_raw_config
if
defined?
(
@_raw_config
)
return
@_raw_config
if
defined?
(
@_raw_config
)
begin
begin
@_raw_config
=
ERB
.
new
(
File
.
read
(
CONFIG_FILE
)).
result
.
freeze
@_raw_config
=
ERB
.
new
(
File
.
read
(
config_file
)).
result
.
freeze
rescue
Errno
::
ENOENT
rescue
Errno
::
ENOENT
@_raw_config
=
false
@_raw_config
=
false
end
end
@_raw_config
@_raw_config
end
end
def
config_file
ENV
[
'GITLAB_REDIS_CONFIG_FILE'
]
||
File
.
expand_path
(
'../../config/resque.yml'
,
__dir__
)
end
end
end
def
initialize
(
rails_env
=
nil
)
def
initialize
(
rails_env
=
nil
)
...
...
spec/config/mail_room_spec.rb
View file @
4eb24c31
require
'spec_helper'
require
'spec_helper'
describe
'mail_room.yml'
do
describe
'mail_room.yml'
do
let
(
:config_path
)
{
'config/mail_room.yml'
}
let
(
:mailroom_config_path
)
{
'config/mail_room.yml'
}
let
(
:configuration
)
{
YAML
.
load
(
ERB
.
new
(
File
.
read
(
config_path
)).
result
)
}
let
(
:gitlab_config_path
)
{
'config/mail_room.yml'
}
before
(
:each
)
{
clear_raw_config
}
let
(
:redis_config_path
)
{
'config/resque.yml'
}
after
(
:each
)
{
clear_raw_config
}
context
'when incoming email is disabled'
do
let
(
:configuration
)
do
before
do
vars
=
{
ENV
[
'MAIL_ROOM_GITLAB_CONFIG_FILE'
]
=
Rails
.
root
.
join
(
'spec/fixtures/config/mail_room_disabled.yml'
).
to_s
'MAIL_ROOM_GITLAB_CONFIG_FILE'
=>
absolute_path
(
gitlab_config_path
),
Gitlab
::
MailRoom
.
reset_config!
'GITLAB_REDIS_CONFIG_FILE'
=>
absolute_path
(
redis_config_path
)
end
}
cmd
=
"puts ERB.new(File.read(
#{
absolute_path
(
mailroom_config_path
).
inspect
}
)).result"
after
do
output
,
status
=
Gitlab
::
Popen
.
popen
(
%W(ruby -rerb -e
#{
cmd
}
)
,
absolute_path
(
'config'
),
vars
)
ENV
[
'MAIL_ROOM_GITLAB_CONFIG_FILE'
]
=
nil
raise
"Error interpreting
#{
mailroom_config_path
}
:
#{
output
}
"
unless
status
.
zero?
end
YAML
.
load
(
output
)
end
before
(
:each
)
do
ENV
[
'GITLAB_REDIS_CONFIG_FILE'
]
=
absolute_path
(
redis_config_path
)
clear_redis_raw_config
end
after
(
:each
)
do
ENV
[
'GITLAB_REDIS_CONFIG_FILE'
]
=
nil
clear_redis_raw_config
end
context
'when incoming email is disabled'
do
let
(
:gitlab_config_path
)
{
'spec/fixtures/config/mail_room_disabled.yml'
}
it
'contains no configuration'
do
it
'contains no configuration'
do
expect
(
configuration
[
:mailboxes
]).
to
be_nil
expect
(
configuration
[
:mailboxes
]).
to
be_nil
...
@@ -22,21 +37,12 @@ describe 'mail_room.yml' do
...
@@ -22,21 +37,12 @@ describe 'mail_room.yml' do
end
end
context
'when incoming email is enabled'
do
context
'when incoming email is enabled'
do
let
(
:
redis_config
)
{
Rails
.
root
.
join
(
'spec/fixtures/config/redis_new_format_host.yml'
)
}
let
(
:
gitlab_config_path
)
{
'spec/fixtures/config/mail_room_enabled.yml'
}
let
(
:
gitlab_redis
)
{
Gitlab
::
Redis
.
new
(
Rails
.
env
)
}
let
(
:
redis_config_path
)
{
'spec/fixtures/config/redis_new_format_host.yml'
}
before
do
let
(
:gitlab_redis
)
{
Gitlab
::
Redis
.
new
(
Rails
.
env
)
}
ENV
[
'MAIL_ROOM_GITLAB_CONFIG_FILE'
]
=
Rails
.
root
.
join
(
'spec/fixtures/config/mail_room_enabled.yml'
).
to_s
Gitlab
::
MailRoom
.
reset_config!
end
after
do
ENV
[
'MAIL_ROOM_GITLAB_CONFIG_FILE'
]
=
nil
end
it
'contains the intended configuration'
do
it
'contains the intended configuration'
do
stub_const
(
'Gitlab::Redis::CONFIG_FILE'
,
redis_config
)
expect
(
configuration
[
:mailboxes
].
length
).
to
eq
(
1
)
expect
(
configuration
[
:mailboxes
].
length
).
to
eq
(
1
)
mailbox
=
configuration
[
:mailboxes
].
first
mailbox
=
configuration
[
:mailboxes
].
first
...
@@ -66,9 +72,13 @@ describe 'mail_room.yml' do
...
@@ -66,9 +72,13 @@ describe 'mail_room.yml' do
end
end
end
end
def
clear_raw_config
def
clear_r
edis_r
aw_config
Gitlab
::
Redis
.
remove_instance_variable
(
:@_raw_config
)
Gitlab
::
Redis
.
remove_instance_variable
(
:@_raw_config
)
rescue
NameError
rescue
NameError
# raised if @_raw_config was not set; ignore
# raised if @_raw_config was not set; ignore
end
end
def
absolute_path
(
path
)
Rails
.
root
.
join
(
path
).
to_s
end
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