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
Jérome Perrin
gitlab-ce
Commits
da2191af
Commit
da2191af
authored
Mar 20, 2018
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OmniauthInitializer created to improve devise.rb
This should simplify refactoring and allow testing
parent
bce962a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
45 deletions
+131
-45
config/initializers/devise.rb
config/initializers/devise.rb
+1
-45
lib/gitlab/omniauth_initializer.rb
lib/gitlab/omniauth_initializer.rb
+65
-0
spec/lib/gitlab/omniauth_initializer_spec.rb
spec/lib/gitlab/omniauth_initializer_spec.rb
+65
-0
No files found.
config/initializers/devise.rb
View file @
da2191af
...
@@ -219,49 +219,5 @@ Devise.setup do |config|
...
@@ -219,49 +219,5 @@ Devise.setup do |config|
end
end
end
end
Gitlab
.
config
.
omniauth
.
providers
.
each
do
|
provider
|
Gitlab
::
OmniauthInitializer
.
new
(
config
).
execute
(
Gitlab
.
config
.
omniauth
.
providers
)
provider_arguments
=
[]
%w[app_id app_secret]
.
each
do
|
argument
|
provider_arguments
<<
provider
[
argument
]
if
provider
[
argument
]
end
case
provider
[
'args'
]
when
Array
# An Array from the configuration will be expanded.
provider_arguments
.
concat
provider
[
'args'
]
when
Hash
# Add procs for handling SLO
if
provider
[
'name'
]
==
'cas3'
provider
[
'args'
][
:on_single_sign_out
]
=
lambda
do
|
request
|
ticket
=
request
.
params
[
:session_index
]
raise
"Service Ticket not found."
unless
Gitlab
::
Auth
::
OAuth
::
Session
.
valid?
(
:cas3
,
ticket
)
Gitlab
::
Auth
::
OAuth
::
Session
.
destroy
(
:cas3
,
ticket
)
true
end
end
if
provider
[
'name'
]
==
'authentiq'
provider
[
'args'
][
:remote_sign_out_handler
]
=
lambda
do
|
request
|
authentiq_session
=
request
.
params
[
'sid'
]
if
Gitlab
::
Auth
::
OAuth
::
Session
.
valid?
(
:authentiq
,
authentiq_session
)
Gitlab
::
Auth
::
OAuth
::
Session
.
destroy
(
:authentiq
,
authentiq_session
)
true
else
false
end
end
end
if
provider
[
'name'
]
==
'shibboleth'
provider
[
'args'
][
:fail_with_empty_uid
]
=
true
end
# A Hash from the configuration will be passed as is.
provider_arguments
<<
provider
[
'args'
].
symbolize_keys
end
config
.
omniauth
provider
[
'name'
].
to_sym
,
*
provider_arguments
end
end
end
lib/gitlab/omniauth_initializer.rb
0 → 100644
View file @
da2191af
module
Gitlab
class
OmniauthInitializer
def
initialize
(
devise_config
)
@devise_config
=
devise_config
end
def
config
@devise_config
end
def
execute
(
providers
)
initialize_providers
(
providers
)
end
private
def
initialize_providers
(
providers
)
providers
.
each
do
|
provider
|
provider_arguments
=
[]
%w[app_id app_secret]
.
each
do
|
argument
|
provider_arguments
<<
provider
[
argument
]
if
provider
[
argument
]
end
case
provider
[
'args'
]
when
Array
# An Array from the configuration will be expanded.
provider_arguments
.
concat
provider
[
'args'
]
when
Hash
# Add procs for handling SLO
if
provider
[
'name'
]
==
'cas3'
provider
[
'args'
][
:on_single_sign_out
]
=
lambda
do
|
request
|
ticket
=
request
.
params
[
:session_index
]
raise
"Service Ticket not found."
unless
Gitlab
::
Auth
::
OAuth
::
Session
.
valid?
(
:cas3
,
ticket
)
Gitlab
::
Auth
::
OAuth
::
Session
.
destroy
(
:cas3
,
ticket
)
true
end
end
if
provider
[
'name'
]
==
'authentiq'
provider
[
'args'
][
:remote_sign_out_handler
]
=
lambda
do
|
request
|
authentiq_session
=
request
.
params
[
'sid'
]
if
Gitlab
::
Auth
::
OAuth
::
Session
.
valid?
(
:authentiq
,
authentiq_session
)
Gitlab
::
Auth
::
OAuth
::
Session
.
destroy
(
:authentiq
,
authentiq_session
)
true
else
false
end
end
end
if
provider
[
'name'
]
==
'shibboleth'
provider
[
'args'
][
:fail_with_empty_uid
]
=
true
end
# A Hash from the configuration will be passed as is.
provider_arguments
<<
provider
[
'args'
].
symbolize_keys
end
config
.
omniauth
provider
[
'name'
].
to_sym
,
*
provider_arguments
end
end
end
end
spec/lib/gitlab/omniauth_initializer_spec.rb
0 → 100644
View file @
da2191af
require
'spec_helper'
describe
Gitlab
::
OmniauthInitializer
do
let
(
:devise_config
)
{
class_double
(
Devise
)
}
subject
{
described_class
.
new
(
devise_config
)
}
describe
'#execute'
do
it
'configures providers from array'
do
generic_config
=
{
'name'
=>
'generic'
}
expect
(
devise_config
).
to
receive
(
:omniauth
).
with
(
:generic
)
subject
.
execute
([
generic_config
])
end
it
'allows "args" array for app_id and app_secret'
do
legacy_config
=
{
'name'
=>
'legacy'
,
'args'
=>
%w(123 abc)
}
expect
(
devise_config
).
to
receive
(
:omniauth
).
with
(
:legacy
,
'123'
,
'abc'
)
subject
.
execute
([
legacy_config
])
end
it
'passes app_id and app_secret as additional arguments'
do
twitter_config
=
{
'name'
=>
'twitter'
,
'app_id'
=>
'123'
,
'app_secret'
=>
'abc'
}
expect
(
devise_config
).
to
receive
(
:omniauth
).
with
(
:twitter
,
'123'
,
'abc'
)
subject
.
execute
([
twitter_config
])
end
it
'passes "args" hash as symbolized hash argument'
do
hash_config
=
{
'name'
=>
'hash'
,
'args'
=>
{
'custom'
=>
'format'
}
}
expect
(
devise_config
).
to
receive
(
:omniauth
).
with
(
:hash
,
custom:
'format'
)
subject
.
execute
([
hash_config
])
end
it
'configures fail_with_empty_uid for shibboleth'
do
shibboleth_config
=
{
'name'
=>
'shibboleth'
,
'args'
=>
{}
}
expect
(
devise_config
).
to
receive
(
:omniauth
).
with
(
:shibboleth
,
fail_with_empty_uid:
true
)
subject
.
execute
([
shibboleth_config
])
end
it
'configures remote_sign_out_handler proc for authentiq'
do
authentiq_config
=
{
'name'
=>
'authentiq'
,
'args'
=>
{}
}
expect
(
devise_config
).
to
receive
(
:omniauth
).
with
(
:authentiq
,
remote_sign_out_handler:
an_instance_of
(
Proc
))
subject
.
execute
([
authentiq_config
])
end
it
'configures on_single_sign_out proc for cas3'
do
cas3_config
=
{
'name'
=>
'cas3'
,
'args'
=>
{}
}
expect
(
devise_config
).
to
receive
(
:omniauth
).
with
(
:cas3
,
on_single_sign_out:
an_instance_of
(
Proc
))
subject
.
execute
([
cas3_config
])
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