2013-11-12 09:24:10 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2013-11-12 10:17:34 +00:00
|
|
|
* Copyright (c) 2013 Bjoern Schiessle <schiessle@owncloud.com>
|
2013-11-12 09:24:10 +00:00
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2013-11-12 10:17:34 +00:00
|
|
|
|
2013-11-12 09:24:10 +00:00
|
|
|
require_once __DIR__ . '/../lib/helper.php';
|
2013-12-19 10:15:59 +00:00
|
|
|
require_once __DIR__ . '/util.php';
|
2013-11-12 09:24:10 +00:00
|
|
|
|
|
|
|
use OCA\Encryption;
|
|
|
|
|
|
|
|
/**
|
2013-11-12 10:17:34 +00:00
|
|
|
* Class Test_Encryption_Helper
|
2013-11-12 09:24:10 +00:00
|
|
|
*/
|
|
|
|
class Test_Encryption_Helper extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
2013-12-19 10:15:59 +00:00
|
|
|
const TEST_ENCRYPTION_HELPER_USER1 = "test-helper-user1";
|
|
|
|
|
|
|
|
public static function setUpBeforeClass() {
|
|
|
|
// create test user
|
|
|
|
\Test_Encryption_Util::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function tearDownAfterClass() {
|
|
|
|
// cleanup test user
|
|
|
|
\OC_User::deleteUser(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1);
|
|
|
|
}
|
|
|
|
|
2013-11-12 09:24:10 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-11-12 15:48:24 +00:00
|
|
|
function testStripPartialFileExtension() {
|
2013-11-12 09:24:10 +00:00
|
|
|
|
|
|
|
$partFilename = 'testfile.txt.part';
|
|
|
|
$filename = 'testfile.txt';
|
|
|
|
|
2013-11-12 10:17:34 +00:00
|
|
|
$this->assertTrue(Encryption\Helper::isPartialFilePath($partFilename));
|
2013-11-12 09:24:10 +00:00
|
|
|
|
2013-11-12 15:48:24 +00:00
|
|
|
$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($partFilename));
|
2013-11-12 09:24:10 +00:00
|
|
|
|
2013-11-12 10:17:34 +00:00
|
|
|
$this->assertFalse(Encryption\Helper::isPartialFilePath($filename));
|
2013-11-12 09:24:10 +00:00
|
|
|
|
2013-11-12 15:48:24 +00:00
|
|
|
$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename));
|
2013-11-12 09:24:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-11-12 15:48:24 +00:00
|
|
|
function testStripPartialFileExtensionWithTransferIdPath() {
|
2013-11-12 09:24:10 +00:00
|
|
|
|
|
|
|
$partFilename = 'testfile.txt.ocTransferId643653835.part';
|
|
|
|
$filename = 'testfile.txt';
|
|
|
|
|
|
|
|
$this->assertTrue(Encryption\Helper::isPartialFilePath($partFilename));
|
|
|
|
|
2013-11-12 15:48:24 +00:00
|
|
|
$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($partFilename));
|
2013-11-12 09:24:10 +00:00
|
|
|
|
|
|
|
$this->assertFalse(Encryption\Helper::isPartialFilePath($filename));
|
|
|
|
|
2013-11-12 15:48:24 +00:00
|
|
|
$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename));
|
2013-11-12 09:24:10 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 15:49:50 +00: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";
|
|
|
|
|
|
|
|
$this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($versionPath));
|
|
|
|
$this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($cachePath));
|
|
|
|
}
|
|
|
|
|
2013-12-19 10:15:59 +00:00
|
|
|
function testGetUser() {
|
|
|
|
|
|
|
|
$path1 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/files/foo/bar.txt";
|
|
|
|
$path2 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/cache/foo/bar.txt";
|
|
|
|
$path3 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/thumbnails/foo";
|
|
|
|
$path4 ="/" . "/" . self::TEST_ENCRYPTION_HELPER_USER1;
|
|
|
|
|
|
|
|
// if we are logged-in every path should return the currently logged-in user
|
|
|
|
$this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path3));
|
|
|
|
|
|
|
|
// now log out
|
|
|
|
\Test_Encryption_Util::logoutHelper();
|
|
|
|
|
|
|
|
// now we should only get the user from /user/files and user/cache paths
|
|
|
|
$this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path1));
|
|
|
|
$this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path2));
|
|
|
|
|
|
|
|
$this->assertFalse(Encryption\Helper::getUser($path3));
|
|
|
|
$this->assertFalse(Encryption\Helper::getUser($path4));
|
|
|
|
|
|
|
|
// Log-in again
|
|
|
|
\Test_Encryption_Util::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1);
|
|
|
|
}
|
|
|
|
|
2013-11-15 15:49:50 +00:00
|
|
|
}
|