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
c46dc161
Commit
c46dc161
authored
May 20, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Codestyle changes and LogoutTokenValidationService behaves consistently
parent
28afd265
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
16 deletions
+34
-16
app/controllers/oauth/geo_auth_controller.rb
app/controllers/oauth/geo_auth_controller.rb
+1
-4
app/services/oauth2/logout_token_validation_service.rb
app/services/oauth2/logout_token_validation_service.rb
+7
-5
spec/controllers/oauth/geo_auth_controller_spec.rb
spec/controllers/oauth/geo_auth_controller_spec.rb
+1
-1
spec/services/oauth2/logout_token_validation_service_spec.rb
spec/services/oauth2/logout_token_validation_service_spec.rb
+25
-6
No files found.
app/controllers/oauth/geo_auth_controller.rb
View file @
c46dc161
...
...
@@ -34,10 +34,7 @@ class Oauth::GeoAuthController < ActionController::Base
end
def
logout
oauth
=
Gitlab
::
Geo
::
OauthSession
.
new
(
state:
params
[
:state
])
token_string
=
oauth
.
extract_logout_token
logout
=
Oauth2
::
LogoutTokenValidationService
.
new
(
current_user
,
token_string
)
logout
=
Oauth2
::
LogoutTokenValidationService
.
new
(
current_user
,
params
)
result
=
logout
.
validate
if
result
[
:status
]
==
:success
sign_out
current_user
...
...
app/services/oauth2/logout_token_validation_service.rb
View file @
c46dc161
...
...
@@ -2,14 +2,16 @@ module Oauth2
class
LogoutTokenValidationService
<
::
BaseService
attr_reader
:status
,
:current_user
def
initialize
(
user
,
access_token_string
)
@access_token_string
=
access_token_string
def
initialize
(
user
,
params
=
{})
if
params
&&
params
[
:state
]
&&
!
params
[
:state
].
empty?
oauth
=
Gitlab
::
Geo
::
OauthSession
.
new
(
state:
params
[
:state
])
@access_token_string
=
oauth
.
extract_logout_token
end
@current_user
=
user
end
def
validate
return
false
unless
access_token
def
execute
return
error
(
'access token not found'
)
unless
access_token
status
=
Oauth2
::
AccessTokenValidationService
.
validate
(
access_token
)
if
status
==
Oauth2
::
AccessTokenValidationService
::
VALID
...
...
spec/controllers/oauth/geo_auth_controller_spec.rb
View file @
c46dc161
...
...
@@ -103,7 +103,7 @@ describe Oauth::GeoAuthController do
end
it
'handles access token problems'
do
allow_any_instance_of
(
Oauth2
::
LogoutTokenValidationService
).
to
receive
(
:validate
)
{
{
:status
=>
:error
,
:message
=>
:expired
}
}
allow_any_instance_of
(
Oauth2
::
LogoutTokenValidationService
).
to
receive
(
:validate
)
{
{
status: :error
,
message:
:expired
}
}
get
:logout
,
state:
logout_state
expect
(
response
.
body
).
to
include
(
"There is a problem with the OAuth access_token:
#{
:expired
}
"
)
...
...
spec/services/oauth2/logout_token_validation_service_spec.rb
View file @
c46dc161
...
...
@@ -3,19 +3,38 @@ require 'spec_helper'
describe
Oauth2
::
LogoutTokenValidationService
,
services:
true
do
let
(
:user
)
{
FactoryGirl
.
create
(
:user
)
}
let
(
:access_token
)
{
FactoryGirl
.
create
(
:doorkeeper_access_token
,
resource_owner_id:
user
.
id
).
token
}
let
(
:logout_state
)
{
Gitlab
::
Geo
::
OauthSession
.
new
(
access_token:
access_token
).
generate_logout_state
}
context
'#validate'
do
it
'returns false when empty'
do
expect
(
described_class
.
new
(
user
,
nil
).
validate
).
to
be_falsey
context
'#execute'
do
it
'returns error when params are nil'
do
result
=
described_class
.
new
(
user
,
nil
).
execute
expect
(
result
[
:status
]).
to
eq
(
:error
)
end
it
'returns false when incorrect encoding'
do
it
'return error when params are empty'
do
result
=
described_class
.
new
(
user
,
{}).
execute
expect
(
result
[
:status
]).
to
eq
(
:error
)
end
it
'returns error when state param is empty'
do
result
=
described_class
.
new
(
user
,
{
state:
nil
}).
execute
expect
(
result
[
:status
]).
to
eq
(
:error
)
result
=
described_class
.
new
(
user
,
{
state:
''
}).
execute
expect
(
result
[
:status
]).
to
eq
(
:error
)
end
it
'returns error when incorrect encoding'
do
invalid_token
=
"
\xD8
00
\xD8
01
\xD8
02"
expect
(
described_class
.
new
(
user
,
invalid_token
).
validate
).
to
be_falsey
allow_any_instance_of
(
Gitlab
::
Geo
::
OauthSession
).
to
receive
(
:extract_logout_token
)
{
invalid_token
}
result
=
described_class
.
new
(
user
,
{
state:
logout_state
}).
execute
expect
(
result
[
:status
]).
to
eq
(
:error
)
end
it
'returns true when token is valid'
do
expect
(
described_class
.
new
(
user
,
access_token
).
validate
).
to
be_truthy
result
=
described_class
.
new
(
user
,
{
state:
logout_state
}).
execute
expect
(
result
[
:status
]).
to
eq
(
:success
)
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