Merge pull request #11978 from nextcloud/bugfix-stable13/9326/make_sure_usermanager_getByEmail_only_returns_IUser

[stable13] filter null values for UserManager::getByEmail
This commit is contained in:
Roeland Jago Douma 2018-10-23 15:14:56 +02:00 committed by GitHub
commit b7524ee49e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -533,8 +533,12 @@ class Manager extends PublicEmitter implements IUserManager {
public function getByEmail($email) {
$userIds = $this->config->getUsersForUserValue('settings', 'email', $email);
return array_map(function($uid) {
$users = array_map(function($uid) {
return $this->get($uid);
}, $userIds);
return array_values(array_filter($users, function($u) {
return ($u instanceof IUser);
}));
}
}

View File

@ -666,4 +666,37 @@ class ManagerTest extends TestCase {
$manager->get('foo')->delete();
$this->assertFalse($manager->userExists('foo'));
}
public function testGetByEmail() {
$config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
$config
->expects($this->at(0))
->method('getUsersForUserValue')
->with('settings', 'email', 'test@example.com')
->will($this->returnValue(['uid1', 'uid99', 'uid2']));
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->at(0))
->method('userExists')
->with($this->equalTo('uid1'))
->will($this->returnValue(true));
$backend->expects($this->at(1))
->method('userExists')
->with($this->equalTo('uid99'))
->will($this->returnValue(false));
$backend->expects($this->at(2))
->method('userExists')
->with($this->equalTo('uid2'))
->will($this->returnValue(true));
$manager = new \OC\User\Manager($config);
$manager->registerBackend($backend);
$users = $manager->getByEmail('test@example.com');
$this->assertCount(2, $users);
$this->assertEquals('uid1', $users[0]->getUID());
$this->assertEquals('uid2', $users[1]->getUID());
}
}