BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
42aa9311
Commit
42aa9311
authored
Aug 02, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'handle-reserved-words-for-oauth-usernames' into 'master'
Uniquify reserved word usernames on OAuth user creation See merge request !13244
parents
cb5adbab
71951fc3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
2 deletions
+41
-2
handle-reserved-words-for-oauth-usernames.yml
.../unreleased/handle-reserved-words-for-oauth-usernames.yml
+4
-0
user.rb
lib/gitlab/o_auth/user.rb
+7
-2
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 @
42aa9311
---
title
:
Uniquify reserved word usernames on OAuth user creation
merge_request
:
13244
author
:
Robin Bobbitt
lib/gitlab/o_auth/user.rb
View file @
42aa9311
...
...
@@ -166,12 +166,17 @@ module Gitlab
username
||=
auth_hash
.
username
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
=
::
Namespace
.
clean_path
(
username
)
if
name
.
strip
.
empty?
name
=
valid_username
if
name
.
strip
.
empty?
{
name:
name
,
username:
::
Namespace
.
clean_path
(
username
)
,
username:
valid_username
,
email:
email
,
password:
auth_hash
.
password
,
password_confirmation:
auth_hash
.
password
,
...
...
spec/lib/gitlab/o_auth/user_spec.rb
View file @
42aa9311
...
...
@@ -457,4 +457,34 @@ describe Gitlab::OAuth::User do
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
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