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
e000ed6b
Commit
e000ed6b
authored
May 13, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor logout token validation
💄
parent
5a4ade92
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
14 deletions
+57
-14
app/controllers/oauth/geo_auth_controller.rb
app/controllers/oauth/geo_auth_controller.rb
+4
-14
app/services/oauth2/logout_token_validation_service.rb
app/services/oauth2/logout_token_validation_service.rb
+32
-0
spec/services/oauth2/logout_token_validation_service_spec.rb
spec/services/oauth2/logout_token_validation_service_spec.rb
+21
-0
No files found.
app/controllers/oauth/geo_auth_controller.rb
View file @
e000ed6b
...
...
@@ -37,21 +37,11 @@ class Oauth::GeoAuthController < ActionController::Base
oauth
=
Gitlab
::
Geo
::
OauthSession
.
new
(
state:
params
[
:state
])
token_string
=
oauth
.
extract_logout_token
unless
token_string
&&
token_string
.
is_utf8?
access_token_error
(
'invalid'
)
end
access_token
=
Doorkeeper
::
AccessToken
.
by_token
(
token_string
)
access_token_status
=
Oauth2
::
AccessTokenValidationService
.
validate
(
access_token
)
if
access_token_status
==
Oauth2
::
AccessTokenValidationService
::
VALID
user
=
User
.
find
(
access_token
.
resource_owner_id
)
if
current_user
==
user
logout
=
Oauth2
::
LogoutTokenValidationService
.
new
(
current_user
,
token_string
)
if
logout
.
valid?
sign_out
current_user
end
else
access_token_error
(
'invalid'
)
access_token_error
(
logout
.
status
)
end
redirect_to
root_path
...
...
app/services/oauth2/logout_token_validation_service.rb
0 → 100644
View file @
e000ed6b
module
Oauth2
class
LogoutTokenValidationService
attr_reader
:status
,
:current_user
def
initialize
(
user
,
access_token_string
)
@access_token_string
=
access_token_string
@current_user
=
user
end
def
validate
return
false
unless
access_token
@status
=
Oauth2
::
AccessTokenValidationService
.
validate
(
access_token
)
if
@status
==
Oauth2
::
AccessTokenValidationService
::
VALID
user
=
User
.
find
(
access_token
.
resource_owner_id
)
if
current_user
==
user
true
end
else
false
end
end
def
access_token
return
unless
@access_token_string
&&
@access_token_string
.
is_utf8?
@access_token
||=
Doorkeeper
::
AccessToken
.
by_token
(
@access_token_string
)
end
end
end
spec/services/oauth2/logout_token_validation_service_spec.rb
0 → 100644
View file @
e000ed6b
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
}
context
'#validate'
do
it
'returns false when empty'
do
expect
(
described_class
.
new
(
user
,
nil
).
validate
).
to
be_falsey
end
it
'returns false when incorrect encoding'
do
invalid_token
=
"
\xD8
00
\xD8
01
\xD8
02"
expect
(
described_class
.
new
(
user
,
invalid_token
).
validate
).
to
be_falsey
end
it
'returns true when token is valid'
do
expect
(
described_class
.
new
(
user
,
access_token
).
validate
).
to
be_truthy
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