summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-11-24 15:31:52 +0100
committerBjoern Schiessle <schiessle@owncloud.com>2014-12-04 13:18:13 +0100
commit698ecbf308d1eae950138bff9edbb0d542c391d0 (patch)
tree3f6ab525053f56c01f2fcef4792a9756f882ab7d /apps/files_sharing/tests
parentf0e6876f2ec8ec4576ca0ce8bbfee5bd8082dc1f (diff)
downloadnextcloud-server-698ecbf308d1eae950138bff9edbb0d542c391d0.tar.gz
nextcloud-server-698ecbf308d1eae950138bff9edbb0d542c391d0.zip
OCS API for server-to-server sharing
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r--apps/files_sharing/tests/api.php60
-rw-r--r--apps/files_sharing/tests/server2server.php102
2 files changed, 132 insertions, 30 deletions
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index 1259197423b..dd6de15010f 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -76,7 +76,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_POST['shareWith'] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2;
$_POST['shareType'] = \OCP\Share::SHARE_TYPE_USER;
- $result = Share\Api::createShare(array());
+ $result = \OCA\Files_Sharing\API\Local::createShare(array());
$this->assertTrue($result->succeeded());
$data = $result->getData();
@@ -93,7 +93,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_POST['path'] = $this->folder;
$_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
- $result = Share\Api::createShare(array());
+ $result = \OCA\Files_Sharing\API\Local::createShare(array());
// check if API call was successful
$this->assertTrue($result->succeeded());
@@ -129,7 +129,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
- $result = Share\Api::createShare(array());
+ $result = \OCA\Files_Sharing\API\Local::createShare(array());
$this->assertFalse($result->succeeded());
@@ -138,7 +138,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
$_POST['password'] = '';
- $result = Share\Api::createShare(array());
+ $result = \OCA\Files_Sharing\API\Local::createShare(array());
$this->assertFalse($result->succeeded());
// share with password should succeed
@@ -146,7 +146,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
$_POST['password'] = 'foo';
- $result = Share\Api::createShare(array());
+ $result = \OCA\Files_Sharing\API\Local::createShare(array());
$this->assertTrue($result->succeeded());
$data = $result->getData();
@@ -157,7 +157,7 @@ class Test_Files_Sharing_Api extends TestCase {
$params['_put'] = array();
$params['_put']['password'] = 'bar';
- $result = Share\Api::updateShare($params);
+ $result = \OCA\Files_Sharing\API\Local::updateShare($params);
$this->assertTrue($result->succeeded());
// removing password should fail
@@ -166,7 +166,7 @@ class Test_Files_Sharing_Api extends TestCase {
$params['_put'] = array();
$params['_put']['password'] = '';
- $result = Share\Api::updateShare($params);
+ $result = \OCA\Files_Sharing\API\Local::updateShare($params);
$this->assertFalse($result->succeeded());
// cleanup
@@ -187,7 +187,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_POST['shareWith'] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2;
$_POST['shareType'] = \OCP\Share::SHARE_TYPE_USER;
- $result = Share\Api::createShare(array());
+ $result = \OCA\Files_Sharing\API\Local::createShare(array());
$this->assertTrue($result->succeeded());
$data = $result->getData();
@@ -213,7 +213,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_POST['shareWith'] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2;
$_POST['shareType'] = \OCP\Share::SHARE_TYPE_USER;
- $result = Share\Api::createShare(array());
+ $result = \OCA\Files_Sharing\API\Local::createShare(array());
$this->assertTrue($result->succeeded());
$data = $result->getData();
@@ -238,7 +238,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_POST['shareWith'] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2;
$_POST['shareType'] = \OCP\Share::SHARE_TYPE_USER;
- $result = Share\Api::createShare(array());
+ $result = \OCA\Files_Sharing\API\Local::createShare(array());
$this->assertFalse($result->succeeded());
@@ -259,7 +259,7 @@ class Test_Files_Sharing_Api extends TestCase {
\OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
- $result = Share\Api::getAllShares(array());
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result->succeeded());
@@ -286,7 +286,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_GET['path'] = $this->filename;
- $result = Share\Api::getAllShares(array());
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result->succeeded());
@@ -323,7 +323,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_GET['path'] = $this->filename;
- $result = Share\Api::getAllShares(array());
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result->succeeded());
@@ -333,7 +333,7 @@ class Test_Files_Sharing_Api extends TestCase {
// now also ask for the reshares
$_GET['reshares'] = 'true';
- $result = Share\Api::getAllShares(array());
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result->succeeded());
@@ -378,7 +378,7 @@ class Test_Files_Sharing_Api extends TestCase {
// call getShare() with share ID
$params = array('id' => $share['id']);
- $result = Share\Api::getShare($params);
+ $result = \OCA\Files_Sharing\API\Local::getShare($params);
$this->assertTrue($result->succeeded());
@@ -413,7 +413,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_GET['path'] = $this->folder;
$_GET['subfiles'] = 'true';
- $result = Share\Api::getAllShares(array());
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result->succeeded());
@@ -470,7 +470,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_GET['path'] = $value['query'];
$_GET['subfiles'] = 'true';
- $result = Share\Api::getAllShares(array());
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result->succeeded());
@@ -521,7 +521,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_GET['path'] = '/';
$_GET['subfiles'] = 'true';
- $result = Share\Api::getAllShares(array());
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result->succeeded());
@@ -583,7 +583,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_GET['path'] = '/';
$_GET['subfiles'] = 'true';
- $result = Share\Api::getAllShares(array());
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result->succeeded());
@@ -652,7 +652,7 @@ class Test_Files_Sharing_Api extends TestCase {
$expectedPath1 = $this->subfolder;
$_GET['path'] = $expectedPath1;
- $result1 = Share\Api::getAllShares(array());
+ $result1 = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result1->succeeded());
@@ -664,7 +664,7 @@ class Test_Files_Sharing_Api extends TestCase {
$expectedPath2 = $this->folder . $this->subfolder;
$_GET['path'] = $expectedPath2;
- $result2 = Share\Api::getAllShares(array());
+ $result2 = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result2->succeeded());
@@ -734,7 +734,7 @@ class Test_Files_Sharing_Api extends TestCase {
$_GET['path'] = '/';
$_GET['subfiles'] = 'true';
- $result = Share\Api::getAllShares(array());
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
$this->assertTrue($result->succeeded());
@@ -771,7 +771,7 @@ class Test_Files_Sharing_Api extends TestCase {
$params = array('id' => 0);
- $result = Share\Api::getShare($params);
+ $result = \OCA\Files_Sharing\API\Local::getShare($params);
$this->assertEquals(404, $result->getStatusCode());
$meta = $result->getMeta();
@@ -831,7 +831,7 @@ class Test_Files_Sharing_Api extends TestCase {
$params['_put'] = array();
$params['_put']['permissions'] = 1;
- $result = Share\Api::updateShare($params);
+ $result = \OCA\Files_Sharing\API\Local::updateShare($params);
$meta = $result->getMeta();
$this->assertTrue($result->succeeded(), $meta['message']);
@@ -859,7 +859,7 @@ class Test_Files_Sharing_Api extends TestCase {
$params['_put'] = array();
$params['_put']['password'] = 'foo';
- $result = Share\Api::updateShare($params);
+ $result = \OCA\Files_Sharing\API\Local::updateShare($params);
$this->assertTrue($result->succeeded());
@@ -919,7 +919,7 @@ class Test_Files_Sharing_Api extends TestCase {
$params['_put'] = array();
$params['_put']['publicUpload'] = 'true';
- $result = Share\Api::updateShare($params);
+ $result = \OCA\Files_Sharing\API\Local::updateShare($params);
$this->assertTrue($result->succeeded());
@@ -977,7 +977,7 @@ class Test_Files_Sharing_Api extends TestCase {
$params['_put'] = array();
$params['_put']['expireDate'] = $dateWithinRange->format('Y-m-d');
- $result = Share\Api::updateShare($params);
+ $result = \OCA\Files_Sharing\API\Local::updateShare($params);
$this->assertTrue($result->succeeded());
@@ -995,7 +995,7 @@ class Test_Files_Sharing_Api extends TestCase {
$params['_put'] = array();
$params['_put']['expireDate'] = $dateOutOfRange->format('Y-m-d');
- $result = Share\Api::updateShare($params);
+ $result = \OCA\Files_Sharing\API\Local::updateShare($params);
$this->assertFalse($result->succeeded());
@@ -1033,7 +1033,7 @@ class Test_Files_Sharing_Api extends TestCase {
$this->assertEquals(2, count($items));
foreach ($items as $item) {
- $result = Share\Api::deleteShare(array('id' => $item['id']));
+ $result = \OCA\Files_Sharing\API\Local::deleteShare(array('id' => $item['id']));
$this->assertTrue($result->succeeded());
}
@@ -1072,7 +1072,7 @@ class Test_Files_Sharing_Api extends TestCase {
$this->assertEquals(1, count($items));
$item = reset($items);
- $result3 = Share\Api::deleteShare(array('id' => $item['id']));
+ $result3 = \OCA\Files_Sharing\API\Local::deleteShare(array('id' => $item['id']));
$this->assertTrue($result3->succeeded());
diff --git a/apps/files_sharing/tests/server2server.php b/apps/files_sharing/tests/server2server.php
new file mode 100644
index 00000000000..7aec0c4951f
--- /dev/null
+++ b/apps/files_sharing/tests/server2server.php
@@ -0,0 +1,102 @@
+<?php
+/**
+ * ownCloud - test server-to-server OCS API
+ *
+ * @copyright (c) ownCloud, Inc.
+ *
+ * @author Bjoern Schiessle <schiessle@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+use OCA\Files_Sharing\Tests\TestCase;
+
+/**
+ * Class Test_Files_Sharing_Api
+ */
+class Test_Files_Sharing_S2S_OCS_API extends TestCase {
+
+ const TEST_FOLDER_NAME = '/folder_share_api_test';
+
+ private $s2s;
+
+ protected function setUp() {
+ parent::setUp();
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+ \OCP\Share::registerBackend('test', 'Test_Share_Backend');
+
+ $this->s2s = new \OCA\Files_Sharing\API\Server2Server();
+ }
+
+ protected function tearDown() {
+ $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external`');
+ $query->execute();
+
+ parent::tearDown();
+ }
+
+ /**
+ * @medium
+ */
+ function testCreateShare() {
+ // simulate a post request
+ $_POST['remote'] = 'localhost';
+ $_POST['token'] = 'token';
+ $_POST['name'] = 'name';
+ $_POST['owner'] = 'owner';
+ $_POST['shareWith'] = self::TEST_FILES_SHARING_API_USER2;
+ $_POST['remote_id'] = 1;
+
+ $result = $this->s2s->createShare(null);
+
+ $this->assertTrue($result->succeeded());
+
+ $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share_external` WHERE `remote_id` = ?');
+ $result = $query->execute(array('1'));
+ $data = $result->fetchRow();
+
+ $this->assertSame('localhost', $data['remote']);
+ $this->assertSame('token', $data['share_token']);
+ $this->assertSame('/name', $data['name']);
+ $this->assertSame('owner', $data['owner']);
+ $this->assertSame(self::TEST_FILES_SHARING_API_USER2, $data['user']);
+ $this->assertSame(1, (int)$data['remote_id']);
+ $this->assertSame(0, (int)$data['accepted']);
+ }
+
+
+ function testDeclineShare() {
+ $dummy = \OCP\DB::prepare('
+ INSERT INTO `*PREFIX*share`
+ (`share_type`, `uid_owner`, `item_type`, `item_source`, `item_target`, `file_source`, `file_target`, `permissions`, `stime`, `token`)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+ ');
+ $dummy->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, self::TEST_FILES_SHARING_API_USER1, 'test', '1', '/1', '1', '/test.txt', '1', time(), 'token'));
+
+ $verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
+ $result = $verify->execute();
+ $data = $result->fetchAll();
+ $this->assertSame(1, count($data));
+
+ $_POST['token'] = 'token';
+ $this->s2s->declineShare(array('id' => $data[0]['id']));
+
+ $verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
+ $result = $verify->execute();
+ $data = $result->fetchAll();
+ $this->assertEmpty($data);
+ }
+}