瀏覽代碼

unit test adjustment

Signed-off-by: Roger Szabo <roger.szabo@web.de>
tags/v12.0.0beta1
Roger Szabo 7 年之前
父節點
當前提交
5fa218051b
共有 3 個檔案被更改,包括 35 行新增23 行删除
  1. 2
    2
      apps/user_ldap/lib/User/User.php
  2. 31
    21
      apps/user_ldap/tests/User/UserTest.php
  3. 2
    0
      tests/bootstrap.php

+ 2
- 2
apps/user_ldap/lib/User/User.php 查看文件

@@ -611,7 +611,7 @@ class User {
$uid = $params['uid'];
if(isset($uid) && $uid === $this->getUsername()) {
//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])) {
$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
@@ -628,7 +628,7 @@ class User {
$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
$result = $this->connection->getFromCache($cacheKey);
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);
}

+ 31
- 21
apps/user_ldap/tests/User/UserTest.php 查看文件

@@ -1263,16 +1263,22 @@ class UserTest extends \Test\TestCase {
}));

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

$access->expects($this->any())
->method('readAttribute')
->will($this->returnCallback(function($dn, $attr) {
if($attr === 'pwdpolicysubentry') {
return array('cn=custom,ou=policies,dc=foo,dc=bar');
}
if($attr === 'pwdchangedtime') {
return array((new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z');
}
if($dn === 'cn=custom,ou=policies,dc=foo,dc=bar' && $attr === 'pwdmaxage') {
return array('2592000');
->method('search')
->will($this->returnCallback(function($filter, $base) {
if($base === 'uid=alice') {
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($dn === 'cn=custom,ou=policies,dc=foo,dc=bar' && $attr === 'pwdexpirewarning') {
return array('2591999');
if($base === 'cn=custom,ou=policies,dc=foo,dc=bar') {
return array(
array(
'pwdmaxage' => array('2592000'),
'pwdexpirewarning' => array('2591999'),
)
);
}
return array();
}));

+ 2
- 0
tests/bootstrap.php 查看文件

@@ -19,3 +19,5 @@ if (!class_exists('PHPUnit_Framework_TestCase')) {
}

OC_Hook::clear();

set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/share/php');

Loading…
取消
儲存