]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added unit test
authorRoeland Jago Douma <roeland@famdouma.nl>
Thu, 19 Mar 2015 09:47:09 +0000 (10:47 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 19 Mar 2015 09:47:09 +0000 (10:47 +0100)
Tests added to make sure that removing an expire date when this is
enforced is not allowed.

apps/files_sharing/tests/api.php
tests/lib/share/share.php

index 9256f9bcc854d251b5d5b076d8bad1cbcc6e48fd..371c94a8c88925a616a8d64d9f6c971eb49c76b6 100644 (file)
@@ -1079,6 +1079,24 @@ class Test_Files_Sharing_Api extends TestCase {
                $this->assertTrue(is_array($updatedLinkShare));
                $this->assertEquals($dateWithinRange->format('Y-m-d') . ' 00:00:00', $updatedLinkShare['expiration']);
 
+
+               // Try to remove expire date
+               $params = array();
+               $params['id'] = $linkShare['id'];
+               $params['_put'] = ['expireDate' => ''];
+
+               $result = \OCA\Files_Sharing\API\Local::updateShare($params);
+
+               $this->assertFalse($result->succeeded());
+
+               $items = \OCP\Share::getItemShared('file', $linkShare['file_source']);
+
+               $updatedLinkShare = reset($items);
+
+               // date shouldn't be changed
+               $this->assertTrue(is_array($updatedLinkShare));
+               $this->assertEquals($dateWithinRange->format('Y-m-d') . ' 00:00:00', $updatedLinkShare['expiration']);
+
                // cleanup
                $config->setAppValue('core', 'shareapi_default_expire_date', 'no');
                $config->setAppValue('core', 'shareapi_enforce_expire_date', 'no');
index 1ef62dc2b078533cbc6a74251fe764e773b28d85..42bb82968af117304caec7407018199b6d62023f 100644 (file)
@@ -1051,6 +1051,41 @@ class Test_Share extends \Test\TestCase {
                                ),
                );
        }
+
+       /**
+        * Ensure that we do not allow removing a an expiration date from a link share if this
+        * is enforced by the settings.
+        */
+       public function testClearExpireDateWhileEnforced() {
+               OC_User::setUserId($this->user1);
+
+               \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes');
+               \OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2');
+               \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'yes');
+
+               $token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ);
+               $this->assertInternalType(
+                       'string',
+                       $token,
+                       'Failed asserting that user 1 successfully shared text.txt as link with token.'
+               );
+
+               $setExpireDateFailed = false;
+               try {
+                       $this->assertTrue(
+                                       OCP\Share::setExpirationDate('test', 'test.txt', '', ''),
+                                       'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
+                       );
+               } catch (\Exception $e) {
+                       $setExpireDateFailed = true;
+               }
+
+               $this->assertTrue($setExpireDateFailed);
+
+               \OC_Appconfig::deleteKey('core', 'shareapi_default_expire_date');
+               \OC_Appconfig::deleteKey('core', 'shareapi_expire_after_n_days');
+               \OC_Appconfig::deleteKey('core', 'shareapi_enforce_expire_date');
+       }
 }
 
 class DummyShareClass extends \OC\Share\Share {