2013-11-12 13:24:10 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2013-11-12 14:17:34 +04:00
|
|
|
* Copyright (c) 2013 Bjoern Schiessle <schiessle@owncloud.com>
|
2013-11-12 13:24:10 +04:00
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
namespace OCA\Files_Encryption\Tests;
|
2013-11-12 13:24:10 +04:00
|
|
|
|
|
|
|
/**
|
2014-12-03 19:20:04 +03:00
|
|
|
* Class Helper
|
2013-11-12 13:24:10 +04:00
|
|
|
*/
|
2014-12-03 19:20:04 +03:00
|
|
|
class Helper extends TestCase {
|
2013-11-12 13:24:10 +04:00
|
|
|
|
2013-12-19 14:15:59 +04:00
|
|
|
const TEST_ENCRYPTION_HELPER_USER1 = "test-helper-user1";
|
2014-05-22 17:43:42 +04:00
|
|
|
const TEST_ENCRYPTION_HELPER_USER2 = "test-helper-user2";
|
2013-12-19 14:15:59 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
protected function setUpUsers() {
|
2013-12-19 14:15:59 +04:00
|
|
|
// create test user
|
2014-12-03 19:03:11 +03:00
|
|
|
self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER2, true);
|
|
|
|
self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1, true);
|
2013-12-19 14:15:59 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
protected function cleanUpUsers() {
|
2013-12-19 14:15:59 +04:00
|
|
|
// cleanup test user
|
2014-12-03 19:03:11 +03:00
|
|
|
\OC_User::deleteUser(self::TEST_ENCRYPTION_HELPER_USER1);
|
|
|
|
\OC_User::deleteUser(self::TEST_ENCRYPTION_HELPER_USER2);
|
2014-10-10 17:34:19 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
public static function setupHooks() {
|
|
|
|
// Filesystem related hooks
|
2014-12-03 19:20:04 +03:00
|
|
|
\OCA\Files_Encryption\Helper::registerFilesystemHooks();
|
2014-11-06 18:53:35 +03:00
|
|
|
|
|
|
|
// clear and register hooks
|
|
|
|
\OC_FileProxy::clearProxies();
|
2014-12-03 18:52:44 +03:00
|
|
|
\OC_FileProxy::register(new \OCA\Files_Encryption\Proxy());
|
2014-11-06 18:53:35 +03:00
|
|
|
}
|
2014-10-10 17:34:19 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
public static function tearDownAfterClass() {
|
|
|
|
parent::tearDownAfterClass();
|
2013-12-19 14:15:59 +04:00
|
|
|
}
|
|
|
|
|
2013-11-12 13:24:10 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-11-12 19:48:24 +04:00
|
|
|
function testStripPartialFileExtension() {
|
2013-11-12 13:24:10 +04:00
|
|
|
|
|
|
|
$partFilename = 'testfile.txt.part';
|
|
|
|
$filename = 'testfile.txt';
|
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertTrue(\OCA\Files_Encryption\Helper::isPartialFilePath($partFilename));
|
2013-11-12 13:24:10 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertEquals('testfile.txt', \OCA\Files_Encryption\Helper::stripPartialFileExtension($partFilename));
|
2013-11-12 13:24:10 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertFalse(\OCA\Files_Encryption\Helper::isPartialFilePath($filename));
|
2013-11-12 13:24:10 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertEquals('testfile.txt', \OCA\Files_Encryption\Helper::stripPartialFileExtension($filename));
|
2013-11-12 13:24:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-11-12 19:48:24 +04:00
|
|
|
function testStripPartialFileExtensionWithTransferIdPath() {
|
2013-11-12 13:24:10 +04:00
|
|
|
|
|
|
|
$partFilename = 'testfile.txt.ocTransferId643653835.part';
|
|
|
|
$filename = 'testfile.txt';
|
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertTrue(\OCA\Files_Encryption\Helper::isPartialFilePath($partFilename));
|
2013-11-12 13:24:10 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertEquals('testfile.txt', \OCA\Files_Encryption\Helper::stripPartialFileExtension($partFilename));
|
2013-11-12 13:24:10 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertFalse(\OCA\Files_Encryption\Helper::isPartialFilePath($filename));
|
2013-11-12 13:24:10 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertEquals('testfile.txt', \OCA\Files_Encryption\Helper::stripPartialFileExtension($filename));
|
2013-11-12 13:24:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-15 19:49:50 +04:00
|
|
|
function testGetPathToRealFile() {
|
|
|
|
|
|
|
|
// the relative path to /user/files/ that's what we want to get from getPathToRealFile()
|
|
|
|
$relativePath = "foo/bar/test.txt";
|
|
|
|
|
|
|
|
// test paths
|
|
|
|
$versionPath = "/user/files_versions/foo/bar/test.txt.v456756835";
|
|
|
|
$cachePath = "/user/cache/transferid636483/foo/bar/test.txt";
|
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertEquals($relativePath, \OCA\Files_Encryption\Helper::getPathToRealFile($versionPath));
|
|
|
|
$this->assertEquals($relativePath, \OCA\Files_Encryption\Helper::getPathToRealFile($cachePath));
|
2013-11-15 19:49:50 +04:00
|
|
|
}
|
|
|
|
|
2013-12-19 14:15:59 +04:00
|
|
|
function testGetUser() {
|
2014-11-06 18:53:35 +03:00
|
|
|
self::setUpUsers();
|
2013-12-19 14:15:59 +04:00
|
|
|
|
|
|
|
$path1 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/files/foo/bar.txt";
|
|
|
|
$path2 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/cache/foo/bar.txt";
|
2014-05-22 17:43:42 +04:00
|
|
|
$path3 = "/" . self::TEST_ENCRYPTION_HELPER_USER2 . "/thumbnails/foo";
|
2013-12-19 14:15:59 +04:00
|
|
|
$path4 ="/" . "/" . self::TEST_ENCRYPTION_HELPER_USER1;
|
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1);
|
2014-05-22 17:43:42 +04:00
|
|
|
|
2013-12-19 14:15:59 +04:00
|
|
|
// if we are logged-in every path should return the currently logged-in user
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, \OCA\Files_Encryption\Helper::getUser($path3));
|
2013-12-19 14:15:59 +04:00
|
|
|
|
|
|
|
// now log out
|
2014-11-06 18:53:35 +03:00
|
|
|
self::logoutHelper();
|
2013-12-19 14:15:59 +04:00
|
|
|
|
|
|
|
// now we should only get the user from /user/files and user/cache paths
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, \OCA\Files_Encryption\Helper::getUser($path1));
|
|
|
|
$this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, \OCA\Files_Encryption\Helper::getUser($path2));
|
2013-12-19 14:15:59 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertFalse(\OCA\Files_Encryption\Helper::getUser($path3));
|
|
|
|
$this->assertFalse(\OCA\Files_Encryption\Helper::getUser($path4));
|
2013-12-19 14:15:59 +04:00
|
|
|
|
|
|
|
// Log-in again
|
2014-12-03 19:03:11 +03:00
|
|
|
self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1);
|
2014-11-06 18:53:35 +03:00
|
|
|
self::cleanUpUsers();
|
2013-12-19 14:15:59 +04:00
|
|
|
}
|
|
|
|
|
2013-11-15 19:49:50 +04:00
|
|
|
}
|