summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-08-20 14:37:41 +0200
committerGitHub <noreply@github.com>2018-08-20 14:37:41 +0200
commit9cf11bd73cd8e35c700149779d9f0d923225acd8 (patch)
treea3b0c74b2bf2cbd86ec88614fb50c33a0c4d323e /apps/user_ldap
parente33670ebcdca2c5234247533069cd82ee1b0638e (diff)
parent2b903aa267a1969edea945538ac778a008ea7955 (diff)
downloadnextcloud-server-9cf11bd73cd8e35c700149779d9f0d923225acd8.tar.gz
nextcloud-server-9cf11bd73cd8e35c700149779d9f0d923225acd8.zip
Merge pull request #10687 from nextcloud/fix/noid/false-positive-change-mention
don't blame randome people for background email updates
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/User_LDAP.php10
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php57
2 files changed, 48 insertions, 19 deletions
diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php
index ca7e0b304ea..11ed02f47ab 100644
--- a/apps/user_ldap/lib/User_LDAP.php
+++ b/apps/user_ldap/lib/User_LDAP.php
@@ -318,11 +318,6 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
$dn = $user->getDN();
//check if user really still exists by reading its entry
if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
- $lcr = $this->access->connection->getConnectionResource();
- if(is_null($lcr)) {
- throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
- }
-
try {
$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
if (!$uuid) {
@@ -330,7 +325,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
}
$newDn = $this->access->getUserDnByUuid($uuid);
//check if renamed user is still valid by reapplying the ldap filter
- if (!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
+ if ($newDn === $dn || !is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
return false;
}
$this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
@@ -376,9 +371,6 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
$result = $this->userExistsOnLDAP($user);
$this->access->connection->writeToCache('userExists'.$uid, $result);
- if($result === true) {
- $user->update();
- }
return $result;
}
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index 447b91decff..693159dc72b 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -515,13 +515,16 @@ class User_LDAPTest extends TestCase {
$this->assertTrue($result);
}
- /**
- * @expectedException \Exception
- */
public function testUserExistsForDeleted() {
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
$this->prepareMockForUserExists();
+ $mapper = $this->createMock(UserMapping::class);
+ $mapper->expects($this->any())
+ ->method('getUUIDByDN')
+ ->with('dnOfFormerUser,dc=test')
+ ->willReturn('45673458748');
+
$this->access->expects($this->any())
->method('readAttribute')
->will($this->returnCallback(function($dn) {
@@ -530,13 +533,24 @@ class User_LDAPTest extends TestCase {
}
return false;
}));
+ $this->access->expects($this->any())
+ ->method('getUserMapper')
+ ->willReturn($mapper);
+ $this->access->expects($this->once())
+ ->method('getUserDnByUuid')
+ ->willThrowException(new \Exception());
+
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getDN')
+ ->willReturn('dnOfFormerUser,dc=test');
$this->userManager->expects($this->atLeastOnce())
->method('get')
- ->willReturn($this->createMock(User::class));
+ ->willReturn($user);
//test for deleted user
- $backend->userExists('formerUser');
+ $this->assertFalse($backend->userExists('formerUser'));
}
public function testUserExistsForNeverExisting() {
@@ -588,14 +602,17 @@ class User_LDAPTest extends TestCase {
$this->assertTrue($result);
}
- /**
- * @expectedException \Exception
- */
public function testUserExistsPublicAPIForDeleted() {
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
$this->prepareMockForUserExists();
\OC_User::useBackend($backend);
+ $mapper = $this->createMock(UserMapping::class);
+ $mapper->expects($this->any())
+ ->method('getUUIDByDN')
+ ->with('dnOfFormerUser,dc=test')
+ ->willReturn('45673458748');
+
$this->access->expects($this->any())
->method('readAttribute')
->will($this->returnCallback(function($dn) {
@@ -604,12 +621,24 @@ class User_LDAPTest extends TestCase {
}
return false;
}));
+ $this->access->expects($this->any())
+ ->method('getUserMapper')
+ ->willReturn($mapper);
+ $this->access->expects($this->once())
+ ->method('getUserDnByUuid')
+ ->willThrowException(new \Exception());
+
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getDN')
+ ->willReturn('dnOfFormerUser,dc=test');
+
$this->userManager->expects($this->atLeastOnce())
->method('get')
- ->willReturn($this->createMock(User::class));
+ ->willReturn($user);
//test for deleted user
- \OC::$server->getUserManager()->userExists('formerUser');
+ $this->assertFalse(\OC::$server->getUserManager()->userExists('formerUser'));
}
public function testUserExistsPublicAPIForNeverExisting() {
@@ -762,6 +791,14 @@ class User_LDAPTest extends TestCase {
return false;
}
}));
+ $this->access->connection->expects($this->any())
+ ->method('getFromCache')
+ ->willReturnCallback(function($key) {
+ if($key === 'userExistsnewyorker') {
+ return true;
+ }
+ return null;
+ });
$user = $this->createMock(User::class);
$user->expects($this->any())