summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests/webdav.php
diff options
context:
space:
mode:
authorFlorin Peter <github@florin-peter.de>2013-05-26 20:44:15 +0200
committerFlorin Peter <github@florin-peter.de>2013-05-26 20:44:15 +0200
commit9dd277576a87b8876ebf281ba21161fa30645807 (patch)
treee0fec7e05a91f1838a37e998e356d79f672386ba /apps/files_encryption/tests/webdav.php
parentc7981abbc902ece98ceaad72e475ec5515cd26a7 (diff)
downloadnextcloud-server-9dd277576a87b8876ebf281ba21161fa30645807.tar.gz
nextcloud-server-9dd277576a87b8876ebf281ba21161fa30645807.zip
added users for tests
reformat code to meet coding guidelines
Diffstat (limited to 'apps/files_encryption/tests/webdav.php')
-rwxr-xr-xapps/files_encryption/tests/webdav.php146
1 files changed, 79 insertions, 67 deletions
diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php
index 57848cd273c..94d3ec3fa55 100755
--- a/apps/files_encryption/tests/webdav.php
+++ b/apps/files_encryption/tests/webdav.php
@@ -20,13 +20,14 @@
*
*/
-require_once realpath( dirname( __FILE__ ) . '/../../../lib/base.php' );
-require_once realpath( dirname( __FILE__ ) . '/../lib/crypt.php' );
-require_once realpath( dirname( __FILE__ ) . '/../lib/keymanager.php' );
-require_once realpath( dirname( __FILE__ ) . '/../lib/proxy.php' );
-require_once realpath( dirname( __FILE__ ) . '/../lib/stream.php' );
-require_once realpath( dirname( __FILE__ ) . '/../lib/util.php' );
-require_once realpath( dirname( __FILE__ ) . '/../appinfo/app.php' );
+require_once realpath(dirname(__FILE__) . '/../../../lib/base.php');
+require_once realpath(dirname(__FILE__) . '/../lib/crypt.php');
+require_once realpath(dirname(__FILE__) . '/../lib/keymanager.php');
+require_once realpath(dirname(__FILE__) . '/../lib/proxy.php');
+require_once realpath(dirname(__FILE__) . '/../lib/stream.php');
+require_once realpath(dirname(__FILE__) . '/../lib/util.php');
+require_once realpath(dirname(__FILE__) . '/../appinfo/app.php');
+require_once realpath(dirname(__FILE__) . '/util.php');
use OCA\Encryption;
@@ -34,8 +35,9 @@ use OCA\Encryption;
* Class Test_Encryption_Webdav
* @brief this class provide basic webdav tests for PUT,GET and DELETE
*/
-class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
-{
+class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_WEBDAV_USER1 = "test-webdav-user1";
public $userId;
public $pass;
@@ -46,57 +48,63 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
public $dataShort;
public $stateFilesTrashbin;
+ public static function setUpBeforeClass() {
+ // reset backend
+ \OC_User::clearBackends();
+ \OC_User::useBackend('database');
+
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerUserHooks();
+
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1, true);
+ }
+
function setUp() {
// reset backend
- \OC_User::useBackend( 'database' );
+ \OC_User::useBackend('database');
// set user id
- \OC_User::setUserId( 'admin' );
- $this->userId = 'admin';
- $this->pass = 'admin';
+ \OC_User::setUserId(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1);
+ $this->userId = \Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1;
+ $this->pass = \Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1;
// init filesystem view
- $this->view = new \OC_FilesystemView( '/' );
+ $this->view = new \OC_FilesystemView('/');
// init short data
$this->dataShort = 'hats';
- // init filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // clear and register hooks
- \OC_FileProxy::clearProxies();
- \OC_FileProxy::register( new OCA\Encryption\Proxy() );
-
// remember files_trashbin state
- $this->stateFilesTrashbin = OC_App::isEnabled( 'files_trashbin' );
+ $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
// we don't want to tests with app files_trashbin enabled
- \OC_App::disable( 'files_trashbin' );
-
- // init filesystem for user
- \OC_Util::tearDownFS();
- \OC_User::setUserId( '' );
- \OC\Files\Filesystem::tearDown();
- \OC_Util::setupFS( $this->userId );
- \OC_User::setUserId( $this->userId );
-
- // login user
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
- OCA\Encryption\Hooks::login( $params );
+ \OC_App::disable('files_trashbin');
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1);
}
function tearDown() {
// reset app files_trashbin
- if ( $this->stateFilesTrashbin ) {
- OC_App::enable( 'files_trashbin' );
- } else {
- OC_App::disable( 'files_trashbin' );
+ if ($this->stateFilesTrashbin) {
+ OC_App::enable('files_trashbin');
+ }
+ else {
+ OC_App::disable('files_trashbin');
}
+ }
- // clear and register hooks
- \OC_FileProxy::clearProxies();
+ public static function tearDownAfterClass() {
+ // cleanup test user
+ \OC_User::deleteUser(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1);
}
/**
@@ -115,38 +123,40 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic YWRtaW46YWRtaW4=';
$_SERVER['CONTENT_TYPE'] = 'application/octet-stream';
$_SERVER['PATH_INFO'] = '/webdav' . $filename;
- $_SERVER['CONTENT_LENGTH'] = strlen( $this->dataShort );
+ $_SERVER['CONTENT_LENGTH'] = strlen($this->dataShort);
// handle webdav request
- $this->handleWebdavRequest( $this->dataShort );
+ $this->handleWebdavRequest($this->dataShort);
// check if file was created
- $this->assertTrue( $this->view->file_exists( '/' . $this->userId . '/files' . $filename ) );
+ $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files' . $filename));
// check if key-file was created
- $this->assertTrue( $this->view->file_exists( '/' . $this->userId . '/files_encryption/keyfiles/' . $filename . '.key' ) );
+ $this->assertTrue($this->view->file_exists(
+ '/' . $this->userId . '/files_encryption/keyfiles/' . $filename . '.key'));
// check if shareKey-file was created
- $this->assertTrue( $this->view->file_exists( '/' . $this->userId . '/files_encryption/share-keys/' . $filename . '.' . $this->userId . '.shareKey' ) );
+ $this->assertTrue($this->view->file_exists(
+ '/' . $this->userId . '/files_encryption/share-keys/' . $filename . '.' . $this->userId . '.shareKey'));
// disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
// get encrypted file content
- $encryptedContent = $this->view->file_get_contents( '/' . $this->userId . '/files' . $filename );
+ $encryptedContent = $this->view->file_get_contents('/' . $this->userId . '/files' . $filename);
// restore proxy state
\OC_FileProxy::$enabled = $proxyStatus;
// check if encrypted content is valid
- $this->assertTrue( Encryption\Crypt::isCatfileContent( $encryptedContent ) );
+ $this->assertTrue(Encryption\Crypt::isCatfileContent($encryptedContent));
// get decrypted file contents
- $decrypt = file_get_contents( 'crypt://' . $filename );
+ $decrypt = file_get_contents('crypt://' . $filename);
// check if file content match with the written content
- $this->assertEquals( $this->dataShort, $decrypt );
+ $this->assertEquals($this->dataShort, $decrypt);
// return filename for next test
return $filename;
@@ -157,7 +167,7 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
*
* @depends testWebdavPUT
*/
- function testWebdavGET( $filename ) {
+ function testWebdavGET($filename) {
// set server vars
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -169,7 +179,7 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
$content = $this->handleWebdavRequest();
// check if file content match with the written content
- $this->assertEquals( $this->dataShort, $content );
+ $this->assertEquals($this->dataShort, $content);
// return filename for next test
return $filename;
@@ -179,7 +189,7 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
* @brief test webdav delete random file
* @depends testWebdavGET
*/
- function testWebdavDELETE( $filename ) {
+ function testWebdavDELETE($filename) {
// set server vars
$_SERVER['REQUEST_METHOD'] = 'DELETE';
$_SERVER['REQUEST_URI'] = '/remote.php/webdav' . $filename;
@@ -190,13 +200,15 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
$content = $this->handleWebdavRequest();
// check if file was removed
- $this->assertFalse( $this->view->file_exists( '/' . $this->userId . '/files' . $filename ) );
+ $this->assertFalse($this->view->file_exists('/' . $this->userId . '/files' . $filename));
// check if key-file was removed
- $this->assertFalse( $this->view->file_exists( '/' . $this->userId . '/files_encryption/keyfiles' . $filename . '.key' ) );
+ $this->assertFalse($this->view->file_exists(
+ '/' . $this->userId . '/files_encryption/keyfiles' . $filename . '.key'));
// check if shareKey-file was removed
- $this->assertFalse( $this->view->file_exists( '/' . $this->userId . '/files_encryption/share-keys' . $filename . '.' . $this->userId . '.shareKey' ) );
+ $this->assertFalse($this->view->file_exists(
+ '/' . $this->userId . '/files_encryption/share-keys' . $filename . '.' . $this->userId . '.shareKey'));
}
/**
@@ -206,30 +218,30 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
*
* @note this init procedure is copied from /apps/files/remote.php
*/
- function handleWebdavRequest( $body = false ) {
+ function handleWebdavRequest($body = false) {
// Backends
$authBackend = new OC_Connector_Sabre_Auth();
$lockBackend = new OC_Connector_Sabre_Locks();
$requestBackend = new OC_Connector_Sabre_Request();
// Create ownCloud Dir
- $publicDir = new OC_Connector_Sabre_Directory( '' );
+ $publicDir = new OC_Connector_Sabre_Directory('');
// Fire up server
- $server = new Sabre_DAV_Server( $publicDir );
+ $server = new Sabre_DAV_Server($publicDir);
$server->httpRequest = $requestBackend;
- $server->setBaseUri( '/remote.php/webdav/' );
+ $server->setBaseUri('/remote.php/webdav/');
// Load plugins
- $server->addPlugin( new Sabre_DAV_Auth_Plugin( $authBackend, 'ownCloud' ) );
- $server->addPlugin( new Sabre_DAV_Locks_Plugin( $lockBackend ) );
- $server->addPlugin( new Sabre_DAV_Browser_Plugin( false ) ); // Show something in the Browser, but no upload
- $server->addPlugin( new OC_Connector_Sabre_QuotaPlugin() );
- $server->addPlugin( new OC_Connector_Sabre_MaintenancePlugin() );
+ $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend, 'ownCloud'));
+ $server->addPlugin(new Sabre_DAV_Locks_Plugin($lockBackend));
+ $server->addPlugin(new Sabre_DAV_Browser_Plugin(false)); // Show something in the Browser, but no upload
+ $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin());
+ $server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin());
// And off we go!
- if ( $body ) {
- $server->httpRequest->setBody( $body );
+ if ($body) {
+ $server->httpRequest->setBody($body);
}
// turn on output buffering