summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-01-05 15:52:23 +0100
committerGitHub <noreply@github.com>2017-01-05 15:52:23 +0100
commiteeb5ea85f7a16e37a6a37b0af6d5b94f03ca0d0e (patch)
treef5b79091b68580bb8427445c324d8edaa73cd7f1 /tests
parent64097aece923e03b59aa7bb45b0f2995321346bc (diff)
parent22e74cf5ac65dde9a6154fcc32a89ba7231cb01f (diff)
downloadnextcloud-server-eeb5ea85f7a16e37a6a37b0af6d5b94f03ca0d0e.tar.gz
nextcloud-server-eeb5ea85f7a16e37a6a37b0af6d5b94f03ca0d0e.zip
Merge pull request #2817 from nextcloud/fix-invalid-share-perms
Fix invalid share perms
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Repair/RepairInvalidSharesTest.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/lib/Repair/RepairInvalidSharesTest.php b/tests/lib/Repair/RepairInvalidSharesTest.php
index 1ac42e53bf6..83dbed7d202 100644
--- a/tests/lib/Repair/RepairInvalidSharesTest.php
+++ b/tests/lib/Repair/RepairInvalidSharesTest.php
@@ -278,6 +278,73 @@ class RepairInvalidSharesTest extends TestCase {
$result->closeCursor();
}
+ public function fileSharePermissionsProvider() {
+ return [
+ // unchanged for folder
+ [
+ 'folder',
+ 31,
+ 31,
+ ],
+ // unchanged for read-write + share
+ [
+ 'file',
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE,
+ ],
+ // fixed for all perms
+ [
+ 'file',
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_SHARE,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE,
+ ],
+ ];
+ }
+
+ /**
+ * Test adjusting file share permissions
+ *
+ * @dataProvider fileSharePermissionsProvider
+ */
+ public function testFileSharePermissions($itemType, $testPerms, $expectedPerms) {
+ $qb = $this->connection->getQueryBuilder();
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_LINK),
+ 'uid_owner' => $qb->expr()->literal('user1'),
+ 'item_type' => $qb->expr()->literal($itemType),
+ 'item_source' => $qb->expr()->literal(123),
+ 'item_target' => $qb->expr()->literal('/123'),
+ 'file_source' => $qb->expr()->literal(123),
+ 'file_target' => $qb->expr()->literal('/test'),
+ 'permissions' => $qb->expr()->literal($testPerms),
+ 'stime' => $qb->expr()->literal(time()),
+ ])
+ ->execute();
+
+ $shareId = $this->getLastShareId();
+
+ /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
+ $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->repair->run($outputMock);
+
+ $results = $this->connection->getQueryBuilder()
+ ->select('*')
+ ->from('share')
+ ->orderBy('permissions', 'ASC')
+ ->execute()
+ ->fetchAll();
+
+ $this->assertCount(1, $results);
+
+ $updatedShare = $results[0];
+
+ $this->assertEquals($expectedPerms, $updatedShare['permissions']);
+ }
+
/**
* @return int
*/