From 077d41a9ce2419c4bfd1ab5863672386e0cf761a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 5 May 2015 17:16:13 +0200 Subject: [PATCH 1/7] wait with copying the skeleton untill login and setupfs are done --- lib/private/user.php | 5 ++++- lib/private/util.php | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/user.php b/lib/private/user.php index b367723382..2192cbba32 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -241,7 +241,10 @@ class OC_User { $result = self::getUserSession()->login($loginname, $password); if ($result) { //we need to pass the user name, which may differ from login name - OC_Util::setupFS(self::getUserSession()->getUser()->getUID()); + $user = self::getUserSession()->getUser()->getUID(); + OC_Util::setupFS($user); + //trigger creation of user home and /files folder + \OC::$server->getUserFolder($user); } return $result; } diff --git a/lib/private/util.php b/lib/private/util.php index 367199f773..83c92326f8 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -189,9 +189,6 @@ class OC_Util { //jail the user into his "home" directory \OC\Files\Filesystem::init($user, $userDir); - //trigger creation of user home and /files folder - \OC::$server->getUserFolder($user); - OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); } \OC::$server->getEventLogger()->end('setup_fs'); From 415f16eb24138e75be25f66ac261dd08cb269cc9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 May 2015 15:22:05 +0200 Subject: [PATCH 2/7] fix tests --- apps/files_sharing/tests/controller/sharecontroller.php | 5 +---- apps/files_sharing/tests/testcase.php | 1 + tests/lib/testcase.php | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/files_sharing/tests/controller/sharecontroller.php b/apps/files_sharing/tests/controller/sharecontroller.php index 64ee5b8ce5..3a8a282b9a 100644 --- a/apps/files_sharing/tests/controller/sharecontroller.php +++ b/apps/files_sharing/tests/controller/sharecontroller.php @@ -78,10 +78,7 @@ class ShareControllerTest extends \Test\TestCase { \OC_User::createUser($this->user, $this->user); \OC_Util::tearDownFS(); - \OC_User::setUserId(''); - Filesystem::tearDown(); - \OC_User::setUserId($this->user); - \OC_Util::setupFS($this->user); + $this->loginAsUser($this->user); // Create a dummy shared file $view = new View('/'. $this->user . '/files'); diff --git a/apps/files_sharing/tests/testcase.php b/apps/files_sharing/tests/testcase.php index b9e9f07720..7533b13f79 100644 --- a/apps/files_sharing/tests/testcase.php +++ b/apps/files_sharing/tests/testcase.php @@ -153,6 +153,7 @@ abstract class TestCase extends \Test\TestCase { \OC::$server->getUserSession()->setUser(null); \OC\Files\Filesystem::tearDown(); \OC::$server->getUserSession()->login($user, $password); + \OC::$server->getUserFolder($user); \OC_Util::setupFS($user); } diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php index 76d5662da9..3b7ad2a963 100644 --- a/tests/lib/testcase.php +++ b/tests/lib/testcase.php @@ -174,6 +174,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($user); \OC_Util::setupFS($user); + \OC::$server->getUserFolder($user); } /** From a5d652a6b834e4aae9432c1e8e4a2ca0450e8cbb Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 May 2015 15:55:23 +0200 Subject: [PATCH 3/7] fix tests --- tests/lib/testcase.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php index 3b7ad2a963..c1ebfb025c 100644 --- a/tests/lib/testcase.php +++ b/tests/lib/testcase.php @@ -174,7 +174,9 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($user); \OC_Util::setupFS($user); - \OC::$server->getUserFolder($user); + if (\OC_User::userExists($user)) { + \OC::$server->getUserFolder($user); + } } /** From 724f88d9ff1e03e9d857c331961d98da62f31b5e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 May 2015 16:50:43 +0200 Subject: [PATCH 4/7] fix tests --- apps/files_trashbin/tests/trashbin.php | 1 + apps/files_versions/tests/versions.php | 1 + tests/core/avatar/avatarcontrollertest.php | 6 +----- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/files_trashbin/tests/trashbin.php b/apps/files_trashbin/tests/trashbin.php index 85c47b527b..0c37af24de 100644 --- a/apps/files_trashbin/tests/trashbin.php +++ b/apps/files_trashbin/tests/trashbin.php @@ -646,6 +646,7 @@ class Test_Trashbin extends \Test\TestCase { \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($user); \OC_Util::setupFS($user); + \OC::$server->getUserFolder($user); } } diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php index 97afcf715c..685bf48d65 100644 --- a/apps/files_versions/tests/versions.php +++ b/apps/files_versions/tests/versions.php @@ -753,6 +753,7 @@ class Test_Files_Versioning extends \Test\TestCase { \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($user); \OC_Util::setupFS($user); + \OC::$server->getUserFolder($user); } } diff --git a/tests/core/avatar/avatarcontrollertest.php b/tests/core/avatar/avatarcontrollertest.php index a5456eb678..c58d7febc3 100644 --- a/tests/core/avatar/avatarcontrollertest.php +++ b/tests/core/avatar/avatarcontrollertest.php @@ -88,11 +88,7 @@ class AvatarControllerTest extends \Test\TestCase { $this->user = $this->getUniqueID('user'); OC::$server->getUserManager()->createUser($this->user, $this->user); - \OC_Util::tearDownFS(); - \OC_User::setUserId(''); - Filesystem::tearDown(); - \OC_User::setUserId($this->user); - \OC_Util::setupFS($this->user); + $this->loginAsUser($this->user); // Create Cache dir $view = new \OC\Files\View('/'.$this->user); From 5899b7b6ea1f8573370168333c16df38d80a5a38 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 18 May 2015 12:28:54 +0200 Subject: [PATCH 5/7] Fix provisioning API unit tests for login Properly login the user every time to make sure their FS is properly setup. --- apps/provisioning_api/tests/appstest.php | 2 +- apps/provisioning_api/tests/groupstest.php | 12 +-- apps/provisioning_api/tests/userstest.php | 86 +++++++++++----------- 3 files changed, 51 insertions(+), 49 deletions(-) diff --git a/apps/provisioning_api/tests/appstest.php b/apps/provisioning_api/tests/appstest.php index 140dd287a0..94bff8bbf5 100644 --- a/apps/provisioning_api/tests/appstest.php +++ b/apps/provisioning_api/tests/appstest.php @@ -44,7 +44,7 @@ class AppsTest extends TestCase { $user = $this->generateUsers(); \OC_Group::addToGroup($user, 'admin'); - \OC_User::setUserId($user); + self::loginAsUser($user); $result = \OCA\provisioning_API\Apps::getApps(array()); diff --git a/apps/provisioning_api/tests/groupstest.php b/apps/provisioning_api/tests/groupstest.php index 94bde52c39..cb677d9b51 100644 --- a/apps/provisioning_api/tests/groupstest.php +++ b/apps/provisioning_api/tests/groupstest.php @@ -27,7 +27,7 @@ class GroupsTest extends TestCase { public function testGetGroupAsUser() { $users = $this->generateUsers(2); - \OC_User::setUserId($users[0]); + self::loginAsUser($users[0]); $group = $this->getUniqueID(); \OC_Group::createGroup($group); @@ -46,7 +46,7 @@ class GroupsTest extends TestCase { public function testGetGroupAsSubadmin() { $users = $this->generateUsers(2); - \OC_User::setUserId($users[0]); + self::loginAsUser($users[0]); $group = $this->getUniqueID(); \OC_Group::createGroup($group); @@ -75,7 +75,7 @@ class GroupsTest extends TestCase { public function testGetGroupAsIrrelevantSubadmin() { $users = $this->generateUsers(2); - \OC_User::setUserId($users[0]); + self::loginAsUser($users[0]); $group = $this->getUniqueID(); \OC_Group::createGroup($group); @@ -99,7 +99,7 @@ class GroupsTest extends TestCase { public function testGetGroupAsAdmin() { $users = $this->generateUsers(2); - \OC_User::setUserId($users[0]); + self::loginAsUser($users[0]); $group = $this->getUniqueID(); \OC_Group::createGroup($group); @@ -120,7 +120,7 @@ class GroupsTest extends TestCase { public function testGetSubAdminsOfGroup() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -135,7 +135,7 @@ class GroupsTest extends TestCase { \OC_Group::deleteGroup($group1); $user1 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $result = \OCA\provisioning_api\Groups::getSubAdminsOfGroup(array( 'groupid' => $this->getUniqueID(), diff --git a/apps/provisioning_api/tests/userstest.php b/apps/provisioning_api/tests/userstest.php index c6a6133b7d..0ba76355d5 100644 --- a/apps/provisioning_api/tests/userstest.php +++ b/apps/provisioning_api/tests/userstest.php @@ -81,7 +81,7 @@ class UsersTest extends TestCase { public function testGetUserOnSelf() { $user = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $params['userid'] = $user; $result = \OCA\provisioning_API\Users::getUser($params); $this->assertInstanceOf('OC_OCS_Result', $result); @@ -92,7 +92,7 @@ class UsersTest extends TestCase { public function testGetUserOnNonExistingUser() { $user = $this->generateUsers(); \OC_Group::addToGroup($user, 'admin'); - \OC_User::setUserId($user); + self::loginAsUser($user); $params = array(); $params['userid'] = $this->getUniqueID(); while(\OC_User::userExists($params['userid'])) { @@ -108,7 +108,7 @@ class UsersTest extends TestCase { public function testGetUserOnOtherUser() { $users = $this->generateUsers(2); $params['userid'] = $users[0]; - \OC_User::setUserId($users[1]); + self::loginAsUser($users[1]); $result = \OCA\provisioning_API\Users::getUser($params); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertFalse($result->succeeded()); @@ -116,8 +116,10 @@ class UsersTest extends TestCase { // Now as as admin $users = $this->generateUsers(2); $params['userid'] = $users[0]; + // login to generate home + self::loginAsUser($users[0]); \OC_Group::addToGroup($users[1], 'admin'); - \OC_User::setUserId($users[1]); + self::loginAsUser($users[1]); $result = \OCA\provisioning_API\Users::getUser($params); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); @@ -129,7 +131,7 @@ class UsersTest extends TestCase { // Test editing own name $user = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $result = \OCA\provisioning_API\Users::editUser( array( 'userid' => $user, @@ -150,7 +152,7 @@ class UsersTest extends TestCase { // Test admin editing users name $user = $this->generateUsers(); \OC_Group::addToGroup($user, 'admin'); - \OC_User::setUserId($user); + self::loginAsUser($user); $user2 = $this->generateUsers(); $result = \OCA\provisioning_API\Users::editUser( array( @@ -171,7 +173,7 @@ class UsersTest extends TestCase { // Test editing other users name $user = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $user2 = $this->generateUsers(); $result = \OCA\provisioning_API\Users::editUser( array( @@ -195,7 +197,7 @@ class UsersTest extends TestCase { public function testEditOwnQuota($expected, $quota) { $user = $this->generateUsers(); \OC_Group::addToGroup($user, 'admin'); - \OC_User::setUserId($user); + self::loginAsUser($user); $result = \OCA\provisioning_API\Users::editUser( [ 'userid' => $user, @@ -222,7 +224,7 @@ class UsersTest extends TestCase { public function testAdminEditOwnQuota() { $user = $this->generateUsers(); \OC_Group::addToGroup($user, 'admin'); - \OC_User::setUserId($user); + self::loginAsUser($user); $result = \OCA\provisioning_API\Users::editUser( array( 'userid' => $user, @@ -239,7 +241,7 @@ class UsersTest extends TestCase { public function testAdminEditOtherUserQuota() { $user = $this->generateUsers(); \OC_Group::addToGroup($user, 'admin'); - \OC_User::setUserId($user); + self::loginAsUser($user); $user2 = $this->generateUsers(); $result = \OCA\provisioning_API\Users::editUser( array( @@ -256,7 +258,7 @@ class UsersTest extends TestCase { public function testUserEditOtherUserQuota() { $user = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $user2 = $this->generateUsers(); $result = \OCA\provisioning_API\Users::editUser( array( @@ -274,7 +276,7 @@ class UsersTest extends TestCase { public function testUserEditOwnEmail() { $user = $this->generateUsers(); $email = 'test@example.com'; - \OC_User::setUserId($user); + self::loginAsUser($user); $result = \OCA\provisioning_API\Users::editUser( array( 'userid' => $user, @@ -292,7 +294,7 @@ class UsersTest extends TestCase { public function testUserEditOtherUserEmailAsUser() { $users = $this->generateUsers(2); $email = 'test@example.com'; - \OC_User::setUserId($users[0]); + self::loginAsUser($users[0]); $result = \OCA\provisioning_API\Users::editUser( array( 'userid' => $users[1], @@ -309,7 +311,7 @@ class UsersTest extends TestCase { public function testUserEditOtherUserEmailAsAdmin() { $users = $this->generateUsers(2); $email = 'test@example.com'; - \OC_User::setUserId($users[0]); + self::loginAsUser($users[0]); \OC_Group::addToGroup($users[0], 'admin'); $result = \OCA\provisioning_API\Users::editUser( array( @@ -327,7 +329,7 @@ class UsersTest extends TestCase { public function testDeleteSelf() { $user = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $result = \OCA\provisioning_API\Users::deleteUser(array( 'userid' => $user, )); @@ -337,7 +339,7 @@ class UsersTest extends TestCase { public function testDeleteOtherAsUser() { $user = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $user2 = $this->generateUsers(); $result = \OCA\provisioning_API\Users::deleteUser(array( 'userid' => $user2, @@ -348,7 +350,7 @@ class UsersTest extends TestCase { public function testDeleteOtherAsSubAdmin() { $user = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $user2 = $this->generateUsers(); $group = $this->getUniqueID(); \OC_Group::createGroup($group); @@ -365,7 +367,7 @@ class UsersTest extends TestCase { public function testDeleteOtherAsIrelevantSubAdmin() { $user = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $user2 = $this->generateUsers(); $group = $this->getUniqueID(); $group2 = $this->getUniqueID(); @@ -386,7 +388,7 @@ class UsersTest extends TestCase { public function testDeleteOtherAsAdmin() { $user = $this->generateUsers(); \OC_Group::addToGroup($user, 'admin'); - \OC_User::setUserId($user); + self::loginAsUser($user); $user2 = $this->generateUsers(); $result = \OCA\provisioning_API\Users::deleteUser(array( 'userid' => $user2, @@ -398,7 +400,7 @@ class UsersTest extends TestCase { public function testDeleteSelfAsAdmin() { $user = $this->generateUsers(); \OC_Group::addToGroup($user, 'admin'); - \OC_User::setUserId($user); + self::loginAsUser($user); $result = \OCA\provisioning_API\Users::deleteUser(array( 'userid' => $user, )); @@ -408,7 +410,7 @@ class UsersTest extends TestCase { public function testGetUsersGroupsOnSelf() { $user = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $group = $this->getUniqueID(); \OC_Group::createGroup($group); \OC_Group::addToGroup($user, $group); @@ -426,7 +428,7 @@ class UsersTest extends TestCase { public function testGetUsersGroupOnOther() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $group = $this->getUniqueID(); \OC_Group::createGroup($group); \OC_Group::addToGroup($user2, $group); @@ -442,7 +444,7 @@ class UsersTest extends TestCase { $user1 = $this->generateUsers(); \OC_Group::addToGroup($user1, 'admin'); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $group = $this->getUniqueID(); \OC_Group::createGroup($group); \OC_Group::addToGroup($user2, $group); @@ -460,7 +462,7 @@ class UsersTest extends TestCase { public function testGetUsersGroupsOnOtherAsSubAdmin() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $group1 = $this->getUniqueID(); $group2 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -484,7 +486,7 @@ class UsersTest extends TestCase { public function testGetUsersGroupsOnOtherAsIrelevantSubAdmin() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $group1 = $this->getUniqueID(); $group2 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -505,7 +507,7 @@ class UsersTest extends TestCase { $user = $this->generateUsers(); $group = $this->getUniqueID(); \OC_Group::createGroup($group); - \OC_User::setUserId($user); + self::loginAsUser($user); $_POST['groupid'] = $group; $result = \OCA\provisioning_API\Users::addToGroup(array( 'userid' => $user, @@ -522,7 +524,7 @@ class UsersTest extends TestCase { $group = $this->getUniqueID(); \OC_Group::createGroup($group); $user2 = $this->generateUsers(); - \OC_User::setUserId($user); + self::loginAsUser($user); $_POST['groupid'] = $group; $result = \OCA\provisioning_API\Users::addToGroup(array( 'userid' => $user2, @@ -536,7 +538,7 @@ class UsersTest extends TestCase { public function testAddToGroupAsSubAdmin() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); \OC_SubAdmin::createSubAdmin($user1, $group1); @@ -553,7 +555,7 @@ class UsersTest extends TestCase { public function testAddToGroupAsIrelevantSubAdmin() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $group1 = $this->getUniqueID(); $group2 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -573,7 +575,7 @@ class UsersTest extends TestCase { // test delete /cloud/users/{userid}/groups public function testRemoveFromGroupAsSelf() { $user1 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); \OC_Group::addToGroup($user1, $group1); @@ -592,7 +594,7 @@ class UsersTest extends TestCase { public function testRemoveFromGroupAsAdmin() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); \OC_Group::addToGroup($user2, $group1); @@ -611,7 +613,7 @@ class UsersTest extends TestCase { public function testRemoveFromGroupAsSubAdmin() { $user1 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $user2 = $this->generateUsers(); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -632,7 +634,7 @@ class UsersTest extends TestCase { public function testRemoveFromGroupAsIrelevantSubAdmin() { $user1 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); $user2 = $this->generateUsers(); $group1 = $this->getUniqueID(); $group2 = $this->getUniqueID(); @@ -657,7 +659,7 @@ class UsersTest extends TestCase { public function testCreateSubAdmin() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -674,7 +676,7 @@ class UsersTest extends TestCase { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $_POST['groupid'] = 'admin'; $result = \OCA\provisioning_api\Users::addSubAdmin(array( @@ -687,7 +689,7 @@ class UsersTest extends TestCase { $this->resetParams(); $user1 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -704,7 +706,7 @@ class UsersTest extends TestCase { public function testRemoveSubAdmin() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -721,7 +723,7 @@ class UsersTest extends TestCase { \OC_Group::deleteGroup($group1); $user1 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $result = \OCA\provisioning_api\Users::removeSubAdmin(array( 'userid' => $this->getUniqueID(), @@ -737,7 +739,7 @@ class UsersTest extends TestCase { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -757,7 +759,7 @@ class UsersTest extends TestCase { public function testGetSubAdminGroups() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); @@ -772,7 +774,7 @@ class UsersTest extends TestCase { \OC_Group::deleteGroup($group1); $user1 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $group1 = $this->getUniqueID(); $result = \OCA\provisioning_api\Users::getUserSubAdminGroups(array( @@ -786,7 +788,7 @@ class UsersTest extends TestCase { public function testSubAdminOfGroupAlreadySubAdmin() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); - \OC_User::setUserId($user1); + self::loginAsUser($user1); \OC_Group::addToGroup($user1, 'admin'); $group1 = $this->getUniqueID(); \OC_Group::createGroup($group1); From ad88a7d53d039207eddc82993920beab26375f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 19 May 2015 12:35:22 +0200 Subject: [PATCH 6/7] exception class will be logged as well - helps especially in cases where the message contained is empty - e.g. "message":"OCP\\Files\\NotFoundException: at \/home\/deepdiver\/Development\/ownCloud\/core-autotest\/apps\/provisioning_api\/lib\/users.php#354", --- lib/private/log/errorhandler.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/private/log/errorhandler.php b/lib/private/log/errorhandler.php index b1b15f12ed..5e92db398f 100644 --- a/lib/private/log/errorhandler.php +++ b/lib/private/log/errorhandler.php @@ -64,10 +64,16 @@ class ErrorHandler { } } - // Uncaught exception handler + /** + * Uncaught exception handler + * + * @param \Exception $exception + */ public static function onException($exception) { - $msg = $exception->getMessage() . ' at ' . $exception->getFile() . '#' . $exception->getLine(); - self::$logger->critical(self::removePassword($msg), array('app' => 'PHP')); + $class = get_class($exception); + $msg = $exception->getMessage(); + $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); + self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); } //Recoverable errors handler From 6d97dfb00c6bd660d9f8ac3a579f34d70fe87af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 19 May 2015 12:38:03 +0200 Subject: [PATCH 7/7] Catch NotFoundException and return no quota information which simply reflects the current state - no file storage has been initialized for the user. --- apps/provisioning_api/lib/users.php | 36 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/apps/provisioning_api/lib/users.php b/apps/provisioning_api/lib/users.php index 43cf22b071..b709e09726 100644 --- a/apps/provisioning_api/lib/users.php +++ b/apps/provisioning_api/lib/users.php @@ -27,6 +27,7 @@ use \OC_SubAdmin; use \OC_User; use \OC_Group; use \OC_Helper; +use OCP\Files\NotFoundException; class Users { @@ -92,16 +93,8 @@ class Users { $config = \OC::$server->getConfig(); // Find the data - $data = array(); - \OC_Util::tearDownFS(); - \OC_Util::setupFS($userId); - $storage = OC_Helper::getStorageInfo('/'); - $data['quota'] = array( - 'free' => $storage['free'], - 'used' => $storage['used'], - 'total' => $storage['total'], - 'relative' => $storage['relative'], - ); + $data = []; + $data = self::fillStorageInfo($userId, $data); $data['enabled'] = $config->getUserValue($userId, 'core', 'enabled', 'true'); $data['email'] = $config->getUserValue($userId, 'settings', 'email'); $data['displayname'] = OC_User::getDisplayName($parameters['userid']); @@ -350,4 +343,27 @@ class Users { return new OC_OCS_Result($groups); } } + + /** + * @param $userId + * @param $data + * @return mixed + * @throws \OCP\Files\NotFoundException + */ + private static function fillStorageInfo($userId, $data) { + try { + \OC_Util::tearDownFS(); + \OC_Util::setupFS($userId); + $storage = OC_Helper::getStorageInfo('/'); + $data['quota'] = [ + 'free' => $storage['free'], + 'used' => $storage['used'], + 'total' => $storage['total'], + 'relative' => $storage['relative'], + ]; + } catch (NotFoundException $ex) { + $data['quota'] = []; + } + return $data; + } }