From d5f85350e417700218d5ca4f3ffb06b040772152 Mon Sep 17 00:00:00 2001 From: amrita Date: Mon, 17 Apr 2023 16:05:35 +0545 Subject: [PATCH] Refactor api endpoint --- tests/TestHelpers/GraphHelper.php | 36 -------------- ...ected-failures-localAPI-on-OCIS-storage.md | 4 +- .../features/apiGraph/addUserToGroup.feature | 18 ++++++- .../features/bootstrap/GraphContext.php | 49 ++++++++++++++++--- 4 files changed, 61 insertions(+), 46 deletions(-) diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 8ea3c03b76..012fe1683e 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -573,42 +573,6 @@ class GraphHelper { ); } - /** - * tries to add a group to a group - * - * @param string $baseUrl - * @param string $xRequestId - * @param string $adminUser - * @param string $adminPassword - * @param string $groupId - * @param string $groupIdToAdd - * - * @return ResponseInterface - * @throws GuzzleException - */ - public static function addGroupToGroup( - string $baseUrl, - string $xRequestId, - string $adminUser, - string $adminPassword, - string $groupId, - string $groupIdToAdd - ): ResponseInterface { - $url = self::getFullUrl($baseUrl, 'groups/' . $groupId); - $payload = [ - "@odata.id" => self::getFullUrl($baseUrl, 'groups/' . $groupIdToAdd) - ]; - return HttpRequestHelper::sendRequest( - $url, - $xRequestId, - 'PATCH', - $adminUser, - $adminPassword, - self::getRequestHeaders(), - \json_encode($payload) - ); - } - /** * @param string $baseUrl * @param string $xRequestId diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 826e427348..f90d57a0b0 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -161,14 +161,14 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiGraph/addUserToGroup.feature:204](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L204) ### [Users are added in a group with wrong host in host-part of user](https://github.com/owncloud/ocis/issues/5871) -- [apiGraph/addUserToGroup.feature:356](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L356) - [apiGraph/addUserToGroup.feature:370](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L370) +- [apiGraph/addUserToGroup.feature:384](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L384) #### [Admin user can't restore other user spaces](https://github.com/owncloud/ocis/issues/5872) - [apiSpaces/restoreSpaces.feature:94](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/restoreSpaces.feature#L94) ### [Adding the same user as multiple members in a single request results in listing the same user twice in the group](https://github.com/owncloud/ocis/issues/5855) -- [apiGraph/addUserToGroup.feature:407](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L407) +- [apiGraph/addUserToGroup.feature:421](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L421) Note: always have an empty line at the end of this file. The bash script that processes this file requires that the last line has a newline on the end. diff --git a/tests/acceptance/features/apiGraph/addUserToGroup.feature b/tests/acceptance/features/apiGraph/addUserToGroup.feature index afdfb4a94c..468a598db3 100644 --- a/tests/acceptance/features/apiGraph/addUserToGroup.feature +++ b/tests/acceptance/features/apiGraph/addUserToGroup.feature @@ -305,7 +305,7 @@ Feature: add users to group | Carol | grp1 | @issue-5793 - Scenario: try to add a group to a group + Scenario: try to add a group to another group with PATCH request Given the administrator has given "Alice" the role "Admin" using the settings api And these users have been created with default attributes and without skeleton files: | username | @@ -315,7 +315,21 @@ Feature: add users to group | student | | music | And user "Brian" has been added to group "music" - When the administrator "Alice" tries to add a group "music" to a group "student" using the Graph API + When the administrator "Alice" tries to add a group "music" to another group "student" with PATCH request using the Graph API + Then the HTTP status code should be "400" + + @issue-5793 + Scenario: try to add a group to another group with POST request + Given the administrator has given "Alice" the role "Admin" using the settings api + And these users have been created with default attributes and without skeleton files: + | username | + | Brian | + And these groups have been created: + | groupname | + | student | + | music | + And user "Brian" has been added to group "music" + When the administrator "Alice" tries to add a group "music" to another group "student" with POST request using the Graph API Then the HTTP status code should be "400" diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index c902742616..562f938621 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -2072,7 +2072,7 @@ class GraphContext implements Context { } /** - * @When /^the administrator "([^"]*)" tries to add a group "([^"]*)" to a group "([^"]*)" using the Graph API$/ + * @When /^the administrator "([^"]*)" tries to add a group "([^"]*)" to another group "([^"]*)" with PATCH request using the Graph API$/ * * @param string $user * @param string $groupToAdd @@ -2082,19 +2082,56 @@ class GraphContext implements Context { * @throws GuzzleException * @throws Exception */ - public function theAdministratorAddGroupToAGroupAtOnceUsingTheGraphApi(string $user, string $groupToAdd, string $group) { + public function theAdministratorTriesToAddGroupToAGroupAtOnceUsingTheGraphApi(string $user, string $groupToAdd, string $group) { $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); $groupIdToAdd = $this->featureContext->getAttributeOfCreatedGroup($groupToAdd, "id"); $credentials = $this->getAdminOrUserCredentials($user); + $payload = [ + "members@odata.bind" => [GraphHelper::getFullUrl($this->featureContext->getBaseUrl(), 'groups/' . $groupIdToAdd)] + ]; + $this->featureContext->setResponse( - GraphHelper::addGroupToGroup( - $this->featureContext->getBaseUrl(), + HttpRequestHelper::sendRequest( + GraphHelper::getFullUrl($this->featureContext->getBaseUrl(), 'groups/' . $groupId), + $this->featureContext->getStepLineRef(), + 'PATCH', + $credentials["username"], + $credentials["password"], + ['Content-Type' => 'application/json'], + \json_encode($payload) + ) + ); + } + + /** + * @When /^the administrator "([^"]*)" tries to add a group "([^"]*)" to another group "([^"]*)" with POST request using the Graph API$/ + * + * @param string $user + * @param string $groupToAdd + * @param string $group + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function theAdministratorTriesToAddAGroupToAGroupThroughPostRequestUsingTheGraphApi(string $user, string $groupToAdd, string $group) { + $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); + $groupIdToAdd = $this->featureContext->getAttributeOfCreatedGroup($groupToAdd, "id"); + $credentials = $this->getAdminOrUserCredentials($user); + + $payload = [ + "@odata.id" => GraphHelper::getFullUrl($this->featureContext->getBaseUrl(), 'groups/' . $groupIdToAdd) + ]; + + $this->featureContext->setResponse( + HttpRequestHelper::post( + GraphHelper::getFullUrl($this->featureContext->getBaseUrl(), 'groups/' . $groupId . '/members/$ref'), $this->featureContext->getStepLineRef(), $credentials["username"], $credentials["password"], - $groupId, - $groupIdToAdd + ['Content-Type' => 'application/json'], + \json_encode($payload) ) ); }