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
a68b1963
Commit
a68b1963
authored
Sep 03, 2014
by
Jan-Willem van der Meer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Less private methods, more test ordering
parent
61d0bf0b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
60 deletions
+61
-60
lib/gitlab/ldap/access.rb
lib/gitlab/ldap/access.rb
+1
-1
spec/lib/gitlab/ldap/access_spec.rb
spec/lib/gitlab/ldap/access_spec.rb
+60
-59
No files found.
lib/gitlab/ldap/access.rb
View file @
a68b1963
...
...
@@ -127,7 +127,6 @@ module Gitlab
end
end
private
def
ldap_groups
@ldap_groups
||=
::
LdapGroupLink
.
distinct
(
:cn
).
pluck
(
:cn
).
map
do
|
cn
|
Gitlab
::
LDAP
::
Group
.
find_by_cn
(
cn
,
adapter
)
...
...
@@ -141,6 +140,7 @@ module Gitlab
end
.
map
(
&
:cn
)
end
private
def
gitlab_groups_with_ldap_link
::
Group
.
includes
(
:ldap_group_links
).
references
(
:ldap_group_links
).
where
.
not
(
ldap_group_links:
{
id:
nil
})
...
...
spec/lib/gitlab/ldap/access_spec.rb
View file @
a68b1963
...
...
@@ -186,6 +186,66 @@ objectclass: posixGroup
end
end
describe
:update_ldap_group_links
do
let
(
:cns_with_access
)
{
%w(ldap-group1 ldap-group2)
}
let
(
:gitlab_group_1
)
{
create
:group
}
let
(
:gitlab_group_2
)
{
create
:group
}
before
do
access
.
stub
(
:get_ldap_user
)
access
.
stub
(
cns_with_access:
cns_with_access
)
end
context
"non existing access for group-1, allowed via ldap-group1 as MASTER"
do
before
do
gitlab_group_1
.
ldap_group_links
.
create
cn:
'ldap-group1'
,
group_access:
Gitlab
::
Access
::
MASTER
end
it
"gives the user master access for group 1"
do
access
.
update_ldap_group_links
(
user
)
expect
(
gitlab_group_1
.
has_master?
(
user
)
).
to
be_true
end
end
context
"existing access as guest for group-1, allowed via ldap-group1 as DEVELOPER"
do
before
do
gitlab_group_1
.
users_groups
.
guests
.
create
(
user_id:
user
.
id
)
gitlab_group_1
.
ldap_group_links
.
create
cn:
'ldap-group1'
,
group_access:
Gitlab
::
Access
::
MASTER
end
it
"upgrades the users access to master for group 1"
do
expect
{
access
.
update_ldap_group_links
(
user
)
}.
to
\
change
{
gitlab_group_1
.
has_master?
(
user
)
}.
from
(
false
).
to
(
true
)
end
end
context
"existing access as MASTER for group-1, allowed via ldap-group1 as DEVELOPER"
do
before
do
gitlab_group_1
.
users_groups
.
masters
.
create
(
user_id:
user
.
id
)
gitlab_group_1
.
ldap_group_links
.
create
cn:
'ldap-group1'
,
group_access:
Gitlab
::
Access
::
DEVELOPER
end
it
"keeps the users master access for group 1"
do
expect
{
access
.
update_ldap_group_links
(
user
)
}.
not_to
\
change
{
gitlab_group_1
.
has_master?
(
user
)
}
end
end
context
"existing access as master for group-1, not allowed"
do
before
do
gitlab_group_1
.
users_groups
.
masters
.
create
(
user_id:
user
.
id
)
gitlab_group_1
.
ldap_group_links
.
create
cn:
'ldap-group1'
,
group_access:
Gitlab
::
Access
::
MASTER
access
.
stub
(
cns_with_access:
[
'ldap-group2'
])
end
it
"removes user from gitlab_group_1"
do
expect
{
access
.
update_ldap_group_links
(
user
)
}.
to
\
change
{
gitlab_group_1
.
members
.
where
(
user_id:
user
).
any?
}.
from
(
true
).
to
(
false
)
end
end
end
describe
'ldap_groups'
do
let
(
:ldap_group_1
)
do
Net
::
LDAP
::
Entry
.
from_single_ldif_string
(
...
...
@@ -255,64 +315,5 @@ objectclass: posixGroup
expect
(
access
.
cns_with_access
(
ldap_user
)).
to
eql
[
'group1'
]
end
end
describe
:update_ldap_group_links
do
let
(
:cns_with_access
)
{
%w(ldap-group1 ldap-group2)
}
let
(
:gitlab_group_1
)
{
create
:group
}
let
(
:gitlab_group_2
)
{
create
:group
}
before
do
access
.
stub
(
:get_ldap_user
)
access
.
stub
(
cns_with_access:
cns_with_access
)
end
context
"non existing access for group-1, allowed via ldap-group1 as MASTER"
do
before
do
gitlab_group_1
.
ldap_group_links
.
create
cn:
'ldap-group1'
,
group_access:
Gitlab
::
Access
::
MASTER
end
it
"gives the user master access for group 1"
do
access
.
update_ldap_group_links
(
user
)
expect
(
gitlab_group_1
.
has_master?
(
user
)
).
to
be_true
end
end
context
"existing access as guest for group-1, allowed via ldap-group1 as DEVELOPER"
do
before
do
gitlab_group_1
.
users_groups
.
guests
.
create
(
user_id:
user
.
id
)
gitlab_group_1
.
ldap_group_links
.
create
cn:
'ldap-group1'
,
group_access:
Gitlab
::
Access
::
MASTER
end
it
"upgrades the users access to master for group 1"
do
expect
{
access
.
update_ldap_group_links
(
user
)
}.
to
\
change
{
gitlab_group_1
.
has_master?
(
user
)
}.
from
(
false
).
to
(
true
)
end
end
context
"existing access as MASTER for group-1, allowed via ldap-group1 as DEVELOPER"
do
before
do
gitlab_group_1
.
users_groups
.
masters
.
create
(
user_id:
user
.
id
)
gitlab_group_1
.
ldap_group_links
.
create
cn:
'ldap-group1'
,
group_access:
Gitlab
::
Access
::
DEVELOPER
end
it
"keeps the users master access for group 1"
do
expect
{
access
.
update_ldap_group_links
(
user
)
}.
not_to
\
change
{
gitlab_group_1
.
has_master?
(
user
)
}
end
end
context
"existing access as master for group-1, not allowed"
do
before
do
gitlab_group_1
.
users_groups
.
masters
.
create
(
user_id:
user
.
id
)
gitlab_group_1
.
ldap_group_links
.
create
cn:
'ldap-group1'
,
group_access:
Gitlab
::
Access
::
MASTER
access
.
stub
(
cns_with_access:
[
'ldap-group2'
])
end
it
"removes user from gitlab_group_1"
do
expect
{
access
.
update_ldap_group_links
(
user
)
}.
to
\
change
{
gitlab_group_1
.
members
.
where
(
user_id:
user
).
any?
}.
from
(
true
).
to
(
false
)
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