Replaced time() with uniqid() to make sure the file name is unique

The cache isn't cleared properly because unlink() doesn't remove the
cache entry which caused side-effects when reusing the same file name
(which randomly happens when time() returns the same value)

This fix first makes sure the unit tests don't fail any more.
The unlink() case with the cache will be investigated separately.
remotes/origin/ldap_group_count
Vincent Petry 11 years ago
parent 0f794b6889
commit f09c19c316
  1. 34
      apps/files_encryption/tests/crypt.php
  2. 4
      apps/files_encryption/tests/keymanager.php
  3. 2
      apps/files_encryption/tests/proxy.php
  4. 12
      apps/files_encryption/tests/stream.php
  5. 4
      apps/files_encryption/tests/trashbin.php
  6. 12
      apps/files_encryption/tests/util.php
  7. 2
      apps/files_encryption/tests/webdav.php

@ -155,7 +155,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
*/ */
function testSymmetricStreamEncryptShortFileContent() { function testSymmetricStreamEncryptShortFileContent() {
$filename = 'tmp-' . time() . '.test'; $filename = 'tmp-' . uniqid() . '.test';
$util = new Encryption\Util(new \OC_FilesystemView(), $this->userId); $util = new Encryption\Util(new \OC_FilesystemView(), $this->userId);
@ -214,7 +214,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
function testSymmetricStreamEncryptLongFileContent() { function testSymmetricStreamEncryptLongFileContent() {
// Generate a a random filename // Generate a a random filename
$filename = 'tmp-' . time() . '.test'; $filename = 'tmp-' . uniqid() . '.test';
$util = new Encryption\Util(new \OC_FilesystemView(), $this->userId); $util = new Encryption\Util(new \OC_FilesystemView(), $this->userId);
@ -297,7 +297,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
*/ */
function testSymmetricStreamDecryptShortFileContent() { function testSymmetricStreamDecryptShortFileContent() {
$filename = 'tmp-' . time(); $filename = 'tmp-' . uniqid();
// Save long data as encrypted file using stream wrapper // Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///'. $this->userId . '/files/' . $filename, $this->dataShort); $cryptedFile = file_put_contents('crypt:///'. $this->userId . '/files/' . $filename, $this->dataShort);
@ -327,7 +327,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
*/ */
function testSymmetricStreamDecryptLongFileContent() { function testSymmetricStreamDecryptLongFileContent() {
$filename = 'tmp-' . time(); $filename = 'tmp-' . uniqid();
// Save long data as encrypted file using stream wrapper // Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong); $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
@ -418,7 +418,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
*/ */
function testRenameFile() { function testRenameFile() {
$filename = 'tmp-' . time(); $filename = 'tmp-' . uniqid();
// Save long data as encrypted file using stream wrapper // Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong); $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
@ -431,7 +431,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
$this->assertEquals($this->dataLong, $decrypt); $this->assertEquals($this->dataLong, $decrypt);
$newFilename = 'tmp-new-' . time(); $newFilename = 'tmp-new-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
$view->rename($filename, $newFilename); $view->rename($filename, $newFilename);
@ -449,7 +449,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
*/ */
function testMoveFileIntoFolder() { function testMoveFileIntoFolder() {
$filename = 'tmp-' . time(); $filename = 'tmp-' . uniqid();
// Save long data as encrypted file using stream wrapper // Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong); $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
@ -462,8 +462,8 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
$this->assertEquals($this->dataLong, $decrypt); $this->assertEquals($this->dataLong, $decrypt);
$newFolder = '/newfolder' . time(); $newFolder = '/newfolder' . uniqid();
$newFilename = 'tmp-new-' . time(); $newFilename = 'tmp-new-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
$view->mkdir($newFolder); $view->mkdir($newFolder);
$view->rename($filename, $newFolder . '/' . $newFilename); $view->rename($filename, $newFolder . '/' . $newFilename);
@ -484,8 +484,8 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
$filename = '/tmp-' . time(); $filename = '/tmp-' . uniqid();
$folder = '/folder' . time(); $folder = '/folder' . uniqid();
$view->mkdir($folder); $view->mkdir($folder);
@ -500,7 +500,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
$this->assertEquals($this->dataLong, $decrypt); $this->assertEquals($this->dataLong, $decrypt);
$newFolder = '/newfolder/subfolder' . time(); $newFolder = '/newfolder/subfolder' . uniqid();
$view->mkdir('/newfolder'); $view->mkdir('/newfolder');
$view->rename($folder, $newFolder); $view->rename($folder, $newFolder);
@ -519,7 +519,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
* @medium * @medium
*/ */
function testChangePassphrase() { function testChangePassphrase() {
$filename = 'tmp-' . time(); $filename = 'tmp-' . uniqid();
// Save long data as encrypted file using stream wrapper // Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong); $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
@ -557,7 +557,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
*/ */
function testViewFilePutAndGetContents() { function testViewFilePutAndGetContents() {
$filename = '/tmp-' . time(); $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper // Save short data as encrypted file using stream wrapper
@ -590,7 +590,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
* @large * @large
*/ */
function testTouchExistingFile() { function testTouchExistingFile() {
$filename = '/tmp-' . time(); $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper // Save short data as encrypted file using stream wrapper
@ -614,7 +614,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
* @medium * @medium
*/ */
function testTouchFile() { function testTouchFile() {
$filename = '/tmp-' . time(); $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
$view->touch($filename); $view->touch($filename);
@ -638,7 +638,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
* @medium * @medium
*/ */
function testFopenFile() { function testFopenFile() {
$filename = '/tmp-' . time(); $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper // Save short data as encrypted file using stream wrapper

@ -143,7 +143,7 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
$key = $this->randomKey; $key = $this->randomKey;
$file = 'unittest-' . time() . '.txt'; $file = 'unittest-' . uniqid() . '.txt';
$util = new Encryption\Util($this->view, $this->userId); $util = new Encryption\Util($this->view, $this->userId);
@ -196,7 +196,7 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
function testRecursiveDelShareKeys() { function testRecursiveDelShareKeys() {
// generate filename // generate filename
$filename = '/tmp-' . time() . '.txt'; $filename = '/tmp-' . uniqid() . '.txt';
// create folder structure // create folder structure
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1'); $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');

@ -80,7 +80,7 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase {
// init short data // init short data
$this->data = 'hats'; $this->data = 'hats';
$this->filename = 'enc_proxy_tests-' . time() . '.txt'; $this->filename = 'enc_proxy_tests-' . uniqid() . '.txt';
} }

@ -99,7 +99,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
} }
function testStreamOptions() { function testStreamOptions() {
$filename = '/tmp-' . time(); $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper // Save short data as encrypted file using stream wrapper
@ -122,7 +122,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
} }
function testStreamSetBlocking() { function testStreamSetBlocking() {
$filename = '/tmp-' . time(); $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper // Save short data as encrypted file using stream wrapper
@ -144,7 +144,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
* @medium * @medium
*/ */
function testStreamSetTimeout() { function testStreamSetTimeout() {
$filename = '/tmp-' . time(); $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper // Save short data as encrypted file using stream wrapper
@ -163,7 +163,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
} }
function testStreamSetWriteBuffer() { function testStreamSetWriteBuffer() {
$filename = '/tmp-' . time(); $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files'); $view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper // Save short data as encrypted file using stream wrapper
@ -187,9 +187,9 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
*/ */
function testStreamFromLocalFile() { function testStreamFromLocalFile() {
$filename = '/' . $this->userId . '/files/' . 'tmp-' . time().'.txt'; $filename = '/' . $this->userId . '/files/' . 'tmp-' . uniqid().'.txt';
$tmpFilename = "/tmp/" . time() . ".txt"; $tmpFilename = "/tmp/" . uniqid() . ".txt";
// write an encrypted file // write an encrypted file
$cryptedFile = $this->view->file_put_contents($filename, $this->dataShort); $cryptedFile = $this->view->file_put_contents($filename, $this->dataShort);

@ -119,7 +119,7 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase {
function testDeleteFile() { function testDeleteFile() {
// generate filename // generate filename
$filename = 'tmp-' . time() . '.txt'; $filename = 'tmp-' . uniqid() . '.txt';
// save file with content // save file with content
$cryptedFile = file_put_contents('crypt:///' .\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename, $this->dataShort); $cryptedFile = file_put_contents('crypt:///' .\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename, $this->dataShort);
@ -223,7 +223,7 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase {
function testPermanentDeleteFile() { function testPermanentDeleteFile() {
// generate filename // generate filename
$filename = 'tmp-' . time() . '.txt'; $filename = 'tmp-' . uniqid() . '.txt';
// save file with content // save file with content
$cryptedFile = file_put_contents('crypt:///' .$this->userId. '/files/' . $filename, $this->dataShort); $cryptedFile = file_put_contents('crypt:///' .$this->userId. '/files/' . $filename, $this->dataShort);

@ -142,8 +142,8 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
self::loginHelper($this->userId); self::loginHelper($this->userId);
$unencryptedFile = '/tmpUnencrypted-' . time() . '.txt'; $unencryptedFile = '/tmpUnencrypted-' . uniqid() . '.txt';
$encryptedFile = '/tmpEncrypted-' . time() . '.txt'; $encryptedFile = '/tmpEncrypted-' . uniqid() . '.txt';
// Disable encryption proxy to write a unencrypted file // Disable encryption proxy to write a unencrypted file
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
@ -254,7 +254,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
\OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1); \OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
$filename = '/tmp-' . time() . '.test'; $filename = '/tmp-' . uniqid() . '.test';
// Disable encryption proxy to prevent recursive calls // Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
@ -282,7 +282,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
function testGetFileSize() { function testGetFileSize() {
\Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1); \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
$filename = 'tmp-' . time(); $filename = 'tmp-' . uniqid();
$externalFilename = '/' . $this->userId . '/files/' . $filename; $externalFilename = '/' . $this->userId . '/files/' . $filename;
// Test for 0 byte files // Test for 0 byte files
@ -318,7 +318,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
function testEncryptAll() { function testEncryptAll() {
$filename = "/encryptAll" . time() . ".txt"; $filename = "/encryptAll" . uniqid() . ".txt";
$util = new Encryption\Util($this->view, $this->userId); $util = new Encryption\Util($this->view, $this->userId);
// disable encryption to upload a unencrypted file // disable encryption to upload a unencrypted file
@ -350,7 +350,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
function testDecryptAll() { function testDecryptAll() {
$filename = "/decryptAll" . time() . ".txt"; $filename = "/decryptAll" . uniqid() . ".txt";
$util = new Encryption\Util($this->view, $this->userId); $util = new Encryption\Util($this->view, $this->userId);
$this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort); $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort);

@ -113,7 +113,7 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase {
function testWebdavPUT() { function testWebdavPUT() {
// generate filename // generate filename
$filename = '/tmp-' . time() . '.txt'; $filename = '/tmp-' . uniqid() . '.txt';
// set server vars // set server vars
$_SERVER['REQUEST_METHOD'] = 'OPTIONS'; $_SERVER['REQUEST_METHOD'] = 'OPTIONS';

Loading…
Cancel
Save