Skip to content

Commit

Permalink
[stable10] fixes #33216 - lookup in group principal backend as well
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 authored and gitmate-bot committed Nov 5, 2018
1 parent f4f25e1 commit ed7218b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 12 additions & 3 deletions apps/dav/lib/Repair/RemoveInvalidShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace OCA\DAV\Repair;

use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\DAV\GroupPrincipalBackend;
use OCP\IDBConnection;
use OCP\ILogger;
use OCP\Migration\IOutput;
Expand All @@ -39,17 +40,22 @@ class RemoveInvalidShares implements IRepairStep {
private $connection;
/** @var Principal */
private $principalBackend;
/** @var GroupPrincipalBackend */
private $groupPrincipalBackend;

/**
* RemoveInvalidShares constructor.
*
* @param IDBConnection $connection
* @param Principal $principalBackend
* @param GroupPrincipalBackend $groupPrincipalBackend
*/
public function __construct(IDBConnection $connection,
Principal $principalBackend) {
Principal $principalBackend,
GroupPrincipalBackend $groupPrincipalBackend) {
$this->connection = $connection;
$this->principalBackend = $principalBackend;
$this->groupPrincipalBackend = $groupPrincipalBackend;
}

/**
Expand Down Expand Up @@ -80,8 +86,11 @@ public function run(IOutput $output) {
$principaluri = $row['principaluri'];
$p = $this->principalBackend->getPrincipalByPath($principaluri);
if ($p === null) {
$output->info(" ... for principal '$principaluri'");
$this->deleteSharesForPrincipal($principaluri);
$p = $this->groupPrincipalBackend->getPrincipalByPath($principaluri);
if ($p === null) {
$output->info(" ... for principal '$principaluri'");
$this->deleteSharesForPrincipal($principaluri);
}
}
}

Expand Down
11 changes: 7 additions & 4 deletions apps/dav/tests/unit/Repair/RemoveInvalidSharesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace OCA\DAV\Tests\Unit\Repair;

use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\DAV\GroupPrincipalBackend;
use OCA\DAV\Repair\RemoveInvalidShares;
use OCP\Migration\IOutput;
use Test\TestCase;
Expand All @@ -45,23 +46,25 @@ public function setUp() {
]);
}

public function test() {
public function test(): void {
$db = \OC::$server->getDatabaseConnection();
/** @var Principal | \PHPUnit_Framework_MockObject_MockObject $principal */
$principal = $this->createMock(Principal::class);
/** @var GroupPrincipalBackend | \PHPUnit_Framework_MockObject_MockObject $groupPrincipal */
$groupPrincipal = $this->createMock(GroupPrincipalBackend::class);

/** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $output */
$output = $this->createMock(IOutput::class);

$repair = new RemoveInvalidShares($db, $principal);
$this->assertEquals("Remove invalid calendar and addressbook shares", $repair->getName());
$repair = new RemoveInvalidShares($db, $principal, $groupPrincipal);
$this->assertEquals('Remove invalid calendar and addressbook shares', $repair->getName());
$repair->run($output);

$query = $db->getQueryBuilder();
$result = $query->select('*')->from('dav_shares')
->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')))->execute();
$data = $result->fetchAll();
$result->closeCursor();
$this->assertEquals(0, \count($data));
$this->assertCount(0, $data);
}
}

0 comments on commit ed7218b

Please sign in to comment.