Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
077ab272
Commit
077ab272
authored
10 years ago
by
Jörn Friedrich Dreyer
Browse files
Options
Downloads
Patches
Plain Diff
fix_tests
Conflicts: apps/user_ldap/tests/user_ldap.php
parent
8964c506
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/user_ldap/lib/user/manager.php
+7
-2
7 additions, 2 deletions
apps/user_ldap/lib/user/manager.php
apps/user_ldap/tests/user/manager.php
+0
-4
0 additions, 4 deletions
apps/user_ldap/tests/user/manager.php
apps/user_ldap/tests/user_ldap.php
+194
-43
194 additions, 43 deletions
apps/user_ldap/tests/user_ldap.php
with
201 additions
and
49 deletions
apps/user_ldap/lib/user/manager.php
+
7
−
2
View file @
077ab272
...
@@ -149,6 +149,11 @@ class Manager {
...
@@ -149,6 +149,11 @@ class Manager {
$this
->
access
->
getUserMapper
());
$this
->
access
->
getUserMapper
());
}
}
/**
* @brief returns a User object by it's ownCloud username
* @param string the DN or username of the user
* @return \OCA\user_ldap\lib\user\User|\OCA\user_ldap\lib\user\OfflineUser|null
*/
protected
function
createInstancyByUserName
(
$id
)
{
protected
function
createInstancyByUserName
(
$id
)
{
//most likely a uid. Check whether it is a deleted user
//most likely a uid. Check whether it is a deleted user
if
(
$this
->
isDeletedUser
(
$id
))
{
if
(
$this
->
isDeletedUser
(
$id
))
{
...
@@ -158,12 +163,12 @@ class Manager {
...
@@ -158,12 +163,12 @@ class Manager {
if
(
$dn
!==
false
)
{
if
(
$dn
!==
false
)
{
return
$this
->
createAndCache
(
$dn
,
$id
);
return
$this
->
createAndCache
(
$dn
,
$id
);
}
}
throw
new
\Exception
(
'Could not create User instance'
)
;
return
null
;
}
}
/**
/**
* @brief returns a User object by it's DN or ownCloud username
* @brief returns a User object by it's DN or ownCloud username
* @param string the
DN or
username of the user
* @param string the username of the user
* @return \OCA\user_ldap\lib\user\User|\OCA\user_ldap\lib\user\OfflineUser|null
* @return \OCA\user_ldap\lib\user\User|\OCA\user_ldap\lib\user\OfflineUser|null
* @throws \Exception when connection could not be established
* @throws \Exception when connection could not be established
*/
*/
...
...
This diff is collapsed.
Click to expand it.
apps/user_ldap/tests/user/manager.php
+
0
−
4
View file @
077ab272
...
@@ -145,8 +145,6 @@ class Test_User_Manager extends \Test\TestCase {
...
@@ -145,8 +145,6 @@ class Test_User_Manager extends \Test\TestCase {
$manager
=
new
Manager
(
$config
,
$filesys
,
$log
,
$avaMgr
,
$image
,
$dbc
);
$manager
=
new
Manager
(
$config
,
$filesys
,
$log
,
$avaMgr
,
$image
,
$dbc
);
$manager
->
setLdapAccess
(
$access
);
$manager
->
setLdapAccess
(
$access
);
$user
=
$manager
->
get
(
$inputDN
);
$user
=
$manager
->
get
(
$inputDN
);
$this
->
assertNull
(
$user
);
}
}
public
function
testGetByUidExisting
()
{
public
function
testGetByUidExisting
()
{
...
@@ -194,8 +192,6 @@ class Test_User_Manager extends \Test\TestCase {
...
@@ -194,8 +192,6 @@ class Test_User_Manager extends \Test\TestCase {
$manager
=
new
Manager
(
$config
,
$filesys
,
$log
,
$avaMgr
,
$image
,
$dbc
);
$manager
=
new
Manager
(
$config
,
$filesys
,
$log
,
$avaMgr
,
$image
,
$dbc
);
$manager
->
setLdapAccess
(
$access
);
$manager
->
setLdapAccess
(
$access
);
$user
=
$manager
->
get
(
$uid
);
$user
=
$manager
->
get
(
$uid
);
$this
->
assertNull
(
$user
);
}
}
}
}
This diff is collapsed.
Click to expand it.
apps/user_ldap/tests/user_ldap.php
+
194
−
43
View file @
077ab272
...
@@ -428,10 +428,42 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
...
@@ -428,10 +428,42 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
//test for existing user
//test for existing user
$result
=
$backend
->
userExists
(
'gunslinger'
);
$result
=
$backend
->
userExists
(
'gunslinger'
);
$this
->
assertTrue
(
$result
);
$this
->
assertTrue
(
$result
);
}
/**
* @expectedException \Exception
*/
public
function
testUserExistsForDeleted
()
{
$access
=
$this
->
getAccessMock
();
$backend
=
new
UserLDAP
(
$access
);
$this
->
prepareMockForUserExists
(
$access
);
$access
->
expects
(
$this
->
any
())
->
method
(
'readAttribute'
)
->
will
(
$this
->
returnCallback
(
function
(
$dn
)
{
if
(
$dn
===
'dnOfRoland,dc=test'
)
{
return
array
();
}
return
false
;
}));
//test for deleted user
//test for deleted user
$result
=
$backend
->
userExists
(
'formerUser'
);
$result
=
$backend
->
userExists
(
'formerUser'
);
$this
->
assertFalse
(
$result
);
}
public
function
testUserExistsForNeverExisting
()
{
$access
=
$this
->
getAccessMock
();
$backend
=
new
UserLDAP
(
$access
);
$this
->
prepareMockForUserExists
(
$access
);
$access
->
expects
(
$this
->
any
())
->
method
(
'readAttribute'
)
->
will
(
$this
->
returnCallback
(
function
(
$dn
)
{
if
(
$dn
===
'dnOfRoland,dc=test'
)
{
return
array
();
}
return
false
;
}));
//test for never-existing user
//test for never-existing user
$result
=
$backend
->
userExists
(
'mallory'
);
$result
=
$backend
->
userExists
(
'mallory'
);
...
@@ -456,10 +488,44 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
...
@@ -456,10 +488,44 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
//test for existing user
//test for existing user
$result
=
\OCP\User
::
userExists
(
'gunslinger'
);
$result
=
\OCP\User
::
userExists
(
'gunslinger'
);
$this
->
assertTrue
(
$result
);
$this
->
assertTrue
(
$result
);
}
/**
* @expectedException \Exception
*/
public
function
testUserExistsPublicAPIForDeleted
()
{
$access
=
$this
->
getAccessMock
();
$backend
=
new
UserLDAP
(
$access
);
$this
->
prepareMockForUserExists
(
$access
);
\OC_User
::
useBackend
(
$backend
);
$access
->
expects
(
$this
->
any
())
->
method
(
'readAttribute'
)
->
will
(
$this
->
returnCallback
(
function
(
$dn
)
{
if
(
$dn
===
'dnOfRoland,dc=test'
)
{
return
array
();
}
return
false
;
}));
//test for deleted user
//test for deleted user
$result
=
\OCP\User
::
userExists
(
'formerUser'
);
$result
=
\OCP\User
::
userExists
(
'formerUser'
);
$this
->
assertFalse
(
$result
);
}
public
function
testUserExistsPublicAPIForNeverExisting
()
{
$access
=
$this
->
getAccessMock
();
$backend
=
new
UserLDAP
(
$access
);
$this
->
prepareMockForUserExists
(
$access
);
\OC_User
::
useBackend
(
$backend
);
$access
->
expects
(
$this
->
any
())
->
method
(
'readAttribute'
)
->
will
(
$this
->
returnCallback
(
function
(
$dn
)
{
if
(
$dn
===
'dnOfRoland,dc=test'
)
{
return
array
();
}
return
false
;
}));
//test for never-existing user
//test for never-existing user
$result
=
\OCP\User
::
userExists
(
'mallory'
);
$result
=
\OCP\User
::
userExists
(
'mallory'
);
...
@@ -475,7 +541,7 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
...
@@ -475,7 +541,7 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
$this
->
assertFalse
(
$result
);
$this
->
assertFalse
(
$result
);
}
}
public
function
testGetHome
()
{
public
function
testGetHome
AbsolutePath
()
{
$access
=
$this
->
getAccessMock
();
$access
=
$this
->
getAccessMock
();
$config
=
$this
->
getMock
(
'\OCP\IConfig'
);
$config
=
$this
->
getMock
(
'\OCP\IConfig'
);
$backend
=
new
UserLDAP
(
$access
,
$config
);
$backend
=
new
UserLDAP
(
$access
,
$config
);
...
@@ -500,12 +566,6 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
...
@@ -500,12 +566,6 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
}
}
return
array
();
return
array
();
break
;
break
;
case
'dnOfLadyOfShadows,dc=test'
:
if
(
$attr
===
'testAttribute'
)
{
return
array
(
'susannah/'
);
}
return
array
();
break
;
default
:
default
:
return
false
;
return
false
;
}
}
...
@@ -519,10 +579,68 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
...
@@ -519,10 +579,68 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
//absolut path
//absolut path
$result
=
$backend
->
getHome
(
'gunslinger'
);
$result
=
$backend
->
getHome
(
'gunslinger'
);
$this
->
assertEquals
(
'/tmp/rolandshome/'
,
$result
);
$this
->
assertEquals
(
'/tmp/rolandshome/'
,
$result
);
}
public
function
testGetHomeDatadirRelative
()
{
$access
=
$this
->
getAccessMock
();
$backend
=
new
UserLDAP
(
$access
);
$this
->
prepareMockForUserExists
(
$access
);
$access
->
connection
->
expects
(
$this
->
any
())
->
method
(
'__get'
)
->
will
(
$this
->
returnCallback
(
function
(
$name
)
{
if
(
$name
===
'homeFolderNamingRule'
)
{
return
'attr:testAttribute'
;
}
return
null
;
}));
$access
->
expects
(
$this
->
any
())
->
method
(
'readAttribute'
)
->
will
(
$this
->
returnCallback
(
function
(
$dn
,
$attr
)
{
switch
(
$dn
)
{
case
'dnOfLadyOfShadows,dc=test'
:
if
(
$attr
===
'testAttribute'
)
{
return
array
(
'susannah/'
);
}
return
array
();
break
;
default
:
return
false
;
}
}));
//datadir-relativ path
//datadir-relativ path
$result
=
$backend
->
getHome
(
'ladyofshadows'
);
$result
=
$backend
->
getHome
(
'ladyofshadows'
);
$datadir
=
\OCP\Config
::
getSystemValue
(
'datadirectory'
,
\OC
::
$SERVERROOT
.
'/data'
);
$this
->
assertEquals
(
$datadir
.
'/susannah/'
,
$result
);
$this
->
assertEquals
(
$datadir
.
'/susannah/'
,
$result
);
}
/**
* @expectedException \Exception
*/
public
function
testGetHomeNoPath
()
{
$access
=
$this
->
getAccessMock
();
$backend
=
new
UserLDAP
(
$access
);
$this
->
prepareMockForUserExists
(
$access
);
$access
->
connection
->
expects
(
$this
->
any
())
->
method
(
'__get'
)
->
will
(
$this
->
returnCallback
(
function
(
$name
)
{
if
(
$name
===
'homeFolderNamingRule'
)
{
return
'attr:testAttribute'
;
}
return
null
;
}));
$access
->
expects
(
$this
->
any
())
->
method
(
'readAttribute'
)
->
will
(
$this
->
returnCallback
(
function
(
$dn
,
$attr
)
{
switch
(
$dn
)
{
default
:
return
false
;
}
}));
//no path at all – triggers OC default behaviour
//no path at all – triggers OC default behaviour
$result
=
$backend
->
getHome
(
'newyorker'
);
$result
=
$backend
->
getHome
(
'newyorker'
);
...
@@ -562,6 +680,12 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
...
@@ -562,6 +680,12 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
$backend
=
new
UserLDAP
(
$access
,
$this
->
getMock
(
'\OCP\IConfig'
));
$backend
=
new
UserLDAP
(
$access
,
$this
->
getMock
(
'\OCP\IConfig'
));
$this
->
prepareMockForUserExists
(
$access
);
$this
->
prepareMockForUserExists
(
$access
);
$access
->
connection
->
expects
(
$this
->
any
())
->
method
(
'getConnectionResource'
)
->
will
(
$this
->
returnCallback
(
function
()
{
return
true
;
}));
//with displayName
//with displayName
$result
=
$backend
->
getDisplayName
(
'gunslinger'
);
$result
=
$backend
->
getDisplayName
(
'gunslinger'
);
$this
->
assertEquals
(
'Roland Deschain'
,
$result
);
$this
->
assertEquals
(
'Roland Deschain'
,
$result
);
...
@@ -573,9 +697,36 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
...
@@ -573,9 +697,36 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
public
function
testGetDisplayNamePublicAPI
()
{
public
function
testGetDisplayNamePublicAPI
()
{
$access
=
$this
->
getAccessMock
();
$access
=
$this
->
getAccessMock
();
$access
->
expects
(
$this
->
any
())
->
method
(
'username2dn'
)
->
will
(
$this
->
returnCallback
(
function
(
$uid
)
{
switch
(
$uid
)
{
case
'gunslinger'
:
return
'dnOfRoland,dc=test'
;
break
;
case
'formerUser'
:
return
'dnOfFormerUser,dc=test'
;
break
;
case
'newyorker'
:
return
'dnOfNewYorker,dc=test'
;
break
;
case
'ladyofshadows'
:
return
'dnOfLadyOfShadows,dc=test'
;
break
;
default
:
return
false
;
}
}));
$this
->
prepareAccessForGetDisplayName
(
$access
);
$this
->
prepareAccessForGetDisplayName
(
$access
);
$backend
=
new
UserLDAP
(
$access
,
$this
->
getMock
(
'\OCP\IConfig'
));
$backend
=
new
UserLDAP
(
$access
,
$this
->
getMock
(
'\OCP\IConfig'
));
$this
->
prepareMockForUserExists
(
$access
);
$this
->
prepareMockForUserExists
(
$access
);
$access
->
connection
->
expects
(
$this
->
any
())
->
method
(
'getConnectionResource'
)
->
will
(
$this
->
returnCallback
(
function
()
{
return
true
;
}));
\OC_User
::
useBackend
(
$backend
);
\OC_User
::
useBackend
(
$backend
);
//with displayName
//with displayName
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment