Skip to content

Commit

Permalink
Merge pull request #12291 from owncloud/issue/10991-stable7-backport
Browse files Browse the repository at this point in the history
Issue/10991 stable7 backport
  • Loading branch information
nickvergessen committed Nov 19, 2014
2 parents e6e0573 + 2f12702 commit 6a6b645
Show file tree
Hide file tree
Showing 47 changed files with 805 additions and 425 deletions.
14 changes: 12 additions & 2 deletions apps/files/tests/ajax_rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
*/
private $files;

function setUp() {
/** @var \OC\Files\Storage\Storage */
private $originalStorage;

protected function setUp() {
parent::setUp();

$this->originalStorage = \OC\Files\Filesystem::getStorage('/');

// mock OC_L10n
if (!self::$user) {
self::$user = uniqid();
Expand All @@ -59,10 +66,13 @@ function setUp() {
$this->files = new \OCA\Files\App($viewMock, $l10nMock);
}

function tearDown() {
protected function tearDown() {
$result = \OC_User::deleteUser(self::$user);
$this->assertTrue($result);
\OC\Files\Filesystem::tearDown();
\OC\Files\Filesystem::mount($this->originalStorage, array(), '/');

parent::tearDown();
}

/**
Expand Down
1 change: 1 addition & 0 deletions apps/files_encryption/lib/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ public function stream_close() {
\OC_FileProxy::$enabled = false;

if ($this->rootView->file_exists($this->rawPath) && $this->size === 0) {
fclose($this->handle);
$this->rootView->unlink($this->rawPath);
}

Expand Down
91 changes: 50 additions & 41 deletions apps/files_encryption/tests/crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Class Test_Encryption_Crypt
*/
class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {

const TEST_ENCRYPTION_CRYPT_USER1 = "test-crypt-user1";

Expand All @@ -42,6 +42,8 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
public $genPublicKey;

public static function setUpBeforeClass() {
parent::setUpBeforeClass();

// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
Expand All @@ -57,10 +59,12 @@ public static function setUpBeforeClass() {
\OC_FileProxy::register(new OCA\Encryption\Proxy());

// create test user
\Test_Encryption_Util::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true);
self::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true);
}

function setUp() {
protected function setUp() {
parent::setUp();

// set user id
\OC_User::setUserId(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1);
$this->userId = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1;
Expand Down Expand Up @@ -88,7 +92,7 @@ function setUp() {
\OC_App::disable('files_trashbin');
}

function tearDown() {
protected function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
Expand All @@ -98,6 +102,8 @@ function tearDown() {

$this->assertTrue(\OC_FileProxy::$enabled);
\OCP\Config::deleteSystemValue('cipher');

parent::tearDown();
}

public static function tearDownAfterClass() {
Expand All @@ -111,12 +117,14 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');

parent::tearDownAfterClass();
}

/**
* @medium
*/
function testGenerateKey() {
public function testGenerateKey() {

# TODO: use more accurate (larger) string length for test confirmation

Expand All @@ -126,7 +134,7 @@ function testGenerateKey() {

}

function testDecryptPrivateKey() {
public function testDecryptPrivateKey() {

// test successful decrypt
$crypted = Encryption\Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat');
Expand All @@ -148,7 +156,7 @@ function testDecryptPrivateKey() {
/**
* @medium
*/
function testSymmetricEncryptFileContent() {
public function testSymmetricEncryptFileContent() {

# TODO: search in keyfile for actual content as IV will ensure this test always passes

Expand All @@ -166,7 +174,7 @@ function testSymmetricEncryptFileContent() {
/**
* @medium
*/
function testSymmetricEncryptFileContentAes128() {
public function testSymmetricEncryptFileContentAes128() {

# TODO: search in keyfile for actual content as IV will ensure this test always passes

Expand All @@ -184,9 +192,9 @@ function testSymmetricEncryptFileContentAes128() {
/**
* @medium
*/
function testSymmetricStreamEncryptShortFileContent() {
public function testSymmetricStreamEncryptShortFileContent() {

$filename = 'tmp-' . uniqid() . '.test';
$filename = 'tmp-' . $this->getUniqueID() . '.test';

$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/'. $filename, $this->dataShort);

Expand Down Expand Up @@ -221,9 +229,9 @@ function testSymmetricStreamEncryptShortFileContent() {
/**
* @medium
*/
function testSymmetricStreamEncryptShortFileContentAes128() {
public function testSymmetricStreamEncryptShortFileContentAes128() {

$filename = 'tmp-' . uniqid() . '.test';
$filename = 'tmp-' . $this->getUniqueID() . '.test';

\OCP\Config::setSystemValue('cipher', 'AES-128-CFB');

Expand Down Expand Up @@ -266,10 +274,10 @@ function testSymmetricStreamEncryptShortFileContentAes128() {
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
* reassembly of its data
*/
function testSymmetricStreamEncryptLongFileContent() {
public function testSymmetricStreamEncryptLongFileContent() {

// Generate a a random filename
$filename = 'tmp-' . uniqid() . '.test';
$filename = 'tmp-' . $this->getUniqueID() . '.test';

// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong);
Expand Down Expand Up @@ -310,10 +318,10 @@ function testSymmetricStreamEncryptLongFileContent() {
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
* reassembly of its data
*/
function testSymmetricStreamEncryptLongFileContentAes128() {
public function testSymmetricStreamEncryptLongFileContentAes128() {

// Generate a a random filename
$filename = 'tmp-' . uniqid() . '.test';
$filename = 'tmp-' . $this->getUniqueID() . '.test';

\OCP\Config::setSystemValue('cipher', 'AES-128-CFB');

Expand Down Expand Up @@ -358,10 +366,10 @@ function testSymmetricStreamEncryptLongFileContentAes128() {
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
* reassembly of its data
*/
function testStreamDecryptLongFileContentWithoutHeader() {
public function testStreamDecryptLongFileContentWithoutHeader() {

// Generate a a random filename
$filename = 'tmp-' . uniqid() . '.test';
$filename = 'tmp-' . $this->getUniqueID() . '.test';

\OCP\Config::setSystemValue('cipher', 'AES-128-CFB');

Expand Down Expand Up @@ -406,7 +414,7 @@ function testStreamDecryptLongFileContentWithoutHeader() {
/**
* @medium
*/
function testIsEncryptedContent() {
public function testIsEncryptedContent() {

$this->assertFalse(Encryption\Crypt::isCatfileContent($this->dataUrl));

Expand All @@ -421,7 +429,7 @@ function testIsEncryptedContent() {
/**
* @large
*/
function testMultiKeyEncrypt() {
public function testMultiKeyEncrypt() {

# TODO: search in keyfile for actual content as IV will ensure this test always passes

Expand Down Expand Up @@ -475,9 +483,9 @@ function testLegacyDecryptLong() {
/**
* @medium
*/
function testRenameFile() {
public function testRenameFile() {

$filename = 'tmp-' . uniqid();
$filename = 'tmp-' . $this->getUniqueID();

// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
Expand All @@ -490,7 +498,7 @@ function testRenameFile() {

$this->assertEquals($this->dataLong, $decrypt);

$newFilename = 'tmp-new-' . uniqid();
$newFilename = 'tmp-new-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
$view->rename($filename, $newFilename);

Expand All @@ -506,9 +514,9 @@ function testRenameFile() {
/**
* @medium
*/
function testMoveFileIntoFolder() {
public function testMoveFileIntoFolder() {

$filename = 'tmp-' . uniqid();
$filename = 'tmp-' . $this->getUniqueID();

// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
Expand All @@ -521,8 +529,8 @@ function testMoveFileIntoFolder() {

$this->assertEquals($this->dataLong, $decrypt);

$newFolder = '/newfolder' . uniqid();
$newFilename = 'tmp-new-' . uniqid();
$newFolder = '/newfolder' . $this->getUniqueID();
$newFilename = 'tmp-new-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
$view->mkdir($newFolder);
$view->rename($filename, $newFolder . '/' . $newFilename);
Expand All @@ -539,12 +547,12 @@ function testMoveFileIntoFolder() {
/**
* @medium
*/
function testMoveFolder() {
public function testMoveFolder() {

$view = new \OC\Files\View('/' . $this->userId . '/files');

$filename = '/tmp-' . uniqid();
$folder = '/folder' . uniqid();
$filename = '/tmp-' . $this->getUniqueID();
$folder = '/folder' . $this->getUniqueID();

$view->mkdir($folder);

Expand All @@ -559,7 +567,7 @@ function testMoveFolder() {

$this->assertEquals($this->dataLong, $decrypt);

$newFolder = '/newfolder/subfolder' . uniqid();
$newFolder = '/newfolder/subfolder' . $this->getUniqueID();
$view->mkdir('/newfolder');

$view->rename($folder, $newFolder);
Expand All @@ -577,8 +585,8 @@ function testMoveFolder() {
/**
* @medium
*/
function testChangePassphrase() {
$filename = 'tmp-' . uniqid();
public function testChangePassphrase() {
$filename = 'tmp-' . $this->getUniqueID();

// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
Expand Down Expand Up @@ -614,9 +622,9 @@ function testChangePassphrase() {
/**
* @medium
*/
function testViewFilePutAndGetContents() {
public function testViewFilePutAndGetContents() {

$filename = '/tmp-' . uniqid();
$filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');

// Save short data as encrypted file using stream wrapper
Expand Down Expand Up @@ -648,8 +656,8 @@ function testViewFilePutAndGetContents() {
/**
* @large
*/
function testTouchExistingFile() {
$filename = '/tmp-' . uniqid();
public function testTouchExistingFile() {
$filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');

// Save short data as encrypted file using stream wrapper
Expand All @@ -672,8 +680,8 @@ function testTouchExistingFile() {
/**
* @medium
*/
function testTouchFile() {
$filename = '/tmp-' . uniqid();
public function testTouchFile() {
$filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');

$view->touch($filename);
Expand All @@ -696,8 +704,8 @@ function testTouchFile() {
/**
* @medium
*/
function testFopenFile() {
$filename = '/tmp-' . uniqid();
public function testFopenFile() {
$filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');

// Save short data as encrypted file using stream wrapper
Expand All @@ -714,6 +722,7 @@ function testFopenFile() {
$this->assertEquals($this->dataShort, $decrypt);

// tear down
fclose($handle);
$view->unlink($filename);
}

Expand Down
Loading

0 comments on commit 6a6b645

Please sign in to comment.