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
Jérome Perrin
gitlab-ce
Commits
6685661b
Commit
6685661b
authored
Feb 11, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean username acquired from OAuth/LDAP.
Fixes #1967.
parent
2dfd2198
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
6 deletions
+33
-6
CHANGELOG
CHANGELOG
+1
-0
app/models/user.rb
app/models/user.rb
+16
-0
lib/gitlab/oauth/user.rb
lib/gitlab/oauth/user.rb
+5
-5
spec/lib/gitlab/oauth/user_spec.rb
spec/lib/gitlab/oauth/user_spec.rb
+1
-1
spec/models/user_spec.rb
spec/models/user_spec.rb
+10
-0
No files found.
CHANGELOG
View file @
6685661b
...
@@ -75,6 +75,7 @@ v 7.8.0 (unreleased)
...
@@ -75,6 +75,7 @@ v 7.8.0 (unreleased)
- Added support for firing system hooks on group create/destroy and adding/removing users to group (Boyan Tabakov)
- Added support for firing system hooks on group create/destroy and adding/removing users to group (Boyan Tabakov)
- Added persistent collapse button for left side nav bar (Jason Blanchard)
- Added persistent collapse button for left side nav bar (Jason Blanchard)
- Prevent losing unsaved comments by automatically restoring them when comment page is loaded again.
- Prevent losing unsaved comments by automatically restoring them when comment page is loaded again.
- Clean the username acquired from OAuth/LDAP so it doesn't fail username validation and block signing up.
v 7.7.2
v 7.7.2
- Update GitLab Shell to version 2.4.2 that fixes a bug when developers can push to protected branch
- Update GitLab Shell to version 2.4.2 that fixes a bug when developers can push to protected branch
...
...
app/models/user.rb
View file @
6685661b
...
@@ -243,6 +243,22 @@ class User < ActiveRecord::Base
...
@@ -243,6 +243,22 @@ class User < ActiveRecord::Base
def
build_user
(
attrs
=
{})
def
build_user
(
attrs
=
{})
User
.
new
(
attrs
)
User
.
new
(
attrs
)
end
end
def
clean_username
(
username
)
username
.
gsub!
(
/@.*\z/
,
""
)
username
.
gsub!
(
/\.git\z/
,
""
)
username
.
gsub!
(
/\A-/
,
""
)
username
.
gsub!
(
/[^a-zA-Z0-9_\-\.]/
,
""
)
counter
=
0
base
=
username
while
by_login
(
username
).
present?
counter
+=
1
username
=
"
#{
base
}#{
counter
}
"
end
username
end
end
end
#
#
...
...
lib/gitlab/oauth/user.rb
View file @
6685661b
...
@@ -86,7 +86,7 @@ module Gitlab
...
@@ -86,7 +86,7 @@ module Gitlab
def
user_attributes
def
user_attributes
{
{
name:
auth_hash
.
name
,
name:
auth_hash
.
name
,
username:
auth_hash
.
username
,
username:
::
User
.
clean_username
(
auth_hash
.
username
)
,
email:
auth_hash
.
email
,
email:
auth_hash
.
email
,
password:
auth_hash
.
password
,
password:
auth_hash
.
password
,
password_confirmation:
auth_hash
.
password
password_confirmation:
auth_hash
.
password
...
...
spec/lib/gitlab/oauth/user_spec.rb
View file @
6685661b
...
@@ -8,7 +8,7 @@ describe Gitlab::OAuth::User do
...
@@ -8,7 +8,7 @@ describe Gitlab::OAuth::User do
let
(
:auth_hash
)
{
double
(
uid:
uid
,
provider:
provider
,
info:
double
(
info_hash
))
}
let
(
:auth_hash
)
{
double
(
uid:
uid
,
provider:
provider
,
info:
double
(
info_hash
))
}
let
(
:info_hash
)
do
let
(
:info_hash
)
do
{
{
nickname:
'
john
'
,
nickname:
'
-john+gitlab-ETC%.git@gmail.com
'
,
name:
'John'
,
name:
'John'
,
email:
'john@mail.com'
email:
'john@mail.com'
}
}
...
...
spec/models/user_spec.rb
View file @
6685661b
...
@@ -301,6 +301,16 @@ describe User do
...
@@ -301,6 +301,16 @@ describe User do
end
end
end
end
describe
".clean_username"
do
let!
(
:user1
)
{
create
(
:user
,
username:
"johngitlab-etc"
)
}
let!
(
:user2
)
{
create
(
:user
,
username:
"JohnGitLab-etc1"
)
}
it
"cleans a username and makes sure it's available"
do
expect
(
User
.
clean_username
(
"-john+gitlab-ETC%.git@gmail.com"
)).
to
eq
(
"johngitlab-ETC2"
)
end
end
describe
'all_ssh_keys'
do
describe
'all_ssh_keys'
do
it
{
should
have_many
(
:keys
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:keys
).
dependent
(
:destroy
)
}
...
...
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