From 856164e5782c747f2ead917ecc99b900cc486802 Mon Sep 17 00:00:00 2001 From: Roger Szabo Date: Wed, 2 May 2018 18:17:21 +0800 Subject: [PATCH 1/2] Fix "Invalid argument supplied for foreach()" Signed-off-by: Roger Szabo --- apps/user_ldap/lib/User/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index eb4101ddc25a1..2757892145062 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -617,7 +617,7 @@ public function handlePasswordExpiry($params) { $uid = $params['uid']; if(isset($uid) && $uid === $this->getUsername()) { //retrieve relevant user attributes - $result = $this->access->search('objectclass=*', $this->dn, ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']); + $result = $this->access->search('objectclass=*', array($this->dn), ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']); if(array_key_exists('pwdpolicysubentry', $result[0])) { $pwdPolicySubentry = $result[0]['pwdpolicysubentry']; @@ -634,7 +634,7 @@ public function handlePasswordExpiry($params) { $cacheKey = 'ppolicyAttributes' . $ppolicyDN; $result = $this->connection->getFromCache($cacheKey); if(is_null($result)) { - $result = $this->access->search('objectclass=*', $ppolicyDN, ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']); + $result = $this->access->search('objectclass=*', array($ppolicyDN), ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']); $this->connection->writeToCache($cacheKey, $result); } From ced15ab7567fd3dc72734993609d663e399748b6 Mon Sep 17 00:00:00 2001 From: Roger Szabo Date: Wed, 9 May 2018 20:24:41 +0800 Subject: [PATCH 2/2] adjust unit tests for \"Invalid argument supplied for foreach()\" fix Signed-off-by: Roger Szabo --- apps/user_ldap/tests/User/UserTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php index 27bd7762e39c3..c61a9bd3d4784 100644 --- a/apps/user_ldap/tests/User/UserTest.php +++ b/apps/user_ldap/tests/User/UserTest.php @@ -1132,7 +1132,7 @@ public function testHandlePasswordExpiryWarningDefaultPolicy() { $this->access->expects($this->any()) ->method('search') ->will($this->returnCallback(function($filter, $base) { - if($base === 'uid=alice') { + if($base === array('uid=alice')) { return array( array( 'pwdchangedtime' => array((new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'), @@ -1140,7 +1140,7 @@ public function testHandlePasswordExpiryWarningDefaultPolicy() { ), ); } - if($base === 'cn=default,ou=policies,dc=foo,dc=bar') { + if($base === array('cn=default,ou=policies,dc=foo,dc=bar')) { return array( array( 'pwdmaxage' => array('2592000'), @@ -1202,7 +1202,7 @@ public function testHandlePasswordExpiryWarningCustomPolicy() { $this->access->expects($this->any()) ->method('search') ->will($this->returnCallback(function($filter, $base) { - if($base === 'uid=alice') { + if($base === array('uid=alice')) { return array( array( 'pwdpolicysubentry' => array('cn=custom,ou=policies,dc=foo,dc=bar'), @@ -1211,7 +1211,7 @@ public function testHandlePasswordExpiryWarningCustomPolicy() { ) ); } - if($base === 'cn=custom,ou=policies,dc=foo,dc=bar') { + if($base === array('cn=custom,ou=policies,dc=foo,dc=bar')) { return array( array( 'pwdmaxage' => array('2592000'),