diff options
Diffstat (limited to 'build/integration/features/bootstrap/Provisioning.php')
-rw-r--r-- | build/integration/features/bootstrap/Provisioning.php | 612 |
1 files changed, 519 insertions, 93 deletions
diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php index feeb850ae7d..935ad2a4a1d 100644 --- a/build/integration/features/bootstrap/Provisioning.php +++ b/build/integration/features/bootstrap/Provisioning.php @@ -1,7 +1,15 @@ <?php +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +use Behat\Gherkin\Node\TableNode; use GuzzleHttp\Client; use GuzzleHttp\Message\ResponseInterface; +use PHPUnit\Framework\Assert; require __DIR__ . '/../../vendor/autoload.php'; @@ -16,7 +24,7 @@ trait Provisioning { /** @var array */ private $createdRemoteGroups = []; - + /** @var array */ private $createdGroups = []; @@ -29,13 +37,29 @@ trait Provisioning { $this->userExists($user); } catch (\GuzzleHttp\Exception\ClientException $ex) { $previous_user = $this->currentUser; - $this->currentUser = "admin"; + $this->currentUser = 'admin'; $this->creatingTheUser($user); $this->currentUser = $previous_user; } $this->userExists($user); - PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + Assert::assertEquals(200, $this->response->getStatusCode()); + } + /** + * @Given /^user "([^"]*)" with displayname "((?:[^"]|\\")*)" exists$/ + * @param string $user + */ + public function assureUserWithDisplaynameExists($user, $displayname) { + try { + $this->userExists($user); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + $previous_user = $this->currentUser; + $this->currentUser = 'admin'; + $this->creatingTheUser($user, $displayname); + $this->currentUser = $previous_user; + } + $this->userExists($user); + Assert::assertEquals(200, $this->response->getStatusCode()); } /** @@ -47,22 +71,22 @@ trait Provisioning { $this->userExists($user); } catch (\GuzzleHttp\Exception\ClientException $ex) { $this->response = $ex->getResponse(); - PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); + Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); return; } $previous_user = $this->currentUser; - $this->currentUser = "admin"; + $this->currentUser = 'admin'; $this->deletingTheUser($user); $this->currentUser = $previous_user; try { $this->userExists($user); } catch (\GuzzleHttp\Exception\ClientException $ex) { $this->response = $ex->getResponse(); - PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); + Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); } } - public function creatingTheUser($user) { + public function creatingTheUser($user, $displayname = '') { $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users"; $client = new Client(); $options = []; @@ -70,13 +94,19 @@ trait Provisioning { $options['auth'] = $this->adminUser; } - $options['body'] = [ - 'userid' => $user, - 'password' => '123456' - ]; + $options['form_params'] = [ + 'userid' => $user, + 'password' => '123456' + ]; + if ($displayname !== '') { + $options['form_params']['displayName'] = $displayname; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; - $this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); - if ($this->currentServer === 'LOCAL'){ + $this->response = $client->post($fullUrl, $options); + if ($this->currentServer === 'LOCAL') { $this->createdUsers[$user] = $user; } elseif ($this->currentServer === 'REMOTE') { $this->createdRemoteUsers[$user] = $user; @@ -86,13 +116,175 @@ trait Provisioning { $options2 = [ 'auth' => [$user, '123456'], ]; - $url = $fullUrl.'/'.$user; - $client->send($client->createRequest('GET', $url, $options2)); + $options2['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + $url = $fullUrl . '/' . $user; + $client->get($url, $options2); + } + + /** + * @Then /^user "([^"]*)" has$/ + * + * @param string $user + * @param TableNode|null $settings + */ + public function userHasSetting($user, $settings) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } else { + $options['auth'] = [$this->currentUser, $this->regularUser]; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + + $response = $client->get($fullUrl, $options); + foreach ($settings->getRows() as $setting) { + $value = json_decode(json_encode(simplexml_load_string($response->getBody())->data->{$setting[0]}), 1); + if (isset($value['element']) && in_array($setting[0], ['additional_mail', 'additional_mailScope'], true)) { + $expectedValues = explode(';', $setting[1]); + foreach ($expectedValues as $expected) { + Assert::assertTrue(in_array($expected, $value['element'], true), 'Data wrong for field: ' . $setting[0]); + } + } elseif (isset($value[0])) { + Assert::assertEqualsCanonicalizing($setting[1], $value[0], 'Data wrong for field: ' . $setting[0]); + } else { + Assert::assertEquals('', $setting[1], 'Data wrong for field: ' . $setting[0]); + } + } + } + + /** + * @Then /^user "([^"]*)" has the following profile data$/ + */ + public function userHasProfileData(string $user, ?TableNode $settings): void { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/profile/$user"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } else { + $options['auth'] = [$this->currentUser, $this->regularUser]; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + 'Accept' => 'application/json', + ]; + + $response = $client->get($fullUrl, $options); + $body = $response->getBody()->getContents(); + $data = json_decode($body, true); + $data = $data['ocs']['data']; + foreach ($settings->getRows() as $setting) { + Assert::assertArrayHasKey($setting[0], $data, 'Profile data field missing: ' . $setting[0]); + if ($setting[1] === 'NULL') { + Assert::assertNull($data[$setting[0]], 'Profile data wrong for field: ' . $setting[0]); + } else { + Assert::assertEquals($setting[1], $data[$setting[0]], 'Profile data wrong for field: ' . $setting[0]); + } + } + } + + /** + * @Then /^group "([^"]*)" has$/ + * + * @param string $user + * @param TableNode|null $settings + */ + public function groupHasSetting($group, $settings) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/details?search=$group"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } else { + $options['auth'] = [$this->currentUser, $this->regularUser]; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + + $response = $client->get($fullUrl, $options); + $groupDetails = simplexml_load_string($response->getBody())->data[0]->groups[0]->element; + foreach ($settings->getRows() as $setting) { + $value = json_decode(json_encode($groupDetails->{$setting[0]}), 1); + if (isset($value[0])) { + Assert::assertEqualsCanonicalizing($setting[1], $value[0]); + } else { + Assert::assertEquals('', $setting[1]); + } + } + } + + + /** + * @Then /^user "([^"]*)" has editable fields$/ + * + * @param string $user + * @param TableNode|null $fields + */ + public function userHasEditableFields($user, $fields) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/user/fields"; + if ($user !== 'self') { + $fullUrl .= '/' . $user; + } + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } else { + $options['auth'] = [$this->currentUser, $this->regularUser]; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + + $response = $client->get($fullUrl, $options); + $fieldsArray = json_decode(json_encode(simplexml_load_string($response->getBody())->data->element), 1); + + $expectedFields = $fields->getRows(); + $expectedFields = $this->simplifyArray($expectedFields); + Assert::assertEquals($expectedFields, $fieldsArray); + } + + /** + * @Then /^search users by phone for region "([^"]*)" with$/ + * + * @param string $user + * @param TableNode|null $settings + */ + public function searchUserByPhone($region, TableNode $searchTable) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/search/by-phone"; + $client = new Client(); + $options = []; + $options['auth'] = $this->adminUser; + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + + $search = []; + foreach ($searchTable->getRows() as $row) { + if (!isset($search[$row[0]])) { + $search[$row[0]] = []; + } + $search[$row[0]][] = $row[1]; + } + + $options['form_params'] = [ + 'location' => $region, + 'search' => $search, + ]; + + $this->response = $client->post($fullUrl, $options); } public function createUser($user) { $previous_user = $this->currentUser; - $this->currentUser = "admin"; + $this->currentUser = 'admin'; $this->creatingTheUser($user); $this->userExists($user); $this->currentUser = $previous_user; @@ -100,7 +292,7 @@ trait Provisioning { public function deleteUser($user) { $previous_user = $this->currentUser; - $this->currentUser = "admin"; + $this->currentUser = 'admin'; $this->deletingTheUser($user); $this->userDoesNotExist($user); $this->currentUser = $previous_user; @@ -108,7 +300,7 @@ trait Provisioning { public function createGroup($group) { $previous_user = $this->currentUser; - $this->currentUser = "admin"; + $this->currentUser = 'admin'; $this->creatingTheGroup($group); $this->groupExists($group); $this->currentUser = $previous_user; @@ -116,17 +308,20 @@ trait Provisioning { public function deleteGroup($group) { $previous_user = $this->currentUser; - $this->currentUser = "admin"; + $this->currentUser = 'admin'; $this->deletingTheGroup($group); $this->groupDoesNotExist($group); $this->currentUser = $previous_user; } - public function userExists($user){ + public function userExists($user) { $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user"; $client = new Client(); $options = []; $options['auth'] = $this->adminUser; + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true' + ]; $this->response = $client->get($fullUrl, $options); } @@ -143,12 +338,15 @@ trait Provisioning { if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; $this->response = $client->get($fullUrl, $options); $respondedArray = $this->getArrayOfGroupsResponded($this->response); sort($respondedArray); - PHPUnit_Framework_Assert::assertContains($group, $respondedArray); - PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + Assert::assertContains($group, $respondedArray); + Assert::assertEquals(200, $this->response->getStatusCode()); } public function userBelongsToGroup($user, $group) { @@ -158,14 +356,17 @@ trait Provisioning { if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; $this->response = $client->get($fullUrl, $options); $respondedArray = $this->getArrayOfGroupsResponded($this->response); if (array_key_exists($group, $respondedArray)) { - return True; - } else{ - return False; + return true; + } else { + return false; } } @@ -174,11 +375,11 @@ trait Provisioning { * @param string $user * @param string $group */ - public function assureUserBelongsToGroup($user, $group){ + public function assureUserBelongsToGroup($user, $group) { $previous_user = $this->currentUser; - $this->currentUser = "admin"; + $this->currentUser = 'admin'; - if (!$this->userBelongsToGroup($user, $group)){ + if (!$this->userBelongsToGroup($user, $group)) { $this->addingUserToGroup($user, $group); } @@ -198,12 +399,15 @@ trait Provisioning { if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; $this->response = $client->get($fullUrl, $options); - $groups = array($group); + $groups = [$group]; $respondedArray = $this->getArrayOfGroupsResponded($this->response); - PHPUnit_Framework_Assert::assertNotEquals($groups, $respondedArray, "", 0.0, 10, true); - PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + Assert::assertNotEqualsCanonicalizing($groups, $respondedArray); + Assert::assertEquals(200, $this->response->getStatusCode()); } /** @@ -218,12 +422,15 @@ trait Provisioning { $options['auth'] = $this->adminUser; } - $options['body'] = [ - 'groupid' => $group, - ]; + $options['form_params'] = [ + 'groupid' => $group, + ]; + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; - $this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); - if ($this->currentServer === 'LOCAL'){ + $this->response = $client->post($fullUrl, $options); + if ($this->currentServer === 'LOCAL') { $this->createdGroups[$group] = $group; } elseif ($this->currentServer === 'REMOTE') { $this->createdRemoteGroups[$group] = $group; @@ -231,6 +438,27 @@ trait Provisioning { } /** + * @When /^assure user "([^"]*)" is disabled$/ + */ + public function assureUserIsDisabled($user) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/disable"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + // TODO: fix hack + $options['form_params'] = [ + 'foo' => 'bar' + ]; + + $this->response = $client->put($fullUrl, $options); + } + + /** * @When /^Deleting the user "([^"]*)"$/ * @param string $user */ @@ -241,8 +469,11 @@ trait Provisioning { if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; - $this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options)); + $this->response = $client->delete($fullUrl, $options); } /** @@ -256,8 +487,17 @@ trait Provisioning { if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; - $this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options)); + $this->response = $client->delete($fullUrl, $options); + + if ($this->currentServer === 'LOCAL') { + unset($this->createdGroups[$group]); + } elseif ($this->currentServer === 'REMOTE') { + unset($this->createdRemoteGroups[$group]); + } } /** @@ -269,7 +509,6 @@ trait Provisioning { $this->userExists($user); $this->groupExists($group); $this->addingUserToGroup($user, $group); - } /** @@ -284,12 +523,15 @@ trait Provisioning { if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; - $options['body'] = [ - 'groupid' => $group, - ]; + $options['form_params'] = [ + 'groupid' => $group, + ]; - $this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); + $this->response = $client->post($fullUrl, $options); } @@ -298,6 +540,9 @@ trait Provisioning { $client = new Client(); $options = []; $options['auth'] = $this->adminUser; + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; $this->response = $client->get($fullUrl, $options); } @@ -311,12 +556,12 @@ trait Provisioning { $this->groupExists($group); } catch (\GuzzleHttp\Exception\ClientException $ex) { $previous_user = $this->currentUser; - $this->currentUser = "admin"; + $this->currentUser = 'admin'; $this->creatingTheGroup($group); $this->currentUser = $previous_user; } $this->groupExists($group); - PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + Assert::assertEquals(200, $this->response->getStatusCode()); } /** @@ -328,18 +573,18 @@ trait Provisioning { $this->groupExists($group); } catch (\GuzzleHttp\Exception\ClientException $ex) { $this->response = $ex->getResponse(); - PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); + Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); return; } $previous_user = $this->currentUser; - $this->currentUser = "admin"; + $this->currentUser = 'admin'; $this->deletingTheGroup($group); $this->currentUser = $previous_user; try { $this->groupExists($group); } catch (\GuzzleHttp\Exception\ClientException $ex) { $this->response = $ex->getResponse(); - PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); + Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); } } @@ -355,12 +600,37 @@ trait Provisioning { if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; $this->response = $client->get($fullUrl, $options); $respondedArray = $this->getArrayOfSubadminsResponded($this->response); sort($respondedArray); - PHPUnit_Framework_Assert::assertContains($user, $respondedArray); - PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + Assert::assertContains($user, $respondedArray); + Assert::assertEquals(200, $this->response->getStatusCode()); + } + + /** + * @Given /^Assure user "([^"]*)" is subadmin of group "([^"]*)"$/ + * @param string $user + * @param string $group + */ + public function assureUserIsSubadminOfGroup($user, $group) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/subadmins"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + $options['form_params'] = [ + 'groupid' => $group + ]; + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + $this->response = $client->post($fullUrl, $options); + Assert::assertEquals(200, $this->response->getStatusCode()); } /** @@ -375,73 +645,99 @@ trait Provisioning { if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; $this->response = $client->get($fullUrl, $options); $respondedArray = $this->getArrayOfSubadminsResponded($this->response); sort($respondedArray); - PHPUnit_Framework_Assert::assertNotContains($user, $respondedArray); - PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + Assert::assertNotContains($user, $respondedArray); + Assert::assertEquals(200, $this->response->getStatusCode()); } /** * @Then /^users returned are$/ - * @param \Behat\Gherkin\Node\TableNode|null $usersList + * @param TableNode|null $usersList */ public function theUsersShouldBe($usersList) { - if ($usersList instanceof \Behat\Gherkin\Node\TableNode) { + if ($usersList instanceof TableNode) { $users = $usersList->getRows(); $usersSimplified = $this->simplifyArray($users); $respondedArray = $this->getArrayOfUsersResponded($this->response); - PHPUnit_Framework_Assert::assertEquals($usersSimplified, $respondedArray, "", 0.0, 10, true); + Assert::assertEqualsCanonicalizing($usersSimplified, $respondedArray); } + } + /** + * @Then /^phone matches returned are$/ + * @param TableNode|null $usersList + */ + public function thePhoneUsersShouldBe($usersList) { + if ($usersList instanceof TableNode) { + $users = $usersList->getRowsHash(); + $listCheckedElements = simplexml_load_string($this->response->getBody())->data; + $respondedArray = json_decode(json_encode($listCheckedElements), true); + Assert::assertEquals($users, $respondedArray); + } + } + + /** + * @Then /^detailed users returned are$/ + * @param TableNode|null $usersList + */ + public function theDetailedUsersShouldBe($usersList) { + if ($usersList instanceof TableNode) { + $users = $usersList->getRows(); + $usersSimplified = $this->simplifyArray($users); + $respondedArray = $this->getArrayOfDetailedUsersResponded($this->response); + $respondedArray = array_keys($respondedArray); + Assert::assertEquals($usersSimplified, $respondedArray); + } } /** * @Then /^groups returned are$/ - * @param \Behat\Gherkin\Node\TableNode|null $groupsList + * @param TableNode|null $groupsList */ public function theGroupsShouldBe($groupsList) { - if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) { + if ($groupsList instanceof TableNode) { $groups = $groupsList->getRows(); $groupsSimplified = $this->simplifyArray($groups); $respondedArray = $this->getArrayOfGroupsResponded($this->response); - PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true); + Assert::assertEqualsCanonicalizing($groupsSimplified, $respondedArray); } - } /** * @Then /^subadmin groups returned are$/ - * @param \Behat\Gherkin\Node\TableNode|null $groupsList + * @param TableNode|null $groupsList */ public function theSubadminGroupsShouldBe($groupsList) { - if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) { + if ($groupsList instanceof TableNode) { $groups = $groupsList->getRows(); $groupsSimplified = $this->simplifyArray($groups); $respondedArray = $this->getArrayOfSubadminsResponded($this->response); - PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true); + Assert::assertEqualsCanonicalizing($groupsSimplified, $respondedArray); } - } /** * @Then /^apps returned are$/ - * @param \Behat\Gherkin\Node\TableNode|null $appList + * @param TableNode|null $appList */ public function theAppsShouldBe($appList) { - if ($appList instanceof \Behat\Gherkin\Node\TableNode) { + if ($appList instanceof TableNode) { $apps = $appList->getRows(); $appsSimplified = $this->simplifyArray($apps); $respondedArray = $this->getArrayOfAppsResponded($this->response); - PHPUnit_Framework_Assert::assertEquals($appsSimplified, $respondedArray, "", 0.0, 10, true); + Assert::assertEqualsCanonicalizing($appsSimplified, $respondedArray); } - } /** * @Then /^subadmin users returned are$/ - * @param \Behat\Gherkin\Node\TableNode|null $groupsList + * @param TableNode|null $groupsList */ public function theSubadminUsersShouldBe($groupsList) { $this->theSubadminGroupsShouldBe($groupsList); @@ -449,44 +745,60 @@ trait Provisioning { /** * Parses the xml answer to get the array of users returned. + * * @param ResponseInterface $resp * @return array */ public function getArrayOfUsersResponded($resp) { - $listCheckedElements = $resp->xml()->data[0]->users[0]->element; + $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->users[0]->element; + $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); + return $extractedElementsArray; + } + + /** + * Parses the xml answer to get the array of detailed users returned. + * + * @param ResponseInterface $resp + * @return array + */ + public function getArrayOfDetailedUsersResponded($resp) { + $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->users; $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); return $extractedElementsArray; } /** * Parses the xml answer to get the array of groups returned. + * * @param ResponseInterface $resp * @return array */ public function getArrayOfGroupsResponded($resp) { - $listCheckedElements = $resp->xml()->data[0]->groups[0]->element; + $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->groups[0]->element; $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); return $extractedElementsArray; } /** * Parses the xml answer to get the array of apps returned. + * * @param ResponseInterface $resp * @return array */ public function getArrayOfAppsResponded($resp) { - $listCheckedElements = $resp->xml()->data[0]->apps[0]->element; + $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->apps[0]->element; $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); return $extractedElementsArray; } /** * Parses the xml answer to get the array of subadmins returned. + * * @param ResponseInterface $resp * @return array */ public function getArrayOfSubadminsResponded($resp) { - $listCheckedElements = $resp->xml()->data[0]->element; + $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->element; $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); return $extractedElementsArray; } @@ -497,17 +809,20 @@ trait Provisioning { * @param string $app */ public function appIsDisabled($app) { - $fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=disabled"; + $fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=disabled'; $client = new Client(); $options = []; if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; $this->response = $client->get($fullUrl, $options); $respondedArray = $this->getArrayOfAppsResponded($this->response); - PHPUnit_Framework_Assert::assertContains($app, $respondedArray); - PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + Assert::assertContains($app, $respondedArray); + Assert::assertEquals(200, $this->response->getStatusCode()); } /** @@ -515,17 +830,84 @@ trait Provisioning { * @param string $app */ public function appIsEnabled($app) { - $fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=enabled"; + $fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=enabled'; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + + $this->response = $client->get($fullUrl, $options); + $respondedArray = $this->getArrayOfAppsResponded($this->response); + Assert::assertContains($app, $respondedArray); + Assert::assertEquals(200, $this->response->getStatusCode()); + } + + /** + * @Given /^app "([^"]*)" is not enabled$/ + * + * Checks that the app is disabled or not installed. + * + * @param string $app + */ + public function appIsNotEnabled($app) { + $fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=enabled'; $client = new Client(); $options = []; if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; $this->response = $client->get($fullUrl, $options); $respondedArray = $this->getArrayOfAppsResponded($this->response); - PHPUnit_Framework_Assert::assertContains($app, $respondedArray); - PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + Assert::assertNotContains($app, $respondedArray); + Assert::assertEquals(200, $this->response->getStatusCode()); + } + + /** + * @Then /^user "([^"]*)" is disabled$/ + * @param string $user + */ + public function userIsDisabled($user) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + + $this->response = $client->get($fullUrl, $options); + // false in xml is empty + Assert::assertTrue(empty(simplexml_load_string($this->response->getBody())->data[0]->enabled)); + } + + /** + * @Then /^user "([^"]*)" is enabled$/ + * @param string $user + */ + public function userIsEnabled($user) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + + $this->response = $client->get($fullUrl, $options); + // boolean to string is integer + Assert::assertEquals('1', simplexml_load_string($this->response->getBody())->data[0]->enabled); } /** @@ -533,39 +915,50 @@ trait Provisioning { * @param string $user * @param string $quota */ - public function userHasAQuotaOf($user, $quota) - { - $body = new \Behat\Gherkin\Node\TableNode([ + public function userHasAQuotaOf($user, $quota) { + $body = new TableNode([ 0 => ['key', 'quota'], 1 => ['value', $quota], ]); // method used from BasicStructure trait - $this->sendingToWith("PUT", "/cloud/users/" . $user, $body); + $this->sendingToWith('PUT', '/cloud/users/' . $user, $body); } /** * @Given user :user has unlimited quota * @param string $user */ - public function userHasUnlimitedQuota($user) - { + public function userHasUnlimitedQuota($user) { $this->userHasAQuotaOf($user, 'none'); } /** + * Returns home path of the given user + * + * @param string $user + */ + public function getUserHome($user) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user"; + $client = new Client(); + $options = []; + $options['auth'] = $this->adminUser; + $this->response = $client->get($fullUrl, $options); + return simplexml_load_string($this->response->getBody())->data[0]->home; + } + + /** * @BeforeScenario * @AfterScenario */ - public function cleanupUsers() - { + public function cleanupUsers() { $previousServer = $this->currentServer; $this->usingServer('LOCAL'); - foreach($this->createdUsers as $user) { + foreach ($this->createdUsers as $user) { $this->deleteUser($user); } $this->usingServer('REMOTE'); - foreach($this->createdRemoteUsers as $remoteUser) { + foreach ($this->createdRemoteUsers as $remoteUser) { $this->deleteUser($remoteUser); } $this->usingServer($previousServer); @@ -575,17 +968,50 @@ trait Provisioning { * @BeforeScenario * @AfterScenario */ - public function cleanupGroups() - { + public function cleanupGroups() { $previousServer = $this->currentServer; $this->usingServer('LOCAL'); - foreach($this->createdGroups as $group) { + foreach ($this->createdGroups as $group) { $this->deleteGroup($group); } $this->usingServer('REMOTE'); - foreach($this->createdRemoteGroups as $remoteGroup) { - $this->deleteUser($remoteGroup); + foreach ($this->createdRemoteGroups as $remoteGroup) { + $this->deleteGroup($remoteGroup); } $this->usingServer($previousServer); } + + /** + * @Then /^user "([^"]*)" has not$/ + */ + public function userHasNotSetting($user, TableNode $settings) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } else { + $options['auth'] = [$this->currentUser, $this->regularUser]; + } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + + $response = $client->get($fullUrl, $options); + foreach ($settings->getRows() as $setting) { + $value = json_decode(json_encode(simplexml_load_string($response->getBody())->data->{$setting[0]}), 1); + if (isset($value[0])) { + if (in_array($setting[0], ['additional_mail', 'additional_mailScope'], true)) { + $expectedValues = explode(';', $setting[1]); + foreach ($expectedValues as $expected) { + Assert::assertFalse(in_array($expected, $value, true)); + } + } else { + Assert::assertNotEqualsCanonicalizing($setting[1], $value[0]); + } + } else { + Assert::assertNotEquals('', $setting[1]); + } + } + } } |