improvements for test testSymmetricStreamEncryptShortFileContent

this runs currently into an infinite loop
This commit is contained in:
Florin Peter 2013-04-29 09:12:43 +02:00
parent 4a63faf64b
commit 4ecd62e58d
1 changed files with 37 additions and 29 deletions

View File

@ -53,9 +53,14 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
$this->userId = 'admin'; $this->userId = 'admin';
$this->pass = 'admin'; $this->pass = 'admin';
\OC_Filesystem::init( '/' ); $userHome = \OC_User::getHome($this->userId);
\OC_Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => \OC_User::getHome($this->userId)), '/' ); if(!file_exists($userHome)) {
mkdir($userHome, 0777, true);
}
$dataDir = str_replace('/'.$this->userId, '', $userHome);
\OC\Files\Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => $dataDir), '/' );
\OC\Files\Filesystem::init($this->userId, '/');
} }
function tearDown() { function tearDown() {
@ -222,34 +227,37 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
function testSymmetricStreamEncryptShortFileContent() { function testSymmetricStreamEncryptShortFileContent() {
$filename = 'tmp-'.time(); $filename = 'tmp-'.time().'.test';
$cryptedFile = file_put_contents( 'crypt://' . $filename, $this->dataShort ); $cryptedFile = file_put_contents( 'crypt://' . $filename, $this->dataShort );
// Test that data was successfully written // Test that data was successfully written
$this->assertTrue( is_int( $cryptedFile ) ); $this->assertTrue( is_int( $cryptedFile ) );
// Get file contents without using any wrapper to get it's actual contents on disk // Get file contents without using any wrapper to get it's actual contents on disk
$retreivedCryptedFile = $this->view->file_get_contents( $this->userId . '/files/' . $filename ); $absolutePath = \OC\Files\Filesystem::getLocalFile($this->userId . '/files/' . $filename);
$retreivedCryptedFile = file_get_contents($absolutePath);
// Check that the file was encrypted before being written to disk // Check that the file was encrypted before being written to disk
$this->assertNotEquals( $this->dataShort, $retreivedCryptedFile ); $this->assertNotEquals( $this->dataShort, $retreivedCryptedFile );
// Get private key // Get the encrypted keyfile
$encryptedPrivateKey = Encryption\Keymanager::getPrivateKey( $this->view, $this->userId ); $encKeyfile = Encryption\Keymanager::getFileKey( $this->view, $this->userId, $filename );
$decryptedPrivateKey = Encryption\Crypt::symmetricDecryptFileContent( $encryptedPrivateKey, $this->pass ); // Attempt to fetch the user's shareKey
$shareKey = Encryption\Keymanager::getShareKey( $this->view, $this->userId, $filename );
// get session
$session = new Encryption\Session( $this->view );
// Get keyfile // get private key
$encryptedKeyfile = Encryption\Keymanager::getFileKey( $this->view, $this->userId, $filename ); $privateKey = $session->getPrivateKey( $this->userId );
$decryptedKeyfile = Encryption\Crypt::keyDecrypt( $encryptedKeyfile, $decryptedPrivateKey );
// Decrypt keyfile with shareKey
$plainKeyfile = Encryption\Crypt::multiKeyDecrypt( $encKeyfile, $shareKey, $privateKey );
// Manually decrypt // Manually decrypt
$manualDecrypt = Encryption\Crypt::symmetricBlockDecryptFileContent( $retreivedCryptedFile, $decryptedKeyfile ); $manualDecrypt = Encryption\Crypt::symmetricDecryptFileContent( $retreivedCryptedFile, $plainKeyfile );
// Check that decrypted data matches // Check that decrypted data matches
$this->assertEquals( $this->dataShort, $manualDecrypt ); $this->assertEquals( $this->dataShort, $manualDecrypt );
@ -329,7 +337,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
$this->view->unlink( $filename ); $this->view->unlink( $filename );
Encryption\Keymanager::deleteFileKey( $filename ); Encryption\Keymanager::deleteFileKey( $this->view, $this->userId, $filename );
} }