Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix unit tests
Signed-off-by: Arthur Schiwon <[email protected]>

# Conflicts:
#	apps/user_ldap/tests/User_LDAPTest.php
  • Loading branch information
blizzz committed Aug 20, 2018
commit bd31fe7c9b08bd369371f1f00cf32c54e7df9175
58 changes: 47 additions & 11 deletions apps/user_ldap/tests/User_LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,17 @@ public function testUserExists() {
$this->assertTrue($result);
}

/**
* @expectedException \Exception
*/
public function testUserExistsForDeleted() {
$access = $this->getAccessMock();
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
$this->prepareMockForUserExists($access);

$mapper = $this->createMock(UserMapping::class);
$mapper->expects($this->any())
->method('getUUIDByDN')
->with('dnOfFormerUser,dc=test')
->willReturn('45673458748');

$access->expects($this->any())
->method('readAttribute')
->will($this->returnCallback(function($dn) {
Expand All @@ -574,14 +577,25 @@ public function testUserExistsForDeleted() {
}
return false;
}));
$access->expects($this->any())
->method('getUserMapper')
->willReturn($mapper);
$access->expects($this->once())
->method('getUserDnByUuid')
->willThrowException(new \Exception());

$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getDN')
->willReturn('dnOfFormerUser,dc=test');

$access->userManager = $this->createMock(Manager::class);
$access->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() {
Expand Down Expand Up @@ -634,15 +648,18 @@ public function testUserExistsPublicAPI() {
$this->assertTrue($result);
}

/**
* @expectedException \Exception
*/
public function testUserExistsPublicAPIForDeleted() {
$access = $this->getAccessMock();
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);

$mapper = $this->createMock(UserMapping::class);
$mapper->expects($this->any())
->method('getUUIDByDN')
->with('dnOfFormerUser,dc=test')
->willReturn('45673458748');

$access->expects($this->any())
->method('readAttribute')
->will($this->returnCallback(function($dn) {
Expand All @@ -651,13 +668,24 @@ public function testUserExistsPublicAPIForDeleted() {
}
return false;
}));
$access->userManager = $this->createMock(Manager::class);
$access->expects($this->any())
->method('getUserMapper')
->willReturn($mapper);
$access->expects($this->once())
->method('getUserDnByUuid')
->willThrowException(new \Exception());

$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getDN')
->willReturn('dnOfFormerUser,dc=test');

$access->userManager->expects($this->atLeastOnce())
->method('get')
->willReturn($this->createMock(User::class));
->willReturn($user);

//test for deleted user
\OCP\User::userExists('formerUser');
$this->assertFalse(\OC::$server->getUserManager()->userExists('formerUser'));
}

public function testUserExistsPublicAPIForNeverExisting() {
Expand Down Expand Up @@ -818,6 +846,14 @@ public function testGetHomeNoPath() {
return false;
}
}));
$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())
Expand Down