Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-06-27 13:14:05 +0300
committerGitHub <noreply@github.com>2016-06-27 13:14:05 +0300
commit6e0c40ffd9d33df8a62da46e364df84c49563ed5 (patch)
tree9c29e3242d4ef788eab9d4fcd60b877b0a02ac9a /tests
parentdbd176cfab14791d2373db5d2ecf39759e07aabc (diff)
parent7dc36289ab4df280ea9412932cec403b62aa30a8 (diff)
Merge pull request #25250 from owncloud/linkshare-includedeletewithuploadperms
Add explicit delete permission to link shares
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Repair/RepairInvalidSharesTest.php87
-rw-r--r--tests/lib/Share20/ManagerTest.php18
2 files changed, 87 insertions, 18 deletions
diff --git a/tests/lib/Repair/RepairInvalidSharesTest.php b/tests/lib/Repair/RepairInvalidSharesTest.php
index a1e871bcc80..1ac42e53bf6 100644
--- a/tests/lib/Repair/RepairInvalidSharesTest.php
+++ b/tests/lib/Repair/RepairInvalidSharesTest.php
@@ -124,6 +124,93 @@ class RepairInvalidSharesTest extends TestCase {
}
/**
+ * Test remove expiration date for non-link shares
+ */
+ public function testAddShareLinkDeletePermission() {
+ $oldPerms = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE;
+ $newPerms = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
+
+ // share with old permissions
+ $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('folder'),
+ '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($oldPerms),
+ 'stime' => $qb->expr()->literal(time()),
+ ])
+ ->execute();
+
+ $bogusShareId = $this->getLastShareId();
+
+ // share with read-only permissions
+ $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('folder'),
+ '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(\OCP\Constants::PERMISSION_READ),
+ 'stime' => $qb->expr()->literal(time()),
+ ])
+ ->execute();
+
+ $keepThisShareId = $this->getLastShareId();
+
+ // user share to keep
+ $qb = $this->connection->getQueryBuilder();
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_USER),
+ 'share_with' => $qb->expr()->literal('recipientuser1'),
+ 'uid_owner' => $qb->expr()->literal('user1'),
+ 'item_type' => $qb->expr()->literal('folder'),
+ '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(3),
+ 'stime' => $qb->expr()->literal(time()),
+ ])
+ ->execute();
+
+ $keepThisShareId2 = $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(3, $results);
+
+ $untouchedShare = $results[0];
+ $untouchedShare2 = $results[1];
+ $updatedShare = $results[2];
+ $this->assertEquals($keepThisShareId, $untouchedShare['id'], 'sanity check');
+ $this->assertEquals($keepThisShareId2, $untouchedShare2['id'], 'sanity check');
+ $this->assertEquals($bogusShareId, $updatedShare['id'], 'sanity check');
+ $this->assertEquals($newPerms, $updatedShare['permissions'], 'delete permission was added');
+ }
+
+ /**
* Test remove shares where the parent share does not exist anymore
*/
public function testSharesNonExistingParent() {
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index a50ea6c892a..d2539f8577c 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -1320,24 +1320,6 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Link shares can't have delete permissions
- */
- public function testLinkCreateChecksDeletePermissions() {
- $share = $this->manager->newShare();
-
- $share->setPermissions(\OCP\Constants::PERMISSION_DELETE);
-
- $this->config
- ->method('getAppValue')
- ->will($this->returnValueMap([
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ]));
-
- $this->invokePrivate($this->manager, 'linkCreateChecks', [$share]);
- }
-
- /**
- * @expectedException Exception
* @expectedExceptionMessage Public upload not allowed
*/
public function testLinkCreateChecksNoPublicUpload() {