From 4e625202d1d2383f4624a462f61117fa7991d781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 16 Jul 2013 00:53:56 +0200 Subject: [PATCH 1/4] Use EXECUTOR_NUMBER in database name and user name. --- autotest.sh | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/autotest.sh b/autotest.sh index 141b4333f97..31757e0e48e 100755 --- a/autotest.sh +++ b/autotest.sh @@ -3,12 +3,17 @@ # ownCloud # # @author Thomas Müller -# @copyright 2012 Thomas Müller thomas.mueller@tmit.eu +# @copyright 2012, 2013 Thomas Müller thomas.mueller@tmit.eu # +#$EXECUTOR_NUMBER is set by Jenkins and allows us to run autotest in parallel +DATABASENAME=oc_autotest$EXECUTOR_NUMBER +ADMINLOGIN=admin$EXECUTOR_NUMBER DATADIR=data-autotest BASEDIR=$PWD +echo "Using database $DATABASENAME" + # create autoconfig for sqlite, mysql and postgresql cat > ./tests/autoconfig-sqlite.php < ./tests/autoconfig-sqlite.php < false, 'dbtype' => 'sqlite', 'dbtableprefix' => 'oc_', - 'adminlogin' => 'admin', + 'adminlogin' => $ADMINLOGIN, 'adminpass' => 'admin', 'directory' => '$BASEDIR/$DATADIR', ); @@ -28,13 +33,13 @@ cat > ./tests/autoconfig-mysql.php < false, 'dbtype' => 'mysql', 'dbtableprefix' => 'oc_', - 'adminlogin' => 'admin', + 'adminlogin' => $ADMINLOGIN, 'adminpass' => 'admin', 'directory' => '$BASEDIR/$DATADIR', - 'dbuser' => 'oc_autotest', - 'dbname' => 'oc_autotest', + 'dbuser' => 'oc_autotest', + 'dbname' => $DATABASENAME, 'dbhost' => 'localhost', - 'dbpass' => 'owncloud', + 'dbpass' => 'owncloud', ); DELIM @@ -44,13 +49,13 @@ cat > ./tests/autoconfig-pgsql.php < false, 'dbtype' => 'pgsql', 'dbtableprefix' => 'oc_', - 'adminlogin' => 'admin', + 'adminlogin' => $ADMINLOGIN, 'adminpass' => 'admin', 'directory' => '$BASEDIR/$DATADIR', - 'dbuser' => 'oc_autotest', - 'dbname' => 'oc_autotest', + 'dbuser' => 'oc_autotest', + 'dbname' => $DATABASENAME, 'dbhost' => 'localhost', - 'dbpass' => 'owncloud', + 'dbpass' => 'owncloud', ); DELIM @@ -60,10 +65,10 @@ cat > ./tests/autoconfig-oci.php < false, 'dbtype' => 'oci', 'dbtableprefix' => 'oc_', - 'adminlogin' => 'admin', + 'adminlogin' => $ADMINLOGIN, 'adminpass' => 'admin', 'directory' => '$BASEDIR/$DATADIR', - 'dbuser' => 'oc_autotest', + 'dbuser' => $DATABASENAME, 'dbname' => 'XE', 'dbhost' => 'localhost', 'dbpass' => 'owncloud', @@ -88,21 +93,21 @@ function execute_tests { # drop database if [ "$1" == "mysql" ] ; then - mysql -u oc_autotest -powncloud -e "DROP DATABASE oc_autotest" + mysql -u oc_autotest -powncloud -e "DROP DATABASE $DATABASENAME" fi if [ "$1" == "pgsql" ] ; then - dropdb -U oc_autotest oc_autotest + dropdb -U oc_autotest $DATABASENAME fi if [ "$1" == "oci" ] ; then echo "drop the database" sqlplus -s -l / as sysdba < Date: Fri, 19 Jul 2013 08:50:22 +0200 Subject: [PATCH 2/4] parallel execution support for mysql added --- autotest.sh | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/autotest.sh b/autotest.sh index 31757e0e48e..6f1cd2ba22c 100755 --- a/autotest.sh +++ b/autotest.sh @@ -8,6 +8,7 @@ #$EXECUTOR_NUMBER is set by Jenkins and allows us to run autotest in parallel DATABASENAME=oc_autotest$EXECUTOR_NUMBER +DATABASEUSER=oc_autotest$EXECUTOR_NUMBER ADMINLOGIN=admin$EXECUTOR_NUMBER DATADIR=data-autotest BASEDIR=$PWD @@ -21,7 +22,7 @@ cat > ./tests/autoconfig-sqlite.php < false, 'dbtype' => 'sqlite', 'dbtableprefix' => 'oc_', - 'adminlogin' => $ADMINLOGIN, + 'adminlogin' => '$ADMINLOGIN', 'adminpass' => 'admin', 'directory' => '$BASEDIR/$DATADIR', ); @@ -33,11 +34,11 @@ cat > ./tests/autoconfig-mysql.php < false, 'dbtype' => 'mysql', 'dbtableprefix' => 'oc_', - 'adminlogin' => $ADMINLOGIN, + 'adminlogin' => '$ADMINLOGIN', 'adminpass' => 'admin', 'directory' => '$BASEDIR/$DATADIR', - 'dbuser' => 'oc_autotest', - 'dbname' => $DATABASENAME, + 'dbuser' => '$DATABASEUSER', + 'dbname' => '$DATABASENAME', 'dbhost' => 'localhost', 'dbpass' => 'owncloud', ); @@ -49,11 +50,11 @@ cat > ./tests/autoconfig-pgsql.php < false, 'dbtype' => 'pgsql', 'dbtableprefix' => 'oc_', - 'adminlogin' => $ADMINLOGIN, + 'adminlogin' => '$ADMINLOGIN', 'adminpass' => 'admin', 'directory' => '$BASEDIR/$DATADIR', - 'dbuser' => 'oc_autotest', - 'dbname' => $DATABASENAME, + 'dbuser' => '$DATABASEUSER', + 'dbname' => '$DATABASENAME', 'dbhost' => 'localhost', 'dbpass' => 'owncloud', ); @@ -65,10 +66,10 @@ cat > ./tests/autoconfig-oci.php < false, 'dbtype' => 'oci', 'dbtableprefix' => 'oc_', - 'adminlogin' => $ADMINLOGIN, + 'adminlogin' => '$ADMINLOGIN', 'adminpass' => 'admin', 'directory' => '$BASEDIR/$DATADIR', - 'dbuser' => $DATABASENAME, + 'dbuser' => '$DATABASENAME', 'dbname' => 'XE', 'dbhost' => 'localhost', 'dbpass' => 'owncloud', @@ -93,10 +94,10 @@ function execute_tests { # drop database if [ "$1" == "mysql" ] ; then - mysql -u oc_autotest -powncloud -e "DROP DATABASE $DATABASENAME" + mysql -u $DATABASEUSER -powncloud -e "DROP DATABASE $DATABASENAME" fi if [ "$1" == "pgsql" ] ; then - dropdb -U oc_autotest $DATABASENAME + dropdb -U $DATABASEUSER $DATABASENAME fi if [ "$1" == "oci" ] ; then echo "drop the database" @@ -158,8 +159,14 @@ fi # # NOTES on mysql: +# - CREATE DATABASE oc_autotest; # - CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'owncloud'; -# - grant access permissions: grant all on oc_autotest.* to 'oc_autotest'@'localhost'; +# - grant all on oc_autotest.* to 'oc_autotest'@'localhost'; +# +# - for parallel executor support with EXECUTOR_NUMBER=0: +# - CREATE DATABASE oc_autotest0; +# - CREATE USER 'oc_autotest0'@'localhost' IDENTIFIED BY 'owncloud'; +# - grant all on oc_autotest0.* to 'oc_autotest0'@'localhost'; # # NOTES on pgsql: # - su - postgres From 7fac7fef03a389fd1755c5e3051d2270e11cc6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 19 Jul 2013 10:49:30 +0200 Subject: [PATCH 3/4] pgsql support added --- autotest.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/autotest.sh b/autotest.sh index 6f1cd2ba22c..abe0b92586c 100755 --- a/autotest.sh +++ b/autotest.sh @@ -170,10 +170,13 @@ fi # # NOTES on pgsql: # - su - postgres -# - createuser -P (enter username and password and enable superuser) +# - createuser -P oc_autotest (enter password and enable superuser) # - to enable dropdb I decided to add following line to pg_hba.conf (this is not the safest way but I don't care for the testing machine): # local all all trust # +# - for parallel executor support with EXECUTOR_NUMBER=0: +# - createuser -P oc_autotest0 (enter password and enable superuser) +# # NOTES on oci: # - it's a pure nightmare to install Oracle on a Linux-System # - DON'T TRY THIS AT HOME! From 20ee9945d18b9a8124e84f2dcbb82b75011f27ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 19 Jul 2013 14:54:10 +0200 Subject: [PATCH 4/4] don't rely on admin user but create a test user for Test_Encryption_Keymanager --- apps/files_encryption/tests/keymanager.php | 32 ++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php index 19ba9a8117f..b644856d95d 100644 --- a/apps/files_encryption/tests/keymanager.php +++ b/apps/files_encryption/tests/keymanager.php @@ -14,6 +14,7 @@ require_once realpath(dirname(__FILE__) . '/../lib/stream.php'); require_once realpath(dirname(__FILE__) . '/../lib/util.php'); require_once realpath(dirname(__FILE__) . '/../lib/helper.php'); require_once realpath(dirname(__FILE__) . '/../appinfo/app.php'); +require_once realpath(dirname(__FILE__) . '/util.php'); use OCA\Encryption; @@ -22,6 +23,8 @@ use OCA\Encryption; */ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase { + const TEST_USER = "test-keymanager-user"; + public $userId; public $pass; public $stateFilesTrashbin; @@ -47,17 +50,9 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase { // disable file proxy by default \OC_FileProxy::$enabled = false; - // setup filesystem - \OC_Util::tearDownFS(); - \OC_User::setUserId(''); - \OC\Files\Filesystem::tearDown(); - \OC_Util::setupFS('admin'); - \OC_User::setUserId('admin'); - - // login admin - $params['uid'] = 'admin'; - $params['password'] = 'admin'; - OCA\Encryption\Hooks::login($params); + // create test user + \OC_User::deleteUser(\Test_Encryption_Keymanager::TEST_USER); + \Test_Encryption_Util::loginHelper(\Test_Encryption_Keymanager::TEST_USER, true); } function setUp() { @@ -75,9 +70,9 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase { $this->view = new \OC_FilesystemView('/'); - \OC_User::setUserId('admin'); - $this->userId = 'admin'; - $this->pass = 'admin'; + \OC_User::setUserId(\Test_Encryption_Keymanager::TEST_USER); + $this->userId = \Test_Encryption_Keymanager::TEST_USER; + $this->pass = \Test_Encryption_Keymanager::TEST_USER; $userHome = \OC_User::getHome($this->userId); $this->dataDir = str_replace('/' . $this->userId, '', $userHome); @@ -101,6 +96,9 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase { public static function tearDownAfterClass() { \OC_FileProxy::$enabled = true; + + // cleanup test user + \OC_User::deleteUser(\Test_Encryption_Keymanager::TEST_USER); } /** @@ -226,9 +224,9 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase { $filename = '/tmp-' . time() . '.txt'; // create folder structure - $this->view->mkdir('/admin/files/folder1'); - $this->view->mkdir('/admin/files/folder1/subfolder'); - $this->view->mkdir('/admin/files/folder1/subfolder/subsubfolder'); + $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1'); + $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/subfolder'); + $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/subfolder/subsubfolder'); // enable encryption proxy $proxyStatus = \OC_FileProxy::$enabled;