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
8399de0c
Commit
8399de0c
authored
Oct 31, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Normalize LDAP DN when looking up identity
parent
bb63ee68
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
35 additions
and
12 deletions
+35
-12
app/models/identity.rb
app/models/identity.rb
+4
-1
changelogs/unreleased/dm-ldap-identity-normalize-dn.yml
changelogs/unreleased/dm-ldap-identity-normalize-dn.yml
+5
-0
lib/gitlab/ldap/auth_hash.rb
lib/gitlab/ldap/auth_hash.rb
+1
-1
lib/gitlab/ldap/user.rb
lib/gitlab/ldap/user.rb
+3
-2
spec/lib/gitlab/ldap/authentication_spec.rb
spec/lib/gitlab/ldap/authentication_spec.rb
+2
-2
spec/lib/gitlab/ldap/user_spec.rb
spec/lib/gitlab/ldap/user_spec.rb
+5
-3
spec/lib/gitlab/o_auth/user_spec.rb
spec/lib/gitlab/o_auth/user_spec.rb
+1
-1
spec/lib/gitlab/saml/user_spec.rb
spec/lib/gitlab/saml/user_spec.rb
+1
-1
spec/models/identity_spec.rb
spec/models/identity_spec.rb
+13
-1
No files found.
app/models/identity.rb
View file @
8399de0c
...
@@ -7,7 +7,10 @@ class Identity < ActiveRecord::Base
...
@@ -7,7 +7,10 @@ class Identity < ActiveRecord::Base
validates
:extern_uid
,
allow_blank:
true
,
uniqueness:
{
scope: :provider
}
validates
:extern_uid
,
allow_blank:
true
,
uniqueness:
{
scope: :provider
}
validates
:user_id
,
uniqueness:
{
scope: :provider
}
validates
:user_id
,
uniqueness:
{
scope: :provider
}
scope
:with_extern_uid
,
->
(
provider
,
extern_uid
)
{
where
(
extern_uid:
extern_uid
,
provider:
provider
)
}
scope
:with_extern_uid
,
->
(
provider
,
extern_uid
)
do
extern_uid
=
Gitlab
::
LDAP
::
Person
.
normalize_dn
(
extern_uid
)
if
provider
.
starts_with?
(
'ldap'
)
where
(
extern_uid:
extern_uid
,
provider:
provider
)
end
def
ldap?
def
ldap?
provider
.
starts_with?
(
'ldap'
)
provider
.
starts_with?
(
'ldap'
)
...
...
changelogs/unreleased/dm-ldap-identity-normalize-dn.yml
0 → 100644
View file @
8399de0c
---
title
:
Normalize LDAP DN when looking up identity
merge_request
:
author
:
type
:
fixed
lib/gitlab/ldap/auth_hash.rb
View file @
8399de0c
...
@@ -4,7 +4,7 @@ module Gitlab
...
@@ -4,7 +4,7 @@ module Gitlab
module
LDAP
module
LDAP
class
AuthHash
<
Gitlab
::
OAuth
::
AuthHash
class
AuthHash
<
Gitlab
::
OAuth
::
AuthHash
def
uid
def
uid
Gitlab
::
LDAP
::
Person
.
normalize_dn
(
super
)
@uid
||=
Gitlab
::
LDAP
::
Person
.
normalize_dn
(
super
)
end
end
private
private
...
...
lib/gitlab/ldap/user.rb
View file @
8399de0c
...
@@ -9,10 +9,11 @@ module Gitlab
...
@@ -9,10 +9,11 @@ module Gitlab
class
User
<
Gitlab
::
OAuth
::
User
class
User
<
Gitlab
::
OAuth
::
User
class
<<
self
class
<<
self
def
find_by_uid_and_provider
(
uid
,
provider
)
def
find_by_uid_and_provider
(
uid
,
provider
)
# LDAP distinguished name is case-insensitive
uid
=
Gitlab
::
LDAP
::
Person
.
normalize_dn
(
uid
)
identity
=
::
Identity
identity
=
::
Identity
.
where
(
provider:
provider
)
.
where
(
provider:
provider
)
.
i
where
(
extern_uid:
uid
).
last
.
where
(
extern_uid:
uid
).
last
identity
&&
identity
.
user
identity
&&
identity
.
user
end
end
end
end
...
...
spec/lib/gitlab/ldap/authentication_spec.rb
View file @
8399de0c
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
LDAP
::
Authentication
do
describe
Gitlab
::
LDAP
::
Authentication
do
let
(
:
user
)
{
create
(
:omniauth_user
,
extern_uid:
dn
)
}
let
(
:
dn
)
{
'uid=John Smith, ou=People, dc=example, dc=com'
}
let
(
:
dn
)
{
'uid=john,ou=people,dc=example,dc=com'
}
let
(
:
user
)
{
create
(
:omniauth_user
,
extern_uid:
Gitlab
::
LDAP
::
Person
.
normalize_dn
(
dn
))
}
let
(
:login
)
{
'john'
}
let
(
:login
)
{
'john'
}
let
(
:password
)
{
'password'
}
let
(
:password
)
{
'password'
}
...
...
spec/lib/gitlab/ldap/user_spec.rb
View file @
8399de0c
...
@@ -44,23 +44,25 @@ describe Gitlab::LDAP::User do
...
@@ -44,23 +44,25 @@ describe Gitlab::LDAP::User do
end
end
describe
'.find_by_uid_and_provider'
do
describe
'.find_by_uid_and_provider'
do
let
(
:dn
)
{
'CN=John Åström, CN=Users, DC=Example, DC=com'
}
it
'retrieves the correct user'
do
it
'retrieves the correct user'
do
special_info
=
{
special_info
=
{
name:
'John Åström'
,
name:
'John Åström'
,
email:
'john@example.com'
,
email:
'john@example.com'
,
nickname:
'jastrom'
nickname:
'jastrom'
}
}
special_hash
=
OmniAuth
::
AuthHash
.
new
(
uid:
'CN=John Åström,CN=Users,DC=Example,DC=com'
,
provider:
'ldapmain'
,
info:
special_info
)
special_hash
=
OmniAuth
::
AuthHash
.
new
(
uid:
dn
,
provider:
'ldapmain'
,
info:
special_info
)
special_chars_user
=
described_class
.
new
(
special_hash
)
special_chars_user
=
described_class
.
new
(
special_hash
)
user
=
special_chars_user
.
save
user
=
special_chars_user
.
save
expect
(
described_class
.
find_by_uid_and_provider
(
special_hash
.
uid
,
special_hash
.
provider
)).
to
eq
user
expect
(
described_class
.
find_by_uid_and_provider
(
dn
,
'ldapmain'
)).
to
eq
user
end
end
end
end
describe
'find or create'
do
describe
'find or create'
do
it
"finds the user if already existing"
do
it
"finds the user if already existing"
do
create
(
:omniauth_user
,
extern_uid:
'uid=
John Smith,ou=P
eople,dc=example,dc=com'
,
provider:
'ldapmain'
)
create
(
:omniauth_user
,
extern_uid:
'uid=
john smith,ou=p
eople,dc=example,dc=com'
,
provider:
'ldapmain'
)
expect
{
ldap_user
.
save
}.
not_to
change
{
User
.
count
}
expect
{
ldap_user
.
save
}.
not_to
change
{
User
.
count
}
end
end
...
...
spec/lib/gitlab/o_auth/user_spec.rb
View file @
8399de0c
...
@@ -4,7 +4,7 @@ describe Gitlab::OAuth::User do
...
@@ -4,7 +4,7 @@ describe Gitlab::OAuth::User do
let
(
:oauth_user
)
{
described_class
.
new
(
auth_hash
)
}
let
(
:oauth_user
)
{
described_class
.
new
(
auth_hash
)
}
let
(
:gl_user
)
{
oauth_user
.
gl_user
}
let
(
:gl_user
)
{
oauth_user
.
gl_user
}
let
(
:uid
)
{
'my-uid'
}
let
(
:uid
)
{
'my-uid'
}
let
(
:dn
)
{
'uid=user1,ou=
P
eople,dc=example'
}
let
(
:dn
)
{
'uid=user1,ou=
p
eople,dc=example'
}
let
(
:provider
)
{
'my-provider'
}
let
(
:provider
)
{
'my-provider'
}
let
(
:auth_hash
)
{
OmniAuth
::
AuthHash
.
new
(
uid:
uid
,
provider:
provider
,
info:
info_hash
)
}
let
(
:auth_hash
)
{
OmniAuth
::
AuthHash
.
new
(
uid:
uid
,
provider:
provider
,
info:
info_hash
)
}
let
(
:info_hash
)
do
let
(
:info_hash
)
do
...
...
spec/lib/gitlab/saml/user_spec.rb
View file @
8399de0c
...
@@ -7,7 +7,7 @@ describe Gitlab::Saml::User do
...
@@ -7,7 +7,7 @@ describe Gitlab::Saml::User do
let
(
:saml_user
)
{
described_class
.
new
(
auth_hash
)
}
let
(
:saml_user
)
{
described_class
.
new
(
auth_hash
)
}
let
(
:gl_user
)
{
saml_user
.
gl_user
}
let
(
:gl_user
)
{
saml_user
.
gl_user
}
let
(
:uid
)
{
'my-uid'
}
let
(
:uid
)
{
'my-uid'
}
let
(
:dn
)
{
'uid=user1,ou=
P
eople,dc=example'
}
let
(
:dn
)
{
'uid=user1,ou=
p
eople,dc=example'
}
let
(
:provider
)
{
'saml'
}
let
(
:provider
)
{
'saml'
}
let
(
:raw_info_attr
)
{
{
'groups'
=>
%w(Developers Freelancers Designers)
}
}
let
(
:raw_info_attr
)
{
{
'groups'
=>
%w(Developers Freelancers Designers)
}
}
let
(
:auth_hash
)
{
OmniAuth
::
AuthHash
.
new
(
uid:
uid
,
provider:
provider
,
info:
info_hash
,
extra:
{
raw_info:
OneLogin
::
RubySaml
::
Attributes
.
new
(
raw_info_attr
)
})
}
let
(
:auth_hash
)
{
OmniAuth
::
AuthHash
.
new
(
uid:
uid
,
provider:
provider
,
info:
info_hash
,
extra:
{
raw_info:
OneLogin
::
RubySaml
::
Attributes
.
new
(
raw_info_attr
)
})
}
...
...
spec/models/identity_spec.rb
View file @
8399de0c
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Identity
do
describe
Identity
do
describe
'relations'
do
describe
'relations'
do
it
{
is_expected
.
to
belong_to
(
:user
)
}
it
{
is_expected
.
to
belong_to
(
:user
)
}
end
end
...
@@ -22,4 +22,16 @@ RSpec.describe Identity do
...
@@ -22,4 +22,16 @@ RSpec.describe Identity do
expect
(
other_identity
.
ldap?
).
to
be_falsey
expect
(
other_identity
.
ldap?
).
to
be_falsey
end
end
end
end
describe
'.with_extern_uid'
do
context
'LDAP identity'
do
let!
(
:ldap_identity
)
{
create
(
:identity
,
provider:
'ldapmain'
,
extern_uid:
'uid=john smith,ou=people,dc=example,dc=com'
)
}
it
'finds the identity when the DN is formatted differently'
do
identity
=
described_class
.
with_extern_uid
(
'ldapmain'
,
'uid=John Smith, ou=People, dc=example, dc=com'
).
first
expect
(
identity
).
to
eq
(
ldap_identity
)
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