2012-07-26 01:08:18 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Michael Gapczynski
|
|
|
|
* @copyright 2012 Michael Gapczynski mtgap@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/>.
|
|
|
|
*/
|
|
|
|
|
2013-01-24 19:47:17 +04:00
|
|
|
class Test_Share extends PHPUnit_Framework_TestCase {
|
2012-07-26 01:08:18 +04:00
|
|
|
|
|
|
|
protected $itemType;
|
|
|
|
protected $userBackend;
|
|
|
|
protected $user1;
|
|
|
|
protected $user2;
|
|
|
|
protected $groupBackend;
|
|
|
|
protected $group1;
|
|
|
|
protected $group2;
|
2013-02-26 22:31:15 +04:00
|
|
|
protected $resharing;
|
2013-09-13 01:37:43 +04:00
|
|
|
protected $dateInFuture;
|
|
|
|
protected $dateInPast;
|
2013-09-05 04:27:29 +04:00
|
|
|
|
2012-07-26 01:08:18 +04:00
|
|
|
public function setUp() {
|
|
|
|
OC_User::clearBackends();
|
|
|
|
OC_User::useBackend('dummy');
|
2012-10-13 22:20:10 +04:00
|
|
|
$this->user1 = uniqid('user1_');
|
|
|
|
$this->user2 = uniqid('user2_');
|
|
|
|
$this->user3 = uniqid('user3_');
|
|
|
|
$this->user4 = uniqid('user4_');
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::createUser($this->user1, 'pass');
|
|
|
|
OC_User::createUser($this->user2, 'pass');
|
|
|
|
OC_User::createUser($this->user3, 'pass');
|
2012-08-20 00:30:38 +04:00
|
|
|
OC_User::createUser($this->user4, 'pass');
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user1);
|
2012-07-26 01:08:18 +04:00
|
|
|
OC_Group::clearBackends();
|
|
|
|
OC_Group::useBackend(new OC_Group_Dummy);
|
|
|
|
$this->group1 = uniqid('group_');
|
|
|
|
$this->group2 = uniqid('group_');
|
|
|
|
OC_Group::createGroup($this->group1);
|
|
|
|
OC_Group::createGroup($this->group2);
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_Group::addToGroup($this->user1, $this->group1);
|
|
|
|
OC_Group::addToGroup($this->user2, $this->group1);
|
|
|
|
OC_Group::addToGroup($this->user3, $this->group1);
|
2012-08-20 00:30:38 +04:00
|
|
|
OC_Group::addToGroup($this->user2, $this->group2);
|
|
|
|
OC_Group::addToGroup($this->user4, $this->group2);
|
2012-08-15 19:55:54 +04:00
|
|
|
OCP\Share::registerBackend('test', 'Test_Share_Backend');
|
2012-11-14 02:45:17 +04:00
|
|
|
OC_Hook::clear('OCP\\Share');
|
2012-11-15 21:13:54 +04:00
|
|
|
OC::registerShareHooks();
|
2013-02-26 22:31:15 +04:00
|
|
|
$this->resharing = OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes');
|
|
|
|
OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes');
|
2013-09-13 01:37:43 +04:00
|
|
|
|
|
|
|
// 20 Minutes in the past, 20 minutes in the future.
|
|
|
|
$now = time();
|
|
|
|
$dateFormat = 'Y-m-d H:i:s';
|
|
|
|
$this->dateInPast = date($dateFormat, $now - 20 * 60);
|
|
|
|
$this->dateInFuture = date($dateFormat, $now + 20 * 60);
|
2012-07-26 01:08:18 +04:00
|
|
|
}
|
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
public function tearDown() {
|
2012-08-25 03:52:27 +04:00
|
|
|
$query = OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `item_type` = ?');
|
2012-08-15 19:55:54 +04:00
|
|
|
$query->execute(array('test'));
|
2013-02-26 22:31:15 +04:00
|
|
|
OC_Appconfig::setValue('core', 'shareapi_allow_resharing', $this->resharing);
|
2012-07-26 01:08:18 +04:00
|
|
|
}
|
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
public function testShareInvalidShareType() {
|
2012-10-12 21:28:24 +04:00
|
|
|
$message = 'Share type foobar is not valid for test.txt';
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', 'foobar', $this->user2, OCP\PERMISSION_READ);
|
2012-10-12 21:28:24 +04:00
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-10-12 21:28:24 +04:00
|
|
|
}
|
2012-07-26 01:08:18 +04:00
|
|
|
}
|
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
public function testInvalidItemType() {
|
|
|
|
$message = 'Sharing backend for foobar not found';
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
OCP\Share::getItemsSharedWith('foobar');
|
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
OCP\Share::getItemSharedWith('foobar', 'test.txt');
|
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
OCP\Share::getItemSharedWithBySource('foobar', 'test.txt');
|
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
OCP\Share::getItemShared('foobar', 'test.txt');
|
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
OCP\Share::unshare('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2);
|
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::setPermissions('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_UPDATE);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-07-26 01:08:18 +04:00
|
|
|
}
|
|
|
|
|
2013-09-05 04:45:52 +04:00
|
|
|
protected function shareUserOneTestFileWithUserTwo() {
|
2013-09-05 04:31:54 +04:00
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(
|
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ),
|
|
|
|
'Failed asserting that user 1 successfully shared text.txt with user 2.'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('test.txt'),
|
|
|
|
OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that test.txt is a shared file of user 1.'
|
|
|
|
);
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('test.txt'),
|
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that user 2 has access to test.txt after initial sharing.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
public function testShareWithUser() {
|
|
|
|
// Invalid shares
|
|
|
|
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner';
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\PERMISSION_READ);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
|
|
|
$message = 'Sharing test.txt failed, because the user foobar does not exist';
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, 'foobar', OCP\PERMISSION_READ);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-08-20 00:30:38 +04:00
|
|
|
$message = 'Sharing foobar failed, because the sharing backend for test could not find its source';
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ);
|
2012-08-20 00:30:38 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-20 00:30:38 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Valid share
|
2013-09-05 04:31:54 +04:00
|
|
|
$this->shareUserOneTestFileWithUserTwo();
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Attempt to share again
|
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$message = 'Sharing test.txt failed, because this item is already shared with '.$this->user2;
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Attempt to share back
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer';
|
2012-08-15 19:55:54 +04:00
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\PERMISSION_READ);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Unshare
|
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Attempt reshare without share permission
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$message = 'Sharing test.txt failed, because resharing is not allowed';
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-11-05 01:16:04 +04:00
|
|
|
// Owner grants share and update permission
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user1);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_SHARE));
|
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Attempt reshare with escalated permissions
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$message = 'Sharing test.txt failed, because the permissions exceed permissions granted to '.$this->user2;
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ | OCP\PERMISSION_DELETE);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Valid reshare
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE));
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user3);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE));
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
|
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Attempt to escalate permissions
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$message = 'Setting permissions for test.txt failed, because the permissions exceed permissions granted to '.$this->user2;
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ | OCP\PERMISSION_DELETE);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Remove update permission
|
|
|
|
OC_User::setUserId($this->user1);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_SHARE));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user2);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_SHARE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user3);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertEquals(array(OCP\PERMISSION_READ), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
|
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Remove share permission
|
|
|
|
OC_User::setUserId($this->user1);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user2);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertEquals(array(OCP\PERMISSION_READ), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user3);
|
|
|
|
$this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt'));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Reshare again, and then have owner unshare
|
|
|
|
OC_User::setUserId($this->user1);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_SHARE));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user2);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2));
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt'));
|
|
|
|
OC_User::setUserId($this->user3);
|
|
|
|
$this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt'));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Attempt target conflict
|
|
|
|
OC_User::setUserId($this->user1);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user3);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ));
|
2012-08-28 02:12:01 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user2);
|
2012-08-28 02:12:01 +04:00
|
|
|
$to_test = OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(2, count($to_test));
|
2012-08-28 02:12:01 +04:00
|
|
|
$this->assertTrue(in_array('test.txt', $to_test));
|
|
|
|
$this->assertTrue(in_array('test1.txt', $to_test));
|
2012-08-22 19:35:30 +04:00
|
|
|
|
2012-08-16 20:20:14 +04:00
|
|
|
// Remove user
|
2012-09-09 04:15:35 +04:00
|
|
|
OC_User::setUserId($this->user1);
|
2012-08-20 00:30:38 +04:00
|
|
|
OC_User::deleteUser($this->user1);
|
|
|
|
OC_User::setUserId($this->user2);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-07-26 01:08:18 +04:00
|
|
|
|
2013-09-05 04:45:52 +04:00
|
|
|
public function testShareWithUserExpirationExpired() {
|
2013-09-04 19:26:30 +04:00
|
|
|
$this->shareUserOneTestFileWithUserTwo();
|
|
|
|
|
2013-09-04 19:15:08 +04:00
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(
|
2013-09-05 04:27:29 +04:00
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast),
|
2013-09-04 19:26:30 +04:00
|
|
|
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
|
2013-09-04 19:15:08 +04:00
|
|
|
);
|
2013-09-04 19:26:30 +04:00
|
|
|
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$this->assertFalse(
|
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that user 2 no longer has access to test.txt after expiration.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-09-05 04:45:52 +04:00
|
|
|
public function testShareWithUserExpirationValid() {
|
2013-09-04 19:26:30 +04:00
|
|
|
$this->shareUserOneTestFileWithUserTwo();
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(
|
2013-09-05 04:27:29 +04:00
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture),
|
2013-09-04 19:26:30 +04:00
|
|
|
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
|
2013-09-04 19:15:08 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('test.txt'),
|
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
2013-09-04 19:26:30 +04:00
|
|
|
'Failed asserting that user 2 still has access to test.txt after expiration date has been set.'
|
2013-09-04 19:15:08 +04:00
|
|
|
);
|
2013-09-04 19:26:30 +04:00
|
|
|
}
|
2013-09-04 19:15:08 +04:00
|
|
|
|
2013-09-05 04:45:52 +04:00
|
|
|
protected function shareUserOneTestFileWithGroupOne() {
|
2013-09-05 04:41:24 +04:00
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(
|
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ),
|
|
|
|
'Failed asserting that user 1 successfully shared text.txt with group 1.'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('test.txt'),
|
|
|
|
OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that test.txt is a shared file of user 1.'
|
|
|
|
);
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('test.txt'),
|
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that user 2 has access to test.txt after initial sharing.'
|
|
|
|
);
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user3);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('test.txt'),
|
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that user 3 has access to test.txt after initial sharing.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
public function testShareWithGroup() {
|
|
|
|
// Invalid shares
|
|
|
|
$message = 'Sharing test.txt failed, because the group foobar does not exist';
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, 'foobar', OCP\PERMISSION_READ);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-10-10 01:16:59 +04:00
|
|
|
$policy = OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global');
|
|
|
|
OC_Appconfig::setValue('core', 'shareapi_share_policy', 'groups_only');
|
2012-08-15 19:55:54 +04:00
|
|
|
$message = 'Sharing test.txt failed, because '.$this->user1.' is not a member of the group '.$this->group2;
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group2, OCP\PERMISSION_READ);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-10-10 01:16:59 +04:00
|
|
|
OC_Appconfig::setValue('core', 'shareapi_share_policy', $policy);
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Valid share
|
2013-09-05 04:41:24 +04:00
|
|
|
$this->shareUserOneTestFileWithGroupOne();
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Attempt to share again
|
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1;
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-15 19:55:54 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Attempt to share back to owner of group share
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer';
|
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\PERMISSION_READ);
|
2012-08-20 00:30:38 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-20 00:30:38 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Attempt to share back to group
|
2012-08-22 19:35:30 +04:00
|
|
|
$message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1;
|
2012-08-20 00:30:38 +04:00
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ);
|
2012-08-20 00:30:38 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-20 00:30:38 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Attempt to share back to member of group
|
2012-08-22 19:35:30 +04:00
|
|
|
$message ='Sharing test.txt failed, because this item is already shared with '.$this->user3;
|
2012-08-20 00:30:38 +04:00
|
|
|
try {
|
2012-11-11 22:58:54 +04:00
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ);
|
2012-08-20 00:30:38 +04:00
|
|
|
$this->fail('Exception was expected: '.$message);
|
|
|
|
} catch (Exception $exception) {
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals($message, $exception->getMessage());
|
2012-08-20 00:30:38 +04:00
|
|
|
}
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-15 19:55:54 +04:00
|
|
|
// Unshare
|
2012-08-20 00:30:38 +04:00
|
|
|
OC_User::setUserId($this->user1);
|
2012-08-15 19:55:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Valid share with same person - user then group
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_DELETE | OCP\PERMISSION_SHARE));
|
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user2);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE | OCP\PERMISSION_SHARE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
|
2012-08-15 19:55:54 +04:00
|
|
|
OC_User::setUserId($this->user3);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
|
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Valid reshare
|
|
|
|
OC_User::setUserId($this->user2);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\PERMISSION_READ));
|
2012-08-20 00:30:38 +04:00
|
|
|
OC_User::setUserId($this->user4);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Unshare from user only
|
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2));
|
|
|
|
OC_User::setUserId($this->user2);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
|
2012-08-20 00:30:38 +04:00
|
|
|
OC_User::setUserId($this->user4);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Valid share with same person - group then user
|
|
|
|
OC_User::setUserId($this->user1);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_DELETE));
|
2012-08-20 00:30:38 +04:00
|
|
|
OC_User::setUserId($this->user2);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
|
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Unshare from group only
|
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1));
|
|
|
|
OC_User::setUserId($this->user2);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_DELETE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
|
|
|
|
|
2012-08-20 00:30:38 +04:00
|
|
|
// Attempt user specific target conflict
|
|
|
|
OC_User::setUserId($this->user3);
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ | OCP\PERMISSION_SHARE));
|
2012-08-20 00:30:38 +04:00
|
|
|
OC_User::setUserId($this->user2);
|
2012-08-28 02:35:10 +04:00
|
|
|
$to_test = OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(2, count($to_test));
|
2012-08-28 02:35:10 +04:00
|
|
|
$this->assertTrue(in_array('test.txt', $to_test));
|
|
|
|
$this->assertTrue(in_array('test1.txt', $to_test));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-11-05 01:16:04 +04:00
|
|
|
// Valid reshare
|
2012-11-11 22:58:54 +04:00
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\PERMISSION_READ | OCP\PERMISSION_SHARE));
|
2012-09-03 02:23:09 +04:00
|
|
|
OC_User::setUserId($this->user4);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-09-03 02:23:09 +04:00
|
|
|
// Remove user from group
|
|
|
|
OC_Group::removeFromGroup($this->user2, $this->group1);
|
|
|
|
OC_User::setUserId($this->user2);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-09-03 02:23:09 +04:00
|
|
|
OC_User::setUserId($this->user4);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-16 20:20:14 +04:00
|
|
|
// Add user to group
|
2012-09-03 02:23:09 +04:00
|
|
|
OC_Group::addToGroup($this->user4, $this->group1);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-09-09 04:15:35 +04:00
|
|
|
// Unshare from self
|
|
|
|
$this->assertTrue(OCP\Share::unshareFromSelf('test', 'test.txt'));
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-09-09 04:15:35 +04:00
|
|
|
OC_User::setUserId($this->user2);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-11-11 22:58:54 +04:00
|
|
|
|
2012-08-16 20:20:14 +04:00
|
|
|
// Remove group
|
2012-09-03 04:01:09 +04:00
|
|
|
OC_Group::deleteGroup($this->group1);
|
2012-09-09 04:15:35 +04:00
|
|
|
OC_User::setUserId($this->user4);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
|
2012-09-03 04:01:09 +04:00
|
|
|
OC_User::setUserId($this->user3);
|
2012-10-12 22:05:45 +04:00
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsShared('test'));
|
2012-07-26 01:08:18 +04:00
|
|
|
}
|
|
|
|
|
2013-09-05 04:45:52 +04:00
|
|
|
public function testShareWithGroupExpirationExpired() {
|
2013-09-05 04:41:24 +04:00
|
|
|
$this->shareUserOneTestFileWithGroupOne();
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(
|
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast),
|
|
|
|
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
|
|
|
|
);
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$this->assertFalse(
|
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that user 2 no longer has access to test.txt after expiration.'
|
|
|
|
);
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user3);
|
|
|
|
$this->assertFalse(
|
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that user 3 no longer has access to test.txt after expiration.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-09-05 04:45:52 +04:00
|
|
|
public function testShareWithGroupExpirationValid() {
|
2013-09-05 04:41:24 +04:00
|
|
|
$this->shareUserOneTestFileWithGroupOne();
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$this->assertTrue(
|
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture),
|
|
|
|
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
|
|
|
|
);
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user2);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('test.txt'),
|
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that user 2 still has access to test.txt after expiration date has been set.'
|
|
|
|
);
|
|
|
|
|
|
|
|
OC_User::setUserId($this->user3);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('test.txt'),
|
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
|
|
|
|
'Failed asserting that user 3 still has access to test.txt after expiration date has been set.'
|
|
|
|
);
|
|
|
|
}
|
2013-09-14 19:56:55 +04:00
|
|
|
|
|
|
|
protected function getShareByValidToken($token) {
|
|
|
|
$row = OCP\Share::getShareByToken($token);
|
|
|
|
$this->assertInternalType(
|
|
|
|
'array',
|
|
|
|
$row,
|
|
|
|
"Failed asserting that a share for token $token exists."
|
|
|
|
);
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testShareItemWithLink() {
|
|
|
|
OC_User::setUserId($this->user1);
|
|
|
|
$token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, OCP\PERMISSION_READ);
|
|
|
|
$this->assertInternalType(
|
|
|
|
'string',
|
|
|
|
$token,
|
|
|
|
'Failed asserting that user 1 successfully shared text.txt as link with token.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// testGetShareByTokenNoExpiration
|
|
|
|
$row = $this->getShareByValidToken($token);
|
|
|
|
$this->assertEmpty(
|
|
|
|
$row['expiration'],
|
|
|
|
'Failed asserting that the returned row does not have an expiration date.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// testGetShareByTokenExpirationValid
|
|
|
|
$this->assertTrue(
|
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture),
|
|
|
|
'Failed asserting that user 1 successfully set a future expiration date for the test.txt share.'
|
|
|
|
);
|
|
|
|
$row = $this->getShareByValidToken($token);
|
|
|
|
$this->assertNotEmpty(
|
|
|
|
$row['expiration'],
|
|
|
|
'Failed asserting that the returned row has an expiration date.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// testGetShareByTokenExpirationExpired
|
|
|
|
$this->assertTrue(
|
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast),
|
|
|
|
'Failed asserting that user 1 successfully set a past expiration date for the test.txt share.'
|
|
|
|
);
|
|
|
|
$this->assertFalse(
|
|
|
|
OCP\Share::getShareByToken($token),
|
|
|
|
'Failed asserting that an expired share could not be found.'
|
|
|
|
);
|
|
|
|
}
|
2012-07-26 01:08:18 +04:00
|
|
|
}
|