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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
6787774a
Commit
6787774a
authored
9 years ago
by
Arthur Schiwon
Browse files
Options
Downloads
Patches
Plain Diff
integration tests for hardening user home retrieval
parent
0e922b18
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/user_ldap/tests/integration/lib/integrationtestuserhome.php
+159
-0
159 additions, 0 deletions
...er_ldap/tests/integration/lib/integrationtestuserhome.php
with
159 additions
and
0 deletions
apps/user_ldap/tests/integration/lib/integrationtestuserhome.php
0 → 100644
+
159
−
0
View file @
6787774a
<?php
/**
* Created by PhpStorm.
* User: blizzz
* Date: 06.08.15
* Time: 08:19
*/
namespace
OCA\user_ldap\tests\integration\lib
;
use
OCA\user_ldap
\lib\user\Manager
as
LDAPUserManager
;
use
OCA\user_ldap
\tests\integration\AbstractIntegrationTest
;
use
OCA\User_LDAP
\Mapping\UserMapping
;
use
OCA\user_ldap\USER_LDAP
;
require_once
__DIR__
.
'/../../../../../lib/base.php'
;
class
IntegrationTestUserHome
extends
AbstractIntegrationTest
{
/** @var UserMapping */
protected
$mapping
;
/** @var USER_LDAP */
protected
$backend
;
/**
* prepares the LDAP environment and sets up a test configuration for
* the LDAP backend.
*/
public
function
init
()
{
require
(
__DIR__
.
'/../setup-scripts/createExplicitUsers.php'
);
parent
::
init
();
$this
->
mapping
=
new
UserMapping
(
\OC
::
$server
->
getDatabaseConnection
());
$this
->
mapping
->
clear
();
$this
->
access
->
setUserMapper
(
$this
->
mapping
);
$this
->
backend
=
new
\OCA\user_ldap\USER_LDAP
(
$this
->
access
,
\OC
::
$server
->
getConfig
());
}
/**
* sets up the LDAP configuration to be used for the test
*/
protected
function
initConnection
()
{
parent
::
initConnection
();
$this
->
connection
->
setConfiguration
([
'homeFolderNamingRule'
=>
'homeDirectory'
,
]);
}
/**
* initializes an LDAP user manager instance
* @return LDAPUserManager
*/
protected
function
initUserManager
()
{
$this
->
userManager
=
new
LDAPUserManager
(
\OC
::
$server
->
getConfig
(),
new
\OCA\user_ldap\lib\FilesystemHelper
(),
new
\OCA\user_ldap\lib\LogWrapper
(),
\OC
::
$server
->
getAvatarManager
(),
new
\OCP\Image
(),
\OC
::
$server
->
getDatabaseConnection
()
);
}
/**
* homeDirectory on LDAP is empty. Return values of getHome should be
* identical to user name, following ownCloud default.
*
* @return bool
*/
protected
function
case1
()
{
\OC
::
$server
->
getConfig
()
->
setAppValue
(
'user_ldap'
,
'enforce_home_folder_naming_rule'
,
false
);
$userManager
=
\oc
::
$server
->
getUserManager
();
$userManager
->
clearBackends
();
$userManager
->
registerBackend
(
$this
->
backend
);
$users
=
$userManager
->
search
(
''
,
5
,
0
);
foreach
(
$users
as
$user
)
{
$home
=
$user
->
getHome
();
$uid
=
$user
->
getUID
();
$posFound
=
strpos
(
$home
,
'/'
.
$uid
);
$posExpected
=
strlen
(
$home
)
-
(
strlen
(
$uid
)
+
1
);
if
(
$posFound
===
false
||
$posFound
!==
$posExpected
)
{
print
(
'"'
.
$user
->
getUID
()
.
'" was not found in "'
.
$home
.
'" or does not end with it.'
.
PHP_EOL
);
return
false
;
}
}
return
true
;
}
/**
* homeDirectory on LDAP is empty. Having the attributes set is enforced.
*
* @return bool
*/
protected
function
case2
()
{
\OC
::
$server
->
getConfig
()
->
setAppValue
(
'user_ldap'
,
'enforce_home_folder_naming_rule'
,
true
);
$userManager
=
\oc
::
$server
->
getUserManager
();
// clearing backends is critical, otherwise the userManager will have
// the user objects cached and the value from case1 returned
$userManager
->
clearBackends
();
$userManager
->
registerBackend
(
$this
->
backend
);
$users
=
$userManager
->
search
(
''
,
5
,
0
);
try
{
foreach
(
$users
as
$user
)
{
$user
->
getHome
();
print
(
'User home was retrieved without throwing an Exception!'
.
PHP_EOL
);
return
false
;
}
}
catch
(
\Exception
$e
)
{
if
(
strpos
(
$e
->
getMessage
(),
'Home dir attribute'
)
===
0
)
{
return
true
;
}
}
return
false
;
}
/**
* homeDirectory on LDAP is set to "attr:" which is effectively empty.
* Return values of getHome should be ownCloud default.
*
* @return bool
*/
protected
function
case3
()
{
\OC
::
$server
->
getConfig
()
->
setAppValue
(
'user_ldap'
,
'enforce_home_folder_naming_rule'
,
true
);
$this
->
connection
->
setConfiguration
([
'homeFolderNamingRule'
=>
'attr:'
,
]);
$userManager
=
\oc
::
$server
->
getUserManager
();
$userManager
->
clearBackends
();
$userManager
->
registerBackend
(
$this
->
backend
);
$users
=
$userManager
->
search
(
''
,
5
,
0
);
try
{
foreach
(
$users
as
$user
)
{
$home
=
$user
->
getHome
();
$uid
=
$user
->
getUID
();
$posFound
=
strpos
(
$home
,
'/'
.
$uid
);
$posExpected
=
strlen
(
$home
)
-
(
strlen
(
$uid
)
+
1
);
if
(
$posFound
===
false
||
$posFound
!==
$posExpected
)
{
print
(
'"'
.
$user
->
getUID
()
.
'" was not found in "'
.
$home
.
'" or does not end with it.'
.
PHP_EOL
);
return
false
;
}
}
}
catch
(
\Exception
$e
)
{
print
(
"Unexpected Exception: "
.
$e
->
getMessage
()
.
PHP_EOL
);
return
false
;
}
return
true
;
}
}
require_once
(
__DIR__
.
'/../setup-scripts/config.php'
);
$test
=
new
IntegrationTestUserHome
(
$host
,
$port
,
$adn
,
$apwd
,
$bdn
);
$test
->
init
();
$test
->
run
();
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