unit test adjustment

Signed-off-by: Roger Szabo <roger.szabo@web.de>
This commit is contained in:
Roger Szabo 2017-04-07 18:06:50 +08:00
parent 0ea8729d1d
commit 5fa218051b
3 changed files with 35 additions and 23 deletions

View File

@ -611,7 +611,7 @@ class User {
$uid = $params['uid']; $uid = $params['uid'];
if(isset($uid) && $uid === $this->getUsername()) { if(isset($uid) && $uid === $this->getUsername()) {
//retrieve relevant user attributes //retrieve relevant user attributes
$result = $this->access->search('objectclass=*', $this->dn, ['sn', 'pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']); $result = $this->access->search('objectclass=*', $this->dn, ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']);
if(array_key_exists('pwdpolicysubentry', $result[0])) { if(array_key_exists('pwdpolicysubentry', $result[0])) {
$pwdPolicySubentry = $result[0]['pwdpolicysubentry']; $pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
@ -628,7 +628,7 @@ class User {
$cacheKey = 'ppolicyAttributes' . $ppolicyDN; $cacheKey = 'ppolicyAttributes' . $ppolicyDN;
$result = $this->connection->getFromCache($cacheKey); $result = $this->connection->getFromCache($cacheKey);
if(is_null($result)) { if(is_null($result)) {
$result = $this->access->search('objectclass=*', $ppolicyDN, ['cn','pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']); $result = $this->access->search('objectclass=*', $ppolicyDN, ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
$this->connection->writeToCache($cacheKey, $result); $this->connection->writeToCache($cacheKey, $result);
} }

View File

@ -1263,16 +1263,22 @@ class UserTest extends \Test\TestCase {
})); }));
$access->expects($this->any()) $access->expects($this->any())
->method('readAttribute') ->method('search')
->will($this->returnCallback(function($dn, $attr) { ->will($this->returnCallback(function($filter, $base) {
if($attr === 'pwdchangedtime') { if($base === 'uid=alice') {
return array((new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'); return array(
array(
'pwdchangedtime' => array((new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'),
),
);
} }
if($dn === 'cn=default,ou=policies,dc=foo,dc=bar' && $attr === 'pwdmaxage') { if($base === 'cn=default,ou=policies,dc=foo,dc=bar') {
return array('2592000'); return array(
} array(
if($dn === 'cn=default,ou=policies,dc=foo,dc=bar' && $attr === 'pwdexpirewarning') { 'pwdmaxage' => array('2592000'),
return array('2591999'); 'pwdexpirewarning' => array('2591999'),
),
);
} }
return array(); return array();
})); }));
@ -1329,19 +1335,23 @@ class UserTest extends \Test\TestCase {
})); }));
$access->expects($this->any()) $access->expects($this->any())
->method('readAttribute') ->method('search')
->will($this->returnCallback(function($dn, $attr) { ->will($this->returnCallback(function($filter, $base) {
if($attr === 'pwdpolicysubentry') { if($base === 'uid=alice') {
return array('cn=custom,ou=policies,dc=foo,dc=bar'); return array(
array(
'pwdpolicysubentry' => array('cn=custom,ou=policies,dc=foo,dc=bar'),
'pwdchangedtime' => array((new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'),
)
);
} }
if($attr === 'pwdchangedtime') { if($base === 'cn=custom,ou=policies,dc=foo,dc=bar') {
return array((new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'); return array(
} array(
if($dn === 'cn=custom,ou=policies,dc=foo,dc=bar' && $attr === 'pwdmaxage') { 'pwdmaxage' => array('2592000'),
return array('2592000'); 'pwdexpirewarning' => array('2591999'),
} )
if($dn === 'cn=custom,ou=policies,dc=foo,dc=bar' && $attr === 'pwdexpirewarning') { );
return array('2591999');
} }
return array(); return array();
})); }));

View File

@ -19,3 +19,5 @@ if (!class_exists('PHPUnit_Framework_TestCase')) {
} }
OC_Hook::clear(); OC_Hook::clear();
set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/share/php');