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
eeef12d4
Commit
eeef12d4
authored
Mar 27, 2020
by
Steve Abrams
Committed by
Peter Leitzen
Mar 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix oauth check to verify user exists
parent
41bc9d6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
7 deletions
+22
-7
changelogs/unreleased/212526-oauth-orphan-check.yml
changelogs/unreleased/212526-oauth-orphan-check.yml
+5
-0
lib/gitlab/auth.rb
lib/gitlab/auth.rb
+2
-4
spec/lib/gitlab/auth_spec.rb
spec/lib/gitlab/auth_spec.rb
+15
-3
No files found.
changelogs/unreleased/212526-oauth-orphan-check.yml
0 → 100644
View file @
eeef12d4
---
title
:
Fix Gitlab::Auth to handle orphaned oauth tokens
merge_request
:
28159
author
:
type
:
fixed
lib/gitlab/auth.rb
View file @
eeef12d4
...
...
@@ -164,20 +164,18 @@ module Gitlab
Gitlab
::
Auth
::
Result
.
new
(
user
,
nil
,
:gitlab_or_ldap
,
full_authentication_abilities
)
end
# rubocop: disable CodeReuse/ActiveRecord
def
oauth_access_token_check
(
login
,
password
)
if
login
==
"oauth2"
&&
password
.
present?
token
=
Doorkeeper
::
AccessToken
.
by_token
(
password
)
if
valid_oauth_token?
(
token
)
user
=
User
.
find_by
(
id:
token
.
resource_owner_id
)
return
unless
user
.
can?
(
:log_in
)
user
=
User
.
id_in
(
token
.
resource_owner_id
).
first
return
unless
user
&
.
can?
(
:log_in
)
Gitlab
::
Auth
::
Result
.
new
(
user
,
nil
,
:oauth
,
full_authentication_abilities
)
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
personal_access_token_check
(
password
)
return
unless
password
.
present?
...
...
spec/lib/gitlab/auth_spec.rb
View file @
eeef12d4
...
...
@@ -250,6 +250,13 @@ describe Gitlab::Auth, :use_clean_rails_memory_store_caching do
let
(
:token_w_api_scope
)
{
Doorkeeper
::
AccessToken
.
create!
(
application_id:
application
.
id
,
resource_owner_id:
user
.
id
,
scopes:
'api'
)
}
let
(
:application
)
{
Doorkeeper
::
Application
.
create!
(
name:
'MyApp'
,
redirect_uri:
'https://app.com'
,
owner:
user
)
}
shared_examples
'an oauth failure'
do
it
'fails'
do
expect
(
gl_auth
.
find_for_git_client
(
"oauth2"
,
token_w_api_scope
.
token
,
project:
nil
,
ip:
'ip'
))
.
to
eq
(
Gitlab
::
Auth
::
Result
.
new
(
nil
,
nil
,
nil
,
nil
))
end
end
it
'succeeds for OAuth tokens with the `api` scope'
do
expect
(
gl_auth
.
find_for_git_client
(
"oauth2"
,
token_w_api_scope
.
token
,
project:
nil
,
ip:
'ip'
)).
to
eq
(
Gitlab
::
Auth
::
Result
.
new
(
user
,
nil
,
:oauth
,
described_class
.
full_authentication_abilities
))
end
...
...
@@ -269,10 +276,15 @@ describe Gitlab::Auth, :use_clean_rails_memory_store_caching do
context
'blocked user'
do
let
(
:user
)
{
create
(
:user
,
:blocked
)
}
it
'fails'
do
expect
(
gl_auth
.
find_for_git_client
(
"oauth2"
,
token_w_api_scope
.
token
,
project:
nil
,
ip:
'ip'
))
.
to
eq
(
Gitlab
::
Auth
::
Result
.
new
(
nil
,
nil
,
nil
,
nil
))
it_behaves_like
'an oauth failure'
end
context
'orphaned token'
do
before
do
user
.
destroy
end
it_behaves_like
'an oauth failure'
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