[Pkg-owncloud-commits] [owncloud] 01/74: dont fail with 500 if configured display name attribute is not set

David Prévot taffit at moszumanska.debian.org
Tue Dec 2 22:04:32 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit fea444b941c0f2c8fadaa819d207a98751de5cb1
Author: Arthur Schiwon <blizzz at owncloud.com>
Date:   Mon Oct 27 15:58:23 2014 +0100

    dont fail with 500 if configured display name attribute is not set
---
 apps/user_ldap/tests/user_ldap.php | 24 ++++++++++++++++++++++--
 apps/user_ldap/user_ldap.php       |  8 +++++++-
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/apps/user_ldap/tests/user_ldap.php b/apps/user_ldap/tests/user_ldap.php
index e51f6cb..c89edc3 100644
--- a/apps/user_ldap/tests/user_ldap.php
+++ b/apps/user_ldap/tests/user_ldap.php
@@ -98,9 +98,10 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
 	/**
 	 * Prepares the Access mock for checkPassword tests
 	 * @param \OCA\user_ldap\lib\Access $access mock
+	 * @param bool noDisplayName
 	 * @return void
 	 */
-	private function prepareAccessForCheckPassword(&$access) {
+	private function prepareAccessForCheckPassword(&$access, $noDisplayName = false) {
 		$access->expects($this->once())
 			   ->method('escapeFilterPart')
 			   ->will($this->returnCallback(function($uid) {
@@ -125,10 +126,14 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
 					return array();
 			   }));
 
+		$retVal = 'gunslinger';
+		if($noDisplayName === true) {
+			$retVal = false;
+		}
 		$access->expects($this->any())
 			   ->method('dn2username')
 			   ->with($this->equalTo('dnOfRoland,dc=test'))
-			   ->will($this->returnValue('gunslinger'));
+			   ->will($this->returnValue($retVal));
 
 		$access->expects($this->any())
 			   ->method('stringResemblesDN')
@@ -178,6 +183,21 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
 		$this->assertFalse($result);
 	}
 
+	public function testCheckPasswordNoDisplayName() {
+		$access = $this->getAccessMock();
+
+		$this->prepareAccessForCheckPassword($access, true);
+		$access->expects($this->once())
+			->method('username2dn')
+			->will($this->returnValue(false));
+
+		$backend = new UserLDAP($access);
+		\OC_User::useBackend($backend);
+
+		$result = $backend->checkPassword('roland', 'dt19');
+		$this->assertFalse($result);
+	}
+
 	public function testCheckPasswordPublicAPI() {
 		$access = $this->getAccessMock();
 		$this->prepareAccessForCheckPassword($access);
diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php
index ae4dfec..6e24431 100644
--- a/apps/user_ldap/user_ldap.php
+++ b/apps/user_ldap/user_ldap.php
@@ -64,8 +64,14 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface {
 			return false;
 		}
 		$dn = $ldap_users[0];
-
 		$user = $this->access->userManager->get($dn);
+		if(is_null($user)) {
+			\OCP\Util::writeLog('user_ldap',
+				'LDAP Login: Could not get user object for DN ' . $dn .
+				'. Maybe the LDAP entry has no set display name attribute?',
+				\OCP\Util::WARN);
+			return false;
+		}
 		if($user->getUsername() !== false) {
 			//are the credentials OK?
 			if(!$this->access->areCredentialsValid($dn, $password)) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list