123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769 |
- <?php
- /**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Tom Needham <tom@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
- namespace OCA\Provisioning_API\Tests;
- class UsersTest extends TestCase {
- protected function resetParams() {
- $_GET = null;
- $_POST = null;
- }
- // Test getting the list of users
- public function testGetUsers() {
- $result = \OCA\provisioning_API\Users::getUsers(array());
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $count = $result->getData();
- $count = count($count['users']);
- $this->assertEquals(count(\OC_User::getUsers()), $count);
- $user = $this->generateUsers();
- $_GET['search'] = $user;
- $result = \OCA\provisioning_API\Users::getUsers(array());
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $this->assertEquals($user, reset($data['users']));
- // Add several users
- $this->generateUsers(10);
- $this->resetParams();
- $_GET['limit'] = 2;
- $result = \OCA\provisioning_API\Users::getUsers(array());
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $count = $result->getData();
- $count = count($count['users']);
- $this->assertEquals(2, $count);
- $this->resetParams();
- $_GET['limit'] = 1;
- $_GET['offset'] = 1;
- $result = \OCA\provisioning_API\Users::getUsers(array());
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $this->assertEquals(\OC_User::getUsers('', 1, 1), $data['users']);
- }
- public function testAddUser() {
- $this->resetParams();
- $_POST['userid'] = $this->getUniqueID();
- $_POST['password'] = 'password';
- $result = \OCA\provisioning_API\Users::addUser(array());
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertTrue(\OC_User::userExists($_POST['userid']));
- $this->assertEquals($_POST['userid'], \OC_User::checkPassword($_POST['userid'], $_POST['password']));
- $this->users[] = $_POST['userid'];
- }
- public function testGetUserOnSelf() {
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $params['userid'] = $user;
- $result = \OCA\provisioning_API\Users::getUser($params);
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- }
- public function testGetUserOnNonExistingUser() {
- $user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- \OC_User::setUserId($user);
- $params = array();
- $params['userid'] = $this->getUniqueID();
- while(\OC_User::userExists($params['userid'])) {
- $params['userid'] = $this->getUniqueID();
- }
- $result = \OCA\provisioning_API\Users::getUser($params);
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertEquals(\OC_API::RESPOND_NOT_FOUND, $result->getStatusCode());
- }
- public function testGetUserOnOtherUser() {
- $users = $this->generateUsers(2);
- $params['userid'] = $users[0];
- \OC_User::setUserId($users[1]);
- $result = \OCA\provisioning_API\Users::getUser($params);
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- // Now as as admin
- $users = $this->generateUsers(2);
- $params['userid'] = $users[0];
- \OC_Group::addToGroup($users[1], 'admin');
- \OC_User::setUserId($users[1]);
- $result = \OCA\provisioning_API\Users::getUser($params);
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $this->assertEquals(\OC::$server->getConfig()->getUserValue($users[0], 'core', 'enabled', 'true'), $data['enabled']);
- }
- public function testEditOwnDisplayName() {
- // Test editing own name
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $user,
- '_put' => array(
- 'key' => 'display',
- 'value' => 'newname',
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertEquals('newname', \OC_User::getDisplayName($user));
- }
- public function testAdminEditDisplayNameOfUser() {
- // Test admin editing users name
- $user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- \OC_User::setUserId($user);
- $user2 = $this->generateUsers();
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $user2,
- '_put' => array(
- 'key' => 'display',
- 'value' => 'newname',
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertEquals('newname', \OC_User::getDisplayName($user2));
- }
- public function testUserEditOtherUserDisplayName() {
- // Test editing other users name
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $user2 = $this->generateUsers();
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $user2,
- '_put' => array(
- 'key' => 'display',
- 'value' => 'newname',
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- }
- public function testEditOwnQuota() {
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $user,
- '_put' => array(
- 'key' => 'quota',
- 'value' => '20G',
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- }
- public function testAdminEditOwnQuota() {
- $user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- \OC_User::setUserId($user);
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $user,
- '_put' => array(
- 'key' => 'quota',
- 'value' => '20G',
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- }
- public function testAdminEditOtherUserQuota() {
- $user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- \OC_User::setUserId($user);
- $user2 = $this->generateUsers();
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $user2,
- '_put' => array(
- 'key' => 'quota',
- 'value' => '20G',
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- }
- public function testUserEditOtherUserQuota() {
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $user2 = $this->generateUsers();
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $user2,
- '_put' => array(
- 'key' => 'quota',
- 'value' => '20G',
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- }
- public function testUserEditOwnEmail() {
- $user = $this->generateUsers();
- $email = 'test@example.com';
- \OC_User::setUserId($user);
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $user,
- '_put' => array(
- 'key' => 'email',
- 'value' => $email,
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertEquals($email, \OC::$server->getConfig()->getUserValue($user, 'settings', 'email', null));
- }
- public function testUserEditOtherUserEmailAsUser() {
- $users = $this->generateUsers(2);
- $email = 'test@example.com';
- \OC_User::setUserId($users[0]);
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $users[1],
- '_put' => array(
- 'key' => 'email',
- 'value' => $email,
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- }
- public function testUserEditOtherUserEmailAsAdmin() {
- $users = $this->generateUsers(2);
- $email = 'test@example.com';
- \OC_User::setUserId($users[0]);
- \OC_Group::addToGroup($users[0], 'admin');
- $result = \OCA\provisioning_API\Users::editUser(
- array(
- 'userid' => $users[1],
- '_put' => array(
- 'key' => 'email',
- 'value' => $email,
- ),
- )
- );
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertEquals($email, \OC::$server->getConfig()->getUserValue($users[1], 'settings', 'email', null));
- }
- public function testDeleteSelf() {
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $result = \OCA\provisioning_API\Users::deleteUser(array(
- 'userid' => $user,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- }
- public function testDeleteOtherAsUser() {
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $user2 = $this->generateUsers();
- $result = \OCA\provisioning_API\Users::deleteUser(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- }
- public function testDeleteOtherAsSubAdmin() {
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $user2 = $this->generateUsers();
- $group = $this->getUniqueID();
- \OC_Group::createGroup($group);
- \OC_Group::addToGroup($user, $group);
- \OC_Group::addToGroup($user2, $group);
- \OC_SubAdmin::createSubAdmin($user, $group);
- $result = \OCA\provisioning_API\Users::deleteUser(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- \OC_Group::deleteGroup($group);
- }
- public function testDeleteOtherAsIrelevantSubAdmin() {
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $user2 = $this->generateUsers();
- $group = $this->getUniqueID();
- $group2 = $this->getUniqueID();
- \OC_Group::createGroup($group);
- \OC_Group::createGroup($group2);
- \OC_Group::addToGroup($user, $group);
- \OC_Group::addToGroup($user2, $group2);
- \OC_SubAdmin::createSubAdmin($user, $group);
- $result = \OCA\provisioning_API\Users::deleteUser(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- \OC_Group::deleteGroup($group);
- \OC_Group::deleteGroup($group2);
- }
- public function testDeleteOtherAsAdmin() {
- $user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- \OC_User::setUserId($user);
- $user2 = $this->generateUsers();
- $result = \OCA\provisioning_API\Users::deleteUser(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- }
- public function testDeleteSelfAsAdmin() {
- $user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- \OC_User::setUserId($user);
- $result = \OCA\provisioning_API\Users::deleteUser(array(
- 'userid' => $user,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- }
- public function testGetUsersGroupsOnSelf() {
- $user = $this->generateUsers();
- \OC_User::setUserId($user);
- $group = $this->getUniqueID();
- \OC_Group::createGroup($group);
- \OC_Group::addToGroup($user, $group);
- $result = \OCA\provisioning_API\Users::getUsersGroups(array(
- 'userid' => $user,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $this->assertEquals($group, reset($data['groups']));
- $this->assertEquals(1, count($data['groups']));
- \OC_Group::deleteGroup($group);
- }
- public function testGetUsersGroupOnOther() {
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $group = $this->getUniqueID();
- \OC_Group::createGroup($group);
- \OC_Group::addToGroup($user2, $group);
- $result = \OCA\provisioning_API\Users::getUsersGroups(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- \OC_Group::deleteGroup($group);
- }
- public function testGetUsersGroupOnOtherAsAdmin() {
- $user1 = $this->generateUsers();
- \OC_Group::addToGroup($user1, 'admin');
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $group = $this->getUniqueID();
- \OC_Group::createGroup($group);
- \OC_Group::addToGroup($user2, $group);
- $result = \OCA\provisioning_API\Users::getUsersGroups(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $this->assertEquals($group, reset($data['groups']));
- $this->assertEquals(1, count($data['groups']));
- \OC_Group::deleteGroup($group);
- }
- public function testGetUsersGroupsOnOtherAsSubAdmin() {
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $group1 = $this->getUniqueID();
- $group2 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_Group::createGroup($group2);
- \OC_Group::addToGroup($user2, $group1);
- \OC_Group::addToGroup($user2, $group2);
- \OC_Group::addToGroup($user1, $group1);
- \OC_SubAdmin::createSubAdmin($user1, $group1);
- $result = \OCA\provisioning_API\Users::getUsersGroups(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $this->assertEquals($group1, reset($data['groups']));
- $this->assertEquals(1, count($data['groups']));
- \OC_Group::deleteGroup($group1);
- \OC_Group::deleteGroup($group2);
- }
- public function testGetUsersGroupsOnOtherAsIrelevantSubAdmin() {
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $group1 = $this->getUniqueID();
- $group2 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_Group::createGroup($group2);
- \OC_Group::addToGroup($user2, $group2);
- \OC_Group::addToGroup($user1, $group1);
- \OC_SubAdmin::createSubAdmin($user1, $group1);
- $result = \OCA\provisioning_API\Users::getUsersGroups(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- \OC_Group::deleteGroup($group1);
- \OC_Group::deleteGroup($group2);
- }
- public function testAddToGroup() {
- $user = $this->generateUsers();
- $group = $this->getUniqueID();
- \OC_Group::createGroup($group);
- \OC_User::setUserId($user);
- $_POST['groupid'] = $group;
- $result = \OCA\provisioning_API\Users::addToGroup(array(
- 'userid' => $user,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertFalse(\OC_Group::inGroup($user, $group));
- \OC_Group::deleteGroup($group);
- }
- public function testAddToGroupAsAdmin() {
- $user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- $group = $this->getUniqueID();
- \OC_Group::createGroup($group);
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user);
- $_POST['groupid'] = $group;
- $result = \OCA\provisioning_API\Users::addToGroup(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertTrue(\OC_Group::inGroup($user2, $group));
- \OC_Group::deleteGroup($group);
- }
- public function testAddToGroupAsSubAdmin() {
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $group1 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_SubAdmin::createSubAdmin($user1, $group1);
- $_POST['groupid'] = $group1;
- $result = \OCA\provisioning_API\Users::addToGroup(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertFalse(\OC_Group::inGroup($user2, $group1));
- \OC_Group::deleteGroup($group1);
- }
- public function testAddToGroupAsIrelevantSubAdmin() {
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $group1 = $this->getUniqueID();
- $group2 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_Group::createGroup($group2);
- \OC_SubAdmin::createSubAdmin($user1, $group1);
- $_POST['groupid'] = $group2;
- $result = \OCA\provisioning_API\Users::addToGroup(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertFalse(\OC_Group::inGroup($user2, $group2));
- \OC_Group::deleteGroup($group1);
- \OC_Group::deleteGroup($group2);
- }
- // test delete /cloud/users/{userid}/groups
- public function testRemoveFromGroupAsSelf() {
- $user1 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $group1 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_Group::addToGroup($user1, $group1);
- $result = \OCA\provisioning_api\Users::removeFromGroup(array(
- 'userid' => $user1,
- '_delete' => array(
- 'groupid' => $group1,
- ),
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertTrue(\OC_Group::inGroup($user1, $group1));
- \OC_Group::deleteGroup($group1);
- }
- public function testRemoveFromGroupAsAdmin() {
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $group1 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_Group::addToGroup($user2, $group1);
- \OC_Group::addToGroup($user1, 'admin');
- $result = \OCA\provisioning_api\Users::removeFromGroup(array(
- 'userid' => $user2,
- '_delete' => array(
- 'groupid' => $group1,
- ),
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertFalse(\OC_Group::inGroup($user2, $group1));
- \OC_Group::deleteGroup($group1);
- }
- public function testRemoveFromGroupAsSubAdmin() {
- $user1 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $user2 = $this->generateUsers();
- $group1 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_Group::addToGroup($user1, $group1);
- \OC_Group::addToGroup($user2, $group1);
- \OC_SubAdmin::createSubAdmin($user1, $group1);
- $result = \OCA\provisioning_api\Users::removeFromGroup(array(
- 'userid' => $user2,
- '_delete' => array(
- 'groupid' => $group1,
- ),
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertFalse(\OC_Group::inGroup($user2, $group1));
- \OC_Group::deleteGroup($group1);
- }
- public function testRemoveFromGroupAsIrelevantSubAdmin() {
- $user1 = $this->generateUsers();
- \OC_User::setUserId($user1);
- $user2 = $this->generateUsers();
- $group1 = $this->getUniqueID();
- $group2 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_Group::createGroup($group2);
- \OC_Group::addToGroup($user1, $group1);
- \OC_Group::addToGroup($user2, $group2);
- \OC_SubAdmin::createSubAdmin($user1, $group1);
- $result = \OCA\provisioning_api\Users::removeFromGroup(array(
- 'userid' => $user2,
- '_delete' => array(
- 'groupid' => $group2,
- ),
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertTrue(\OC_Group::inGroup($user2, $group2));
- \OC_Group::deleteGroup($group1);
- \OC_Group::deleteGroup($group2);
- }
- public function testCreateSubAdmin() {
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- \OC_Group::addToGroup($user1, 'admin');
- $group1 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- $_POST['groupid'] = $group1;
- $result = \OCA\provisioning_api\Users::addSubAdmin(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertTrue(\OC_SubAdmin::isSubAdminofGroup($user2, $group1));
- \OC_Group::deleteGroup($group1);
- $this->resetParams();
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- \OC_Group::addToGroup($user1, 'admin');
- $_POST['groupid'] = 'admin';
- $result = \OCA\provisioning_api\Users::addSubAdmin(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertEquals(103, $result->getStatusCode());
- $this->assertFalse($result->succeeded());
- $this->resetParams();
- $user1 = $this->generateUsers();
- \OC_User::setUserId($user1);
- \OC_Group::addToGroup($user1, 'admin');
- $group1 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- $_POST['groupid'] = $group1;
- $result = \OCA\provisioning_api\Users::addSubAdmin(array(
- 'userid' => $this->getUniqueID(),
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertEquals(101, $result->getStatusCode());
- \OC_Group::deleteGroup($group1);
- }
- public function testRemoveSubAdmin() {
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- \OC_Group::addToGroup($user1, 'admin');
- $group1 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_SubAdmin::createSubAdmin($user2, $group1);
- $result = \OCA\provisioning_api\Users::removeSubAdmin(array(
- 'userid' => $user2,
- '_delete' => array(
- 'groupid' => $group1,
- ),
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $this->assertTrue(!\OC_SubAdmin::isSubAdminofGroup($user2, $group1));
- \OC_Group::deleteGroup($group1);
- $user1 = $this->generateUsers();
- \OC_User::setUserId($user1);
- \OC_Group::addToGroup($user1, 'admin');
- $result = \OCA\provisioning_api\Users::removeSubAdmin(array(
- 'userid' => $this->getUniqueID(),
- '_delete' => array(
- 'groupid' => $group1,
- ),
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertEquals(101, $result->getStatusCode());
- $this->assertFalse($result->succeeded());
- $this->resetParams();
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- \OC_Group::addToGroup($user1, 'admin');
- $group1 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- $_POST['groupid'] = $group1;
- $result = \OCA\provisioning_api\Users::removeSubAdmin(array(
- 'userid' => $user2,
- '_delete' => array(
- 'groupid' => $group1,
- ),
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertEquals(102, $result->getStatusCode());
- \OC_Group::deleteGroup($group1);
- }
- public function testGetSubAdminGroups() {
- $user1 = $this->generateUsers();
- $user2 = $this->generateUsers();
- \OC_User::setUserId($user1);
- \OC_Group::addToGroup($user1, 'admin');
- $group1 = $this->getUniqueID();
- \OC_Group::createGroup($group1);
- \OC_SubAdmin::createSubAdmin($user2, $group1);
- $result = \OCA\provisioning_api\Users::getUserSubAdminGroups(array(
- 'userid' => $user2,
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $this->assertEquals($group1, reset($data));
- \OC_Group::deleteGroup($group1);
- $user1 = $this->generateUsers();
- \OC_User::setUserId($user1);
- \OC_Group::addToGroup($user1, 'admin');
- $group1 = $this->getUniqueID();
- $result = \OCA\provisioning_api\Users::getUserSubAdminGroups(array(
- 'userid' => $this->getUniqueID(),
- ));
- $this->assertInstanceOf('OC_OCS_Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertEquals(101, $result->getStatusCode());
- }
- }
|