// login as first user
self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
+
+ $this->createMocks();
}
protected function tearDown() {
\OC_App::disable('files_trashbin');
}
+ $this->restoreHttpHelper();
+
parent::tearDown();
}
parent::tearDownAfterClass();
}
- /**
- * @medium
- */
- function testDeclineServer2ServerShare() {
-
+ private function createMocks() {
$config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
$certificateManager = $this->getMock('\OCP\ICertificateManager');
$httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper')
->setConstructorArgs(array($config, $certificateManager))
->getMock();
- $httpHelperMock->expects($this->once())->method('post')->with($this->anything())->will($this->returnValue(true));
+ $httpHelperMock->expects($this->any())->method('post')->with($this->anything())->will($this->returnValue(array('success' => true, 'result' => "{'ocs' : { 'meta' : { 'statuscode' : 100 }}}")));
+
+ $this->registerHttpHelper($httpHelperMock);
+ }
+
+ /**
+ * Register an http helper mock for testing purposes.
+ * @param $httpHelper http helper mock
+ */
+ 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;
+ });
+ }
+
+ /**
+ * @medium
+ */
+ function testDeclineServer2ServerShare() {
self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
$share = $query->fetch();
- $this->registerHttpHelper($httpHelperMock);
$_POST['token'] = $token;
$s2s = new \OCA\Files_Sharing\API\Server2Server();
$s2s->declineShare(array('id' => $share['id']));
- $this->restoreHttpHelper();
$this->assertFalse($this->view->file_exists(
'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
}
-
- /**
- * Register an http helper mock for testing purposes.
- * @param $httpHelper http helper mock
- */
- 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;
- });
- }
-
/**
* @medium
* @param bool $withTeardown
}
- function testPublicShareFile() {
+ function testRemoteShareFile() {
+ // login as admin
+ //self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
+
+ // save file with content
+ $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
+
+ // test that data was successfully written
+ $this->assertTrue(is_int($cryptedFile));
+
+ // disable encryption proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+
+ // get the file info from previous created file
+ $fileInfo = $this->view->getFileInfo(
+ '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+
+ // check if we have a valid file info
+ $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
+
+ // check if the unencrypted file size is stored
+ $this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
+
+ // re-enable the file proxy
+ \OC_FileProxy::$enabled = $proxyStatus;
+
+ // share the file
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_REMOTE, 'user1@server1', \OCP\Constants::PERMISSION_ALL);
+
+ $publicShareKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'publicShareKeyId');
+
+ // check if share key for public exists
+ $this->assertTrue($this->view->file_exists(
+ '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
+
+ // unshare the file
+ \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_REMOTE, 'user1@server1');
+
+ // check if share key not exists
+ $this->assertFalse($this->view->file_exists(
+ '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
+
+ // cleanup
+ $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
+
+ // check if share key not exists
+ $this->assertFalse($this->view->file_exists(
+ '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ }
+
+ function testPublicShareFile() {
// login as admin
self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
$shares = $sharePaths = $fileTargets = array();
$publicShare = false;
+ $remoteShare = false;
$source = -1;
$cache = false;
//check for public link shares
if (!$publicShare) {
- $query = \OC_DB::prepare(
- 'SELECT `share_with`
- FROM
- `*PREFIX*share`
- WHERE
- `item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')'
+ $query = \OC_DB::prepare('
+ SELECT `share_with`
+ FROM `*PREFIX*share`
+ WHERE `item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')', 1
);
$result = $query->execute(array($source, self::SHARE_TYPE_LINK));
if (\OCP\DB::isError($result)) {
- \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
} else {
if ($result->fetchRow()) {
$publicShare = true;
}
}
+ //check for remote share
+ if (!$remoteShare) {
+ $query = \OC_DB::prepare('
+ SELECT `share_with`
+ FROM `*PREFIX*share`
+ WHERE `item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')', 1
+ );
+
+ $result = $query->execute(array($source, self::SHARE_TYPE_REMOTE));
+
+ if (\OCP\DB::isError($result)) {
+ \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
+ } else {
+ if ($result->fetchRow()) {
+ $remoteShare = true;
+ }
+ }
+ }
+
// let's get the parent for the next round
$meta = $cache->get((int)$source);
if($meta !== false) {
return $sharePaths;
}
- return array("users" => array_unique($shares), "public" => $publicShare);
+ return array('users' => array_unique($shares), 'public' => $publicShare, 'remote' => $remoteShare);
}
/**
if ($user && $remote) {
$url = $remote . self::BASE_PATH_TO_SHARE_API . '?format=' . self::RESPONSE_FORMAT;
- $local = \OC::$server->getURLGenerator()->getAbsoluteURL('');
+ $local = \OC::$server->getURLGenerator()->getAbsoluteURL('/');
$fields = array(
'shareWith' => $user,