fixed tests, now tests should work via autotest.sh

files_encryption app is now enabled in enable_all.php
This commit is contained in:
Florin Peter 2013-04-30 01:35:46 +02:00
Родитель 882a747b47
Коммит 27ce7845b4
4 изменённых файлов: 50 добавлений и 23 удалений

Просмотреть файл

@ -204,7 +204,12 @@ class Util {
$this->view->file_put_contents( $this->privateKeyPath, $encryptedPrivateKey );
\OC_FileProxy::$enabled = true;
// create database configuration
$sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery`) VALUES (?,?,?)';
$args = array( $this->userId, 'server-side', 0);
$query = \OCP\DB::prepare( $sql );
$query->execute( $args );
}
return true;

Просмотреть файл

@ -50,8 +50,8 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase {
$userHome = \OC_User::getHome($this->userId);
$this->dataDir = str_replace('/'.$this->userId, '', $userHome);
\OC_Filesystem::init( $this->userId, '/' );
\OC_Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => $this->dataDir), '/' );
\OC\Files\Filesystem::init( $this->userId, '/' );
\OC\Files\Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => $this->dataDir), '/' );
}

Просмотреть файл

@ -29,19 +29,20 @@ use OCA\Encryption;
class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
function setUp() {
\OC_Filesystem::mount( 'OC_Filestorage_Local', array(), '/' );
// set content for encrypting / decrypting in tests
// reset backend
\OC_User::useBackend('database');
\OC_User::setUserId( 'admin' );
$this->userId = 'admin';
$this->pass = 'admin';
// set content for encrypting / decrypting in tests
$this->dataUrl = realpath( dirname(__FILE__).'/../lib/crypt.php' );
$this->dataShort = 'hats';
$this->dataLong = file_get_contents( realpath( dirname(__FILE__).'/../lib/crypt.php' ) );
$this->legacyData = realpath( dirname(__FILE__).'/legacy-text.txt' );
$this->legacyEncryptedData = realpath( dirname(__FILE__).'/legacy-encrypted-text.txt' );
$this->userId = 'admin';
$this->pass = 'admin';
$keypair = Encryption\Crypt::createKeypair();
$this->genPublicKey = $keypair['publicKey'];
@ -54,9 +55,15 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
$this->privateKeyPath = $this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key
$this->view = new \OC_FilesystemView( '/' );
$this->mockView = m::mock('OC_FilesystemView');
$this->util = new Encryption\Util( $this->mockView, $this->userId );
$userHome = \OC_User::getHome($this->userId);
$this->dataDir = str_replace('/'.$this->userId, '', $userHome);
\OC\Files\Filesystem::init( $this->userId, '/' );
\OC\Files\Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => $this->dataDir), '/' );
$mockView = m::mock('OC_FilesystemView');
$this->util = new Encryption\Util( $mockView, $this->userId );
}
@ -90,8 +97,8 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
$mockView = m::mock('OC_FilesystemView');
$mockView->shouldReceive( 'file_exists' )->times(5)->andReturn( false );
$mockView->shouldReceive( 'mkdir' )->times(4)->andReturn( true );
$mockView->shouldReceive( 'file_exists' )->times(7)->andReturn( false );
$mockView->shouldReceive( 'mkdir' )->times(6)->andReturn( true );
$mockView->shouldReceive( 'file_put_contents' )->withAnyArgs();
$util = new Encryption\Util( $mockView, $this->userId );
@ -107,7 +114,7 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
$mockView = m::mock('OC_FilesystemView');
$mockView->shouldReceive( 'file_exists' )->times(6)->andReturn( true );
$mockView->shouldReceive( 'file_exists' )->times(8)->andReturn( true );
$mockView->shouldReceive( 'file_put_contents' )->withAnyArgs();
$util = new Encryption\Util( $mockView, $this->userId );
@ -141,7 +148,7 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
$mockView = m::mock('OC_FilesystemView');
$mockView->shouldReceive( 'file_exists' )->times(3)->andReturn( true );
$mockView->shouldReceive( 'file_exists' )->times(5)->andReturn( true );
$util = new Encryption\Util( $mockView, $this->userId );
@ -190,11 +197,25 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
function testGetUidAndFilename() {
\OC_User::setUserId( 'admin' );
$this->util->getUidAndFilename( 'test1.txt' );
$filename = 'tmp-'.time().'.test';
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort);
// Re-enable proxy - our work is done
\OC_FileProxy::$enabled = $proxyStatus;
$util = new Encryption\Util( $this->view, $this->userId );
list($fileOwnerUid, $file) = $util->getUidAndFilename( $filename );
$this->assertEquals('admin', $fileOwnerUid);
$this->assertEquals($file, $filename);
}
// /**

Просмотреть файл

@ -8,6 +8,7 @@
require_once __DIR__.'/../lib/base.php';
OC_App::enable('files_encryption');
OC_App::enable('calendar');
OC_App::enable('contacts');
OC_App::enable('apptemplateadvanced');