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
71951fc3
Commit
71951fc3
authored
Aug 01, 2017
by
Robin Bobbitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Uniquify reserved word usernames on OAuth user creation
parent
48c51e20
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
2 deletions
+41
-2
changelogs/unreleased/handle-reserved-words-for-oauth-usernames.yml
.../unreleased/handle-reserved-words-for-oauth-usernames.yml
+4
-0
lib/gitlab/o_auth/user.rb
lib/gitlab/o_auth/user.rb
+7
-2
spec/lib/gitlab/o_auth/user_spec.rb
spec/lib/gitlab/o_auth/user_spec.rb
+30
-0
No files found.
changelogs/unreleased/handle-reserved-words-for-oauth-usernames.yml
0 → 100644
View file @
71951fc3
---
title
:
Uniquify reserved word usernames on OAuth user creation
merge_request
:
13244
author
:
Robin Bobbitt
lib/gitlab/o_auth/user.rb
View file @
71951fc3
...
@@ -166,12 +166,17 @@ module Gitlab
...
@@ -166,12 +166,17 @@ module Gitlab
username
||=
auth_hash
.
username
username
||=
auth_hash
.
username
email
||=
auth_hash
.
email
email
||=
auth_hash
.
email
valid_username
=
::
Namespace
.
clean_path
(
username
)
uniquify
=
Uniquify
.
new
valid_username
=
uniquify
.
string
(
valid_username
)
{
|
s
|
!
DynamicPathValidator
.
valid_user_path?
(
s
)
}
name
=
auth_hash
.
name
name
=
auth_hash
.
name
name
=
::
Namespace
.
clean_path
(
username
)
if
name
.
strip
.
empty?
name
=
valid_username
if
name
.
strip
.
empty?
{
{
name:
name
,
name:
name
,
username:
::
Namespace
.
clean_path
(
username
)
,
username:
valid_username
,
email:
email
,
email:
email
,
password:
auth_hash
.
password
,
password:
auth_hash
.
password
,
password_confirmation:
auth_hash
.
password
,
password_confirmation:
auth_hash
.
password
,
...
...
spec/lib/gitlab/o_auth/user_spec.rb
View file @
71951fc3
...
@@ -457,4 +457,34 @@ describe Gitlab::OAuth::User do
...
@@ -457,4 +457,34 @@ describe Gitlab::OAuth::User do
end
end
end
end
end
end
describe
'generating username'
do
context
'when no collision with existing user'
do
it
'generates the username with no counter'
do
expect
(
gl_user
.
username
).
to
eq
(
'johngitlab-ETC'
)
end
end
context
'when collision with existing user'
do
it
'generates the username with a counter'
do
oauth_user
.
save
oauth_user2
=
described_class
.
new
(
OmniAuth
::
AuthHash
.
new
(
uid:
'my-uid2'
,
provider:
provider
,
info:
{
nickname:
'johngitlab-ETC@othermail.com'
,
email:
'john@othermail.com'
}))
expect
(
oauth_user2
.
gl_user
.
username
).
to
eq
(
'johngitlab-ETC1'
)
end
end
context
'when username is a reserved word'
do
let
(
:info_hash
)
do
{
nickname:
'admin@othermail.com'
,
email:
'admin@othermail.com'
}
end
it
'generates the username with a counter'
do
expect
(
gl_user
.
username
).
to
eq
(
'admin1'
)
end
end
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