fixing tests for the new part file handling
This commit is contained in:
parent
802213f7ec
commit
9f10f15fd4
|
@ -156,6 +156,22 @@ class Helper {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if a path is a .part file
|
||||||
|
* @param string $path Path that may identify a .part file
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isPartialFilePath($path) {
|
||||||
|
|
||||||
|
$extension = pathinfo($path, PATHINFO_EXTENSION);
|
||||||
|
if ( $extension === 'part' || $extension === 'etmp') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove .path extension from a file path
|
* @brief Remove .path extension from a file path
|
||||||
|
|
|
@ -152,10 +152,10 @@ class Keymanager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// try reusing key file if part file
|
// try reusing key file if part file
|
||||||
if (self::isPartialFilePath($targetPath)) {
|
if (Helper::isPartialFilePath($targetPath)) {
|
||||||
|
|
||||||
$result = $view->file_put_contents(
|
$result = $view->file_put_contents(
|
||||||
$basePath . '/' . \OCA\Encryption\Helper::fixPartialFilePath($targetPath) . '.key', $catfile);
|
$basePath . '/' . Helper::fixPartialFilePath($targetPath) . '.key', $catfile);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -169,22 +169,6 @@ class Keymanager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if a path is a .part file
|
|
||||||
* @param string $path Path that may identify a .part file
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function isPartialFilePath($path) {
|
|
||||||
|
|
||||||
$extension = pathinfo($path, PATHINFO_EXTENSION);
|
|
||||||
if ( $extension === 'part' || $extension === 'etmp') {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief retrieve keyfile for an encrypted file
|
* @brief retrieve keyfile for an encrypted file
|
||||||
* @param \OC_FilesystemView $view
|
* @param \OC_FilesystemView $view
|
||||||
|
@ -200,7 +184,7 @@ class Keymanager {
|
||||||
$util = new Util($view, \OCP\User::getUser());
|
$util = new Util($view, \OCP\User::getUser());
|
||||||
|
|
||||||
list($owner, $filename) = $util->getUidAndFilename($filePath);
|
list($owner, $filename) = $util->getUidAndFilename($filePath);
|
||||||
$filename = \OCA\Encryption\Helper::fixPartialFilePath($filename);
|
$filename = Helper::fixPartialFilePath($filename);
|
||||||
$filePath_f = ltrim($filename, '/');
|
$filePath_f = ltrim($filename, '/');
|
||||||
|
|
||||||
// in case of system wide mount points the keys are stored directly in the data directory
|
// in case of system wide mount points the keys are stored directly in the data directory
|
||||||
|
@ -359,8 +343,8 @@ class Keymanager {
|
||||||
foreach ($shareKeys as $userId => $shareKey) {
|
foreach ($shareKeys as $userId => $shareKey) {
|
||||||
|
|
||||||
// try reusing key file if part file
|
// try reusing key file if part file
|
||||||
if (self::isPartialFilePath($shareKeyPath)) {
|
if (Helper::isPartialFilePath($shareKeyPath)) {
|
||||||
$writePath = $basePath . '/' . \OCA\Encryption\Helper::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey';
|
$writePath = $basePath . '/' . Helper::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey';
|
||||||
} else {
|
} else {
|
||||||
$writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';
|
$writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';
|
||||||
}
|
}
|
||||||
|
@ -396,7 +380,7 @@ class Keymanager {
|
||||||
$util = new Util($view, \OCP\User::getUser());
|
$util = new Util($view, \OCP\User::getUser());
|
||||||
|
|
||||||
list($owner, $filename) = $util->getUidAndFilename($filePath);
|
list($owner, $filename) = $util->getUidAndFilename($filePath);
|
||||||
$filename = \OCA\Encryption\Helper::fixPartialFilePath($filename);
|
$filename = Helper::fixPartialFilePath($filename);
|
||||||
// in case of system wide mount points the keys are stored directly in the data directory
|
// in case of system wide mount points the keys are stored directly in the data directory
|
||||||
if ($util->isSystemWideMountPoint($filename)) {
|
if ($util->isSystemWideMountPoint($filename)) {
|
||||||
$shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey';
|
$shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey';
|
||||||
|
|
|
@ -342,7 +342,7 @@ class Proxy extends \OC_FileProxy {
|
||||||
|
|
||||||
$fileInfo = false;
|
$fileInfo = false;
|
||||||
// get file info from database/cache if not .part file
|
// get file info from database/cache if not .part file
|
||||||
if (!Keymanager::isPartialFilePath($path)) {
|
if (!Helper::isPartialFilePath($path)) {
|
||||||
$fileInfo = $view->getFileInfo($path);
|
$fileInfo = $view->getFileInfo($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ class Proxy extends \OC_FileProxy {
|
||||||
$fixSize = $util->getFileSize($path);
|
$fixSize = $util->getFileSize($path);
|
||||||
$fileInfo['unencrypted_size'] = $fixSize;
|
$fileInfo['unencrypted_size'] = $fixSize;
|
||||||
// put file info if not .part file
|
// put file info if not .part file
|
||||||
if (!Keymanager::isPartialFilePath($relativePath)) {
|
if (!Helper::isPartialFilePath($relativePath)) {
|
||||||
$view->putFileInfo($path, $fileInfo);
|
$view->putFileInfo($path, $fileInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -372,7 +372,7 @@ class Proxy extends \OC_FileProxy {
|
||||||
$fileInfo['unencrypted_size'] = $size;
|
$fileInfo['unencrypted_size'] = $size;
|
||||||
|
|
||||||
// put file info if not .part file
|
// put file info if not .part file
|
||||||
if (!Keymanager::isPartialFilePath($relativePath)) {
|
if (!Helper::isPartialFilePath($relativePath)) {
|
||||||
$view->putFileInfo($path, $fileInfo);
|
$view->putFileInfo($path, $fileInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2012 Sam Tuke <samtuke@owncloud.com>
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../lib/base.php';
|
||||||
|
require_once __DIR__ . '/../lib/crypt.php';
|
||||||
|
require_once __DIR__ . '/../lib/keymanager.php';
|
||||||
|
require_once __DIR__ . '/../lib/proxy.php';
|
||||||
|
require_once __DIR__ . '/../lib/stream.php';
|
||||||
|
require_once __DIR__ . '/../lib/util.php';
|
||||||
|
require_once __DIR__ . '/../lib/helper.php';
|
||||||
|
require_once __DIR__ . '/../appinfo/app.php';
|
||||||
|
require_once __DIR__ . '/util.php';
|
||||||
|
|
||||||
|
use OCA\Encryption;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Test_Encryption_Keymanager
|
||||||
|
*/
|
||||||
|
class Test_Encryption_Helper extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @medium
|
||||||
|
*/
|
||||||
|
function testFixPartialFilePath() {
|
||||||
|
|
||||||
|
$partFilename = 'testfile.txt.part';
|
||||||
|
$filename = 'testfile.txt';
|
||||||
|
|
||||||
|
$this->assertTrue(Encryption\Keymanager::isPartialFilePath($partFilename));
|
||||||
|
|
||||||
|
$this->assertEquals('testfile.txt', Encryption\Helper::fixPartialFilePath($partFilename));
|
||||||
|
|
||||||
|
$this->assertFalse(Encryption\Keymanager::isPartialFilePath($filename));
|
||||||
|
|
||||||
|
$this->assertEquals('testfile.txt', Encryption\Keymanager::fixPartialFilePath($filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @medium
|
||||||
|
*/
|
||||||
|
function testFixPartialFileWithTransferIdPath() {
|
||||||
|
|
||||||
|
$partFilename = 'testfile.txt.ocTransferId643653835.part';
|
||||||
|
$filename = 'testfile.txt';
|
||||||
|
|
||||||
|
$this->assertTrue(Encryption\Helper::isPartialFilePath($partFilename));
|
||||||
|
|
||||||
|
$this->assertEquals('testfile.txt', Encryption\Helper::fixPartialFilePath($partFilename));
|
||||||
|
|
||||||
|
$this->assertFalse(Encryption\Helper::isPartialFilePath($filename));
|
||||||
|
|
||||||
|
$this->assertEquals('testfile.txt', Encryption\Helper::fixPartialFilePath($filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -188,23 +188,6 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertArrayHasKey('key', $sslInfoPrivate);
|
$this->assertArrayHasKey('key', $sslInfoPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @medium
|
|
||||||
*/
|
|
||||||
function testFixPartialFilePath() {
|
|
||||||
|
|
||||||
$partFilename = 'testfile.txt.part';
|
|
||||||
$filename = 'testfile.txt';
|
|
||||||
|
|
||||||
$this->assertTrue(Encryption\Keymanager::isPartialFilePath($partFilename));
|
|
||||||
|
|
||||||
$this->assertEquals('testfile.txt', Encryption\Keymanager::fixPartialFilePath($partFilename));
|
|
||||||
|
|
||||||
$this->assertFalse(Encryption\Keymanager::isPartialFilePath($filename));
|
|
||||||
|
|
||||||
$this->assertEquals('testfile.txt', Encryption\Keymanager::fixPartialFilePath($filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @medium
|
* @medium
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue