From c5f768153ad773f3ff39dbad3b81819c4959ae56 Mon Sep 17 00:00:00 2001 From: Nalem7 <61624650+nabim777@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:58:51 +0545 Subject: [PATCH] [tests-only][full-ci] Restructure the steps implementation for group delete to use graph API endpoint (#8006) (#8227) * remove ocs endpoint from delete group * remove adminHasDeletedGroupUsingTheGraphApi * adressing reviews --- tests/TestHelpers/UserHelper.php | 62 ---------- .../features/bootstrap/GraphContext.php | 33 +----- .../features/bootstrap/Provisioning.php | 111 +----------------- .../createShareToSharesFolder.feature | 10 +- 4 files changed, 15 insertions(+), 201 deletions(-) diff --git a/tests/TestHelpers/UserHelper.php b/tests/TestHelpers/UserHelper.php index 33de75b374..e38e05981a 100644 --- a/tests/TestHelpers/UserHelper.php +++ b/tests/TestHelpers/UserHelper.php @@ -188,68 +188,6 @@ class UserHelper { ); } - /** - * - * @param string|null $baseUrl - * @param string|null $group - * @param string|null $adminUser - * @param string|null $adminPassword - * @param string|null $xRequestId - * - * @return ResponseInterface - * @throws GuzzleException - */ - public static function createGroup( - ?string $baseUrl, - ?string $group, - ?string $adminUser, - ?string $adminPassword, - ?string $xRequestId = '' - ):ResponseInterface { - return OcsApiHelper::sendRequest( - $baseUrl, - $adminUser, - $adminPassword, - "POST", - "/cloud/groups", - $xRequestId, - ['groupid' => $group] - ); - } - - /** - * - * @param string|null $baseUrl - * @param string|null $group - * @param string|null $adminUser - * @param string|null $adminPassword - * @param string|null $xRequestId - * @param int|null $ocsApiVersion - * - * @return ResponseInterface - * @throws GuzzleException - */ - public static function deleteGroup( - ?string $baseUrl, - ?string $group, - ?string $adminUser, - ?string $adminPassword, - ?string $xRequestId = '', - ?int $ocsApiVersion = 2 - ):ResponseInterface { - $group = \rawurlencode($group); - return OcsApiHelper::sendRequest( - $baseUrl, - $adminUser, - $adminPassword, - "DELETE", - "/cloud/groups/" . $group, - $xRequestId, - [], - $ocsApiVersion - ); - } - /** * * @param string|null $baseUrl diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 79c174f784..aee5618c25 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -287,21 +287,15 @@ class GraphContext implements Context { /** * @param string $groupId - * @param bool $checkResult * * @return void * @throws GuzzleException */ public function adminDeletesGroupWithGroupId( - string $groupId, - bool $checkResult = false + string $groupId ): void { - $this->featureContext->setResponse( - $this->userDeletesGroupWithGroupId($groupId) - ); - if ($checkResult) { - $this->featureContext->thenTheHTTPStatusCodeShouldBe(204); - } + $response = $this->userDeletesGroupWithGroupId($groupId); + $this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response); } /** @@ -315,26 +309,7 @@ class GraphContext implements Context { string $group ): void { $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); - if ($groupId) { - $this->adminDeletesGroupWithGroupId($groupId); - } else { - throw new Exception( - "Group id does not exist for '$group' in the created list." - . " Cannot delete group without id when using the Graph API." - ); - } - } - - /** - * @param string $group - * - * @return void - * @throws Exception - * @throws GuzzleException - */ - public function adminHasDeletedGroupUsingTheGraphApi(string $group): void { - $this->adminDeletesGroupUsingTheGraphApi($group); - $this->featureContext->thenTheHTTPStatusCodeShouldBe(204); + $this->adminDeletesGroupWithGroupId($groupId); } /** diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 04bbad86c4..1ef51bd4bf 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -2672,10 +2672,10 @@ trait Provisioning { */ public function cleanupGroup(string $group):void { try { - if (OcisHelper::isTestingWithGraphApi()) { - $this->graphContext->adminHasDeletedGroupUsingTheGraphApi($group); + if ($this->isTestingWithLdap()) { + $this->deleteLdapGroup($group); } else { - $this->deleteTheGroupUsingTheProvisioningApi($group); + $this->graphContext->adminDeletesGroupUsingTheGraphApi($group); } } catch (Exception $e) { \error_log( @@ -3467,23 +3467,6 @@ trait Provisioning { return $response; } - /** - * @param string $group group name - * - * @return void - * @throws Exception - * @throws LdapException - */ - public function deleteGroup(string $group):void { - if ($this->groupExists($group)) { - if ($this->isTestingWithLdap() && \in_array($group, $this->ldapCreatedGroups)) { - $this->deleteLdapGroup($group); - } else { - $this->deleteTheGroupUsingTheProvisioningApi($group); - } - } - } - /** * @Given /^group "([^"]*)" has been deleted$/ * @@ -3494,96 +3477,14 @@ trait Provisioning { * @throws GuzzleException */ public function groupHasBeenDeleted(string $group):void { - if (OcisHelper::isTestingWithGraphApi()) { - $this->graphContext->adminHasDeletedGroupUsingTheGraphApi($group); + if ($this->isTestingWithLdap()) { + $this->deleteLdapGroup($group); } else { - $this->deleteGroup($group); + $this->graphContext->adminDeletesGroupUsingTheGraphApi($group); } $this->groupShouldNotExist($group); } - /** - * @When /^the administrator deletes group "([^"]*)" from the default user backend$/ - * - * @param string $group - * - * @return void - * @throws Exception - */ - public function adminDeletesGroup(string $group):void { - $this->deleteGroup($group); - $this->pushToLastStatusCodesArrays(); - } - - /** - * @When /^the administrator deletes group "([^"]*)" using the provisioning API$/ - * - * @param string $group - * - * @return void - * @throws Exception - */ - public function deleteTheGroupUsingTheProvisioningApi(string $group):void { - $this->emptyLastHTTPStatusCodesArray(); - $this->emptyLastOCSStatusCodesArray(); - $this->response = UserHelper::deleteGroup( - $this->getBaseUrl(), - $group, - $this->getAdminUsername(), - $this->getAdminPassword(), - $this->getStepLineRef(), - $this->ocsApiVersion - ); - $this->pushToLastStatusCodesArrays(); - if ($this->theGroupShouldExist($group) - && $this->theGroupShouldBeAbleToBeDeleted($group) - && ($this->response->getStatusCode() !== 200) - ) { - \error_log( - "INFORMATION: could not delete group '$group'" - . $this->response->getStatusCode() . " " . $this->response->getBody() - ); - } - - $this->rememberThatGroupIsNotExpectedToExist($group); - } - - /** - * @When the administrator deletes the following groups using the provisioning API - * - * @param TableNode $table - * - * @return void - * @throws Exception - */ - public function theAdministratorDeletesTheFollowingGroupsUsingTheProvisioningApi(TableNode $table):void { - $this->verifyTableNodeColumns($table, ["groupname"]); - $groups = $table->getHash(); - foreach ($groups as $group) { - $this->deleteTheGroupUsingTheProvisioningApi($group["groupname"]); - } - } - - /** - * @When user :user tries to delete group :group using the provisioning API - * - * @param string $user - * @param string $group - * - * @return void - * @throws JsonException - */ - public function userTriesToDeleteGroupUsingTheProvisioningApi(string $user, string $group):void { - $this->response = UserHelper::deleteGroup( - $this->getBaseUrl(), - $group, - $this->getActualUsername($user), - $this->getActualPassword($user), - $this->getStepLineRef(), - $this->ocsApiVersion - ); - } - /** * @param string $group * diff --git a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature index bc35b8aed3..8ea802c838 100644 --- a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature +++ b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature @@ -452,13 +452,13 @@ Feature: sharing Then the OCS status code should be "" And the HTTP status code should be "200" And the fields of the last response to user "Alice" sharing with group "grp1" should include - | share_with | grp1 | - | file_target | /textfile0.txt | - | path | /textfile0.txt | - | uid_owner | %username% | + | share_with | grp1 | + | file_target | /Shares/textfile0.txt | + | path | /textfile0.txt | + | uid_owner | %username% | Then as "Brian" file "/Shares/textfile0.txt" should exist And as "Carol" file "/Shares/textfile0.txt" should exist - When the administrator deletes group "grp1" using the provisioning API + When the administrator deletes group "grp1" using the Graph API And user "Alice" sends HTTP method "GET" to OCS API endpoint "/apps/files_sharing/api/v1/shares" Then the OCS status code should be "" And the HTTP status code should be "200"