2014-11-24 17:31:52 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-02-26 13:37:37 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
2014-11-24 17:31:52 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2014-11-24 17:31:52 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-11-24 17:31:52 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-11-24 17:31:52 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-11-24 17:31:52 +03:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2016-05-04 12:03:40 +03:00
|
|
|
namespace OCA\FederatedFileSharing\Tests;
|
|
|
|
|
2017-01-27 14:52:17 +03:00
|
|
|
use OC\Federation\CloudIdManager;
|
2016-05-04 12:03:40 +03:00
|
|
|
use OC\Files\Filesystem;
|
|
|
|
use OCA\FederatedFileSharing\DiscoveryManager;
|
2016-05-04 13:16:02 +03:00
|
|
|
use OCA\FederatedFileSharing\FederatedShareProvider;
|
2016-08-19 13:01:13 +03:00
|
|
|
use OCA\FederatedFileSharing\Controller\RequestHandlerController;
|
2017-01-27 14:52:17 +03:00
|
|
|
use OCP\Federation\ICloudIdManager;
|
2016-09-29 01:03:29 +03:00
|
|
|
use OCP\Http\Client\IClient;
|
|
|
|
use OCP\Http\Client\IClientService;
|
|
|
|
use OCP\Http\Client\IResponse;
|
2016-05-04 16:26:30 +03:00
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\Share\IShare;
|
2014-11-24 17:31:52 +03:00
|
|
|
|
|
|
|
/**
|
2016-05-04 12:03:40 +03:00
|
|
|
* Class RequestHandlerTest
|
2015-11-03 03:52:41 +03:00
|
|
|
*
|
2016-05-04 12:03:40 +03:00
|
|
|
* @package OCA\FederatedFileSharing\Tests
|
2015-11-03 03:52:41 +03:00
|
|
|
* @group DB
|
2014-11-24 17:31:52 +03:00
|
|
|
*/
|
2016-08-19 13:01:13 +03:00
|
|
|
class RequestHandlerControllerTest extends TestCase {
|
2014-11-24 17:31:52 +03:00
|
|
|
|
|
|
|
const TEST_FOLDER_NAME = '/folder_share_api_test';
|
|
|
|
|
2015-01-21 02:11:15 +03:00
|
|
|
/**
|
|
|
|
* @var \OCP\IDBConnection
|
|
|
|
*/
|
|
|
|
private $connection;
|
|
|
|
|
|
|
|
/**
|
2016-08-19 13:01:13 +03:00
|
|
|
* @var RequestHandlerController
|
2015-01-21 02:11:15 +03:00
|
|
|
*/
|
2014-11-24 17:31:52 +03:00
|
|
|
private $s2s;
|
|
|
|
|
2016-08-19 13:01:13 +03:00
|
|
|
/** @var \OCA\FederatedFileSharing\FederatedShareProvider|\PHPUnit_Framework_MockObject_MockObject */
|
2016-04-18 19:17:08 +03:00
|
|
|
private $federatedShareProvider;
|
|
|
|
|
2016-08-19 13:01:13 +03:00
|
|
|
/** @var \OCA\FederatedFileSharing\Notifications|\PHPUnit_Framework_MockObject_MockObject */
|
2016-05-04 16:26:30 +03:00
|
|
|
private $notifications;
|
|
|
|
|
2016-08-19 13:01:13 +03:00
|
|
|
/** @var \OCA\FederatedFileSharing\AddressHandler|\PHPUnit_Framework_MockObject_MockObject */
|
2016-05-04 16:26:30 +03:00
|
|
|
private $addressHandler;
|
|
|
|
|
2016-08-19 13:01:13 +03:00
|
|
|
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-05-04 16:26:30 +03:00
|
|
|
private $userManager;
|
|
|
|
|
2016-08-19 13:01:13 +03:00
|
|
|
/** @var IShare|\PHPUnit_Framework_MockObject_MockObject */
|
2016-05-04 16:26:30 +03:00
|
|
|
private $share;
|
|
|
|
|
2017-01-27 14:52:17 +03:00
|
|
|
/** @var ICloudIdManager */
|
|
|
|
private $cloudIdManager;
|
|
|
|
|
2014-11-24 17:31:52 +03:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2016-05-19 11:11:42 +03:00
|
|
|
\OCP\Share::registerBackend('test', 'Test\Share\Backend');
|
2014-11-24 17:31:52 +03:00
|
|
|
|
2014-12-04 21:51:04 +03:00
|
|
|
$config = $this->getMockBuilder('\OCP\IConfig')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2016-08-19 13:01:13 +03:00
|
|
|
$clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')->getMock();
|
2014-12-04 21:51:04 +03:00
|
|
|
$httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper')
|
2015-03-16 13:28:23 +03:00
|
|
|
->setConstructorArgs([$config, $clientService])
|
2014-12-04 21:51:04 +03:00
|
|
|
->getMock();
|
|
|
|
$httpHelperMock->expects($this->any())->method('post')->with($this->anything())->will($this->returnValue(true));
|
2016-08-19 13:01:13 +03:00
|
|
|
$this->share = $this->getMockBuilder('\OCP\Share\IShare')->getMock();
|
2016-04-18 19:17:08 +03:00
|
|
|
$this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$this->federatedShareProvider->expects($this->any())
|
|
|
|
->method('isOutgoingServer2serverShareEnabled')->willReturn(true);
|
|
|
|
$this->federatedShareProvider->expects($this->any())
|
|
|
|
->method('isIncomingServer2serverShareEnabled')->willReturn(true);
|
2016-05-04 16:26:30 +03:00
|
|
|
$this->federatedShareProvider->expects($this->any())->method('getShareById')
|
|
|
|
->willReturn($this->share);
|
2014-12-04 21:51:04 +03:00
|
|
|
|
2016-05-04 16:26:30 +03:00
|
|
|
$this->notifications = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2016-08-19 13:01:13 +03:00
|
|
|
$this->userManager = $this->getMockBuilder('OCP\IUserManager')->getMock();
|
2017-01-27 14:52:17 +03:00
|
|
|
|
|
|
|
$this->cloudIdManager = new CloudIdManager();
|
2016-05-04 16:26:30 +03:00
|
|
|
|
2014-12-04 21:51:04 +03:00
|
|
|
$this->registerHttpHelper($httpHelperMock);
|
|
|
|
|
2016-08-19 13:01:13 +03:00
|
|
|
$this->s2s = new RequestHandlerController(
|
|
|
|
'federatedfilesharing',
|
|
|
|
\OC::$server->getRequest(),
|
2016-05-04 16:26:30 +03:00
|
|
|
$this->federatedShareProvider,
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
\OC::$server->getShareManager(),
|
|
|
|
$this->notifications,
|
|
|
|
$this->addressHandler,
|
2017-01-27 14:52:17 +03:00
|
|
|
$this->userManager,
|
|
|
|
$this->cloudIdManager
|
2016-05-04 16:26:30 +03:00
|
|
|
);
|
2015-01-21 02:11:15 +03:00
|
|
|
|
|
|
|
$this->connection = \OC::$server->getDatabaseConnection();
|
2014-11-24 17:31:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown() {
|
|
|
|
$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external`');
|
|
|
|
$query->execute();
|
|
|
|
|
2016-05-04 16:26:30 +03:00
|
|
|
$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share`');
|
|
|
|
$query->execute();
|
|
|
|
|
2014-12-04 21:51:04 +03:00
|
|
|
$this->restoreHttpHelper();
|
|
|
|
|
2014-11-24 17:31:52 +03:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2014-12-04 21:51:04 +03:00
|
|
|
/**
|
|
|
|
* Register an http helper mock for testing purposes.
|
2016-08-19 13:01:13 +03:00
|
|
|
* @param \OC\HTTPHelper $httpHelper helper mock
|
2014-12-04 21:51:04 +03:00
|
|
|
*/
|
|
|
|
private function registerHttpHelper($httpHelper) {
|
|
|
|
$this->oldHttpHelper = \OC::$server->query('HTTPHelper');
|
|
|
|
\OC::$server->registerService('HTTPHelper', function ($c) use ($httpHelper) {
|
|
|
|
return $httpHelper;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore the original http helper
|
|
|
|
*/
|
|
|
|
private function restoreHttpHelper() {
|
|
|
|
$oldHttpHelper = $this->oldHttpHelper;
|
|
|
|
\OC::$server->registerService('HTTPHelper', function ($c) use ($oldHttpHelper) {
|
|
|
|
return $oldHttpHelper;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-11-24 17:31:52 +03:00
|
|
|
/**
|
|
|
|
* @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;
|
2014-12-04 21:51:04 +03:00
|
|
|
$_POST['remoteId'] = 1;
|
2014-11-24 17:31:52 +03:00
|
|
|
|
2016-08-19 13:01:13 +03:00
|
|
|
$this->s2s->createShare(null);
|
2014-11-24 17:31:52 +03:00
|
|
|
|
|
|
|
$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() {
|
|
|
|
|
2016-08-19 13:01:13 +03:00
|
|
|
$this->s2s = $this->getMockBuilder('\OCA\FederatedFileSharing\Controller\RequestHandlerController')
|
2016-05-04 16:26:30 +03:00
|
|
|
->setConstructorArgs(
|
|
|
|
[
|
2016-08-19 13:01:13 +03:00
|
|
|
'federatedfilessharing',
|
|
|
|
\OC::$server->getRequest(),
|
2016-05-04 16:26:30 +03:00
|
|
|
$this->federatedShareProvider,
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
\OC::$server->getShareManager(),
|
|
|
|
$this->notifications,
|
|
|
|
$this->addressHandler,
|
2017-01-27 14:52:17 +03:00
|
|
|
$this->userManager,
|
|
|
|
$this->cloudIdManager
|
2016-05-04 16:26:30 +03:00
|
|
|
]
|
|
|
|
)->setMethods(['executeDeclineShare', 'verifyShare'])->getMock();
|
|
|
|
|
|
|
|
$this->s2s->expects($this->once())->method('executeDeclineShare');
|
|
|
|
|
|
|
|
$this->s2s->expects($this->any())->method('verifyShare')->willReturn(true);
|
2014-11-24 17:31:52 +03:00
|
|
|
|
|
|
|
$_POST['token'] = 'token';
|
|
|
|
|
2016-08-19 13:01:13 +03:00
|
|
|
$this->s2s->declineShare(42);
|
2016-05-04 16:26:30 +03:00
|
|
|
|
2014-11-24 17:31:52 +03:00
|
|
|
}
|
2015-01-21 02:11:15 +03:00
|
|
|
|
2016-05-04 16:26:30 +03:00
|
|
|
function XtestDeclineShareMultiple() {
|
|
|
|
|
|
|
|
$this->share->expects($this->any())->method('verifyShare')->willReturn(true);
|
|
|
|
|
2016-03-11 16:49:04 +03:00
|
|
|
$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`, `share_with`)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
');
|
|
|
|
$dummy->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, self::TEST_FILES_SHARING_API_USER1, 'test', '1', '/1', '1', '/test.txt', '1', time(), 'token1', 'foo@bar'));
|
|
|
|
$dummy->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, self::TEST_FILES_SHARING_API_USER1, 'test', '1', '/1', '1', '/test.txt', '1', time(), 'token2', 'bar@bar'));
|
|
|
|
|
|
|
|
$verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
|
|
|
|
$result = $verify->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
$this->assertCount(2, $data);
|
|
|
|
|
|
|
|
$_POST['token'] = 'token1';
|
|
|
|
$this->s2s->declineShare(array('id' => $data[0]['id']));
|
|
|
|
|
|
|
|
$verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
|
|
|
|
$result = $verify->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
$this->assertCount(1, $data);
|
|
|
|
$this->assertEquals('bar@bar', $data[0]['share_with']);
|
|
|
|
|
|
|
|
$_POST['token'] = 'token2';
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2015-01-21 02:11:15 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider dataTestDeleteUser
|
|
|
|
*/
|
|
|
|
function testDeleteUser($toDelete, $expected, $remainingUsers) {
|
|
|
|
$this->createDummyS2SShares();
|
|
|
|
|
2016-09-29 01:03:29 +03:00
|
|
|
$httpClientService = $this->createMock(IClientService::class);
|
|
|
|
$client = $this->createMock(IClient::class);
|
|
|
|
$response = $this->createMock(IResponse::class);
|
|
|
|
$client
|
|
|
|
->expects($this->any())
|
|
|
|
->method('get')
|
|
|
|
->willReturn($response);
|
|
|
|
$client
|
|
|
|
->expects($this->any())
|
|
|
|
->method('post')
|
|
|
|
->willReturn($response);
|
|
|
|
$httpClientService
|
|
|
|
->expects($this->any())
|
|
|
|
->method('newClient')
|
|
|
|
->willReturn($client);
|
|
|
|
|
2016-05-04 12:03:40 +03:00
|
|
|
$discoveryManager = new DiscoveryManager(
|
2016-02-25 22:46:01 +03:00
|
|
|
\OC::$server->getMemCacheFactory(),
|
2016-09-29 01:03:29 +03:00
|
|
|
$httpClientService
|
2016-02-25 22:46:01 +03:00
|
|
|
);
|
2016-05-04 12:03:40 +03:00
|
|
|
$manager = new \OCA\Files_Sharing\External\Manager(
|
2015-01-21 02:11:15 +03:00
|
|
|
\OC::$server->getDatabaseConnection(),
|
2016-05-04 12:03:40 +03:00
|
|
|
Filesystem::getMountManager(),
|
|
|
|
Filesystem::getLoader(),
|
2016-09-29 01:03:29 +03:00
|
|
|
$httpClientService,
|
2015-09-01 19:56:09 +03:00
|
|
|
\OC::$server->getNotificationManager(),
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager,
|
2015-01-20 19:00:29 +03:00
|
|
|
$toDelete
|
2016-02-25 22:46:01 +03:00
|
|
|
);
|
2015-01-21 02:11:15 +03:00
|
|
|
|
|
|
|
$manager->removeUserShares($toDelete);
|
|
|
|
|
|
|
|
$query = $this->connection->prepare('SELECT `user` FROM `*PREFIX*share_external`');
|
|
|
|
$query->execute();
|
|
|
|
$result = $query->fetchAll();
|
|
|
|
|
|
|
|
foreach ($result as $r) {
|
|
|
|
$remainingShares[$r['user']] = isset($remainingShares[$r['user']]) ? $remainingShares[$r['user']] + 1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertSame($remainingUsers, count($remainingShares));
|
|
|
|
|
|
|
|
foreach ($expected as $key => $value) {
|
|
|
|
if ($key === $toDelete) {
|
|
|
|
$this->assertArrayNotHasKey($key, $remainingShares);
|
|
|
|
} else {
|
|
|
|
$this->assertSame($value, $remainingShares[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function dataTestDeleteUser() {
|
|
|
|
return array(
|
|
|
|
array('user1', array('user1' => 0, 'user2' => 3, 'user3' => 3), 2),
|
|
|
|
array('user2', array('user1' => 4, 'user2' => 0, 'user3' => 3), 2),
|
|
|
|
array('user3', array('user1' => 4, 'user2' => 3, 'user3' => 0), 2),
|
|
|
|
array('user4', array('user1' => 4, 'user2' => 3, 'user3' => 3), 3),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createDummyS2SShares() {
|
|
|
|
$query = $this->connection->prepare('
|
|
|
|
INSERT INTO `*PREFIX*share_external`
|
|
|
|
(`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `remote_id`, `accepted`)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
');
|
|
|
|
|
|
|
|
$users = array('user1', 'user2', 'user3');
|
|
|
|
|
|
|
|
for ($i = 0; $i < 10; $i++) {
|
|
|
|
$user = $users[$i%3];
|
|
|
|
$query->execute(array('remote', 'token', 'password', 'name', 'owner', $user, 'mount point', $i, $i, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = $this->connection->prepare('SELECT `id` FROM `*PREFIX*share_external`');
|
|
|
|
$query->execute();
|
|
|
|
$dummyEntries = $query->fetchAll();
|
|
|
|
|
|
|
|
$this->assertSame(10, count($dummyEntries));
|
|
|
|
}
|
|
|
|
|
2016-05-04 13:16:02 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider dataTestGetShare
|
|
|
|
*
|
|
|
|
* @param bool $found
|
|
|
|
* @param bool $correctId
|
|
|
|
* @param bool $correctToken
|
|
|
|
*/
|
|
|
|
public function testGetShare($found, $correctId, $correctToken) {
|
|
|
|
|
|
|
|
$connection = \OC::$server->getDatabaseConnection();
|
|
|
|
$query = $connection->getQueryBuilder();
|
|
|
|
$stime = time();
|
|
|
|
$query->insert('share')
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'share_type' => $query->createNamedParameter(FederatedShareProvider::SHARE_TYPE_REMOTE),
|
|
|
|
'uid_owner' => $query->createNamedParameter(self::TEST_FILES_SHARING_API_USER1),
|
|
|
|
'uid_initiator' => $query->createNamedParameter(self::TEST_FILES_SHARING_API_USER2),
|
|
|
|
'item_type' => $query->createNamedParameter('test'),
|
|
|
|
'item_source' => $query->createNamedParameter('1'),
|
|
|
|
'item_target' => $query->createNamedParameter('/1'),
|
|
|
|
'file_source' => $query->createNamedParameter('1'),
|
|
|
|
'file_target' => $query->createNamedParameter('/test.txt'),
|
|
|
|
'permissions' => $query->createNamedParameter('1'),
|
|
|
|
'stime' => $query->createNamedParameter($stime),
|
|
|
|
'token' => $query->createNamedParameter('token'),
|
|
|
|
'share_with' => $query->createNamedParameter('foo@bar'),
|
|
|
|
]
|
|
|
|
)->execute();
|
|
|
|
$id = $query->getLastInsertId();
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'share_type' => (string)FederatedShareProvider::SHARE_TYPE_REMOTE,
|
|
|
|
'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
'item_type' => 'test',
|
|
|
|
'item_source' => '1',
|
|
|
|
'item_target' => '/1',
|
|
|
|
'file_source' => '1',
|
|
|
|
'file_target' => '/test.txt',
|
|
|
|
'permissions' => '1',
|
|
|
|
'stime' => (string)$stime,
|
|
|
|
'token' => 'token',
|
|
|
|
'share_with' => 'foo@bar',
|
|
|
|
'id' => (string)$id,
|
|
|
|
'uid_initiator' => self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
'parent' => null,
|
|
|
|
'accepted' => '0',
|
|
|
|
'expiration' => null,
|
|
|
|
'mail_send' => '0'
|
|
|
|
];
|
|
|
|
|
|
|
|
$searchToken = $correctToken ? 'token' : 'wrongToken';
|
|
|
|
$searchId = $correctId ? $id : -1;
|
|
|
|
|
|
|
|
$result = $this->invokePrivate($this->s2s, 'getShare', [$searchId, $searchToken]);
|
|
|
|
|
|
|
|
if ($found) {
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
} else {
|
|
|
|
$this->assertSame(false, $result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataTestGetShare() {
|
|
|
|
return [
|
|
|
|
[true, true, true],
|
|
|
|
[false, false, true],
|
|
|
|
[false, true, false],
|
|
|
|
[false, false, false],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2014-11-24 17:31:52 +03:00
|
|
|
}
|