From 1e5bf171fef9714c3fef2b027e40607801da6c74 Mon Sep 17 00:00:00 2001 From: Prajwol Amatya <83579989+PrajwolAmatya@users.noreply.github.com> Date: Mon, 27 Mar 2023 15:47:55 +0545 Subject: [PATCH] [tests-only][full-ci] Forwardport test for send wrong host for adding user in group (#5932) * added test for admin trying to add user with wrong host * added test for adding single user to a group with invalid hostname --- ...ected-failures-localAPI-on-OCIS-storage.md | 4 ++ .../features/apiGraph/addUserToGroup.feature | 24 +++++++ .../features/bootstrap/GraphContext.php | 71 +++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 46ef76cc3f..6ca2ca97c9 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -135,5 +135,9 @@ The expected failures in this file are from features in the owncloud/ocis repo. #### [Try to add group to a group return 204](https://github.com/owncloud/ocis/issues/5793) - [apiGraph/addUserToGroup.feature:244](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L244) +### [Users are added in a group with wrong host in host-part of user](https://github.com/owncloud/ocis/issues/5871) +- [apiGraph/addUserToGroup.feature:292](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L292) +- [apiGraph/addUserToGroup.feature:306](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L306) + 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 d0906e75c8..541b333836 100644 --- a/tests/acceptance/features/apiGraph/addUserToGroup.feature +++ b/tests/acceptance/features/apiGraph/addUserToGroup.feature @@ -287,3 +287,27 @@ Feature: add users to group | {'members@odata.bind': ['https://localhost:9200/graph/v1.0/users/%user_id%',,'https://localhost:9200/graph/v1.0/users/%user_id%']} | | {'members@odata.bind'- ['https://localhost:9200/graph/v1.0/users/%user_id%','https://localhost:9200/graph/v1.0/users/%user_id%']} | | {'members@odata.bind': ['https://localhost:9200/graph/v1.0/users/%user_id%'.'https://localhost:9200/graph/v1.0/users/%user_id%']} | + + @issue-5871 + Scenario: admin tries to add multiple users with wrong host + 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 | + | Carol | + And user "Alice" has created a group "grp1" using the Graph API + When user "Alice" tries to add the following users to a group "grp1" at once with an invalid host using the Graph API + | username | + | Brian | + | Carol | + Then the HTTP status code should be "400" + + @issue-5871 + Scenario: admin tries to add single user with wrong host + 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 user "Alice" has created a group "grp1" using the Graph API + When user "Alice" tries to add user "Brian" to group "grp1" with an invalid host 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 e17c5eb77d..52b94166f7 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -1759,6 +1759,77 @@ class GraphContext implements Context { $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); } + /** + * @When /^user "([^"]*)" tries to add the following users to a group "([^"]*)" at once with an invalid host using the Graph API$/ + * + * @param string $user + * @param string $group + * @param TableNode $table + * + * @return void + * @throws Exception + * @throws GuzzleException + */ + public function userTriesToAddTheFollowingUsersToAGroupAtOnceWithInvalidHostUsingTheGraphApi(string $user, string $group, TableNode $table): void { + $userIds = []; + $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); + $credentials = $this->getAdminOrUserCredentials($user); + $this->featureContext->verifyTableNodeColumns($table, ['username']); + + foreach ($table->getHash() as $row) { + $userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id"); + } + + $payload = [ "members@odata.bind" => [] ]; + foreach ($userIds as $userId) { + $payload["members@odata.bind"][] = GraphHelper::getFullUrl('https://invalid/', 'users/' . $userId); + } + + $this->featureContext->setResponse( + 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 /^user "([^"]*)" tries to add user "([^"]*)" to group "([^"]*)" with an invalid host using the Graph API$/ + * + * @param string $adminUser + * @param string $user + * @param string $group + * + * @return void + * @throws Exception + * @throws GuzzleException + */ + public function userTriesToAddUserToGroupWithInvalidHostUsingTheGraphApi(string $adminUser, string $user, string $group): void { + $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); + $userId = $this->featureContext->getAttributeOfCreatedUser($user, "id"); + $credentials = $this->getAdminOrUserCredentials($adminUser); + + $body = [ + "@odata.id" => GraphHelper::getFullUrl('https://invalid/', 'users/' . $userId) + ]; + + $this->featureContext->setResponse( + HttpRequestHelper::post( + GraphHelper::getFullUrl($this->featureContext->getBaseUrl(), 'groups/' . $groupId . '/members/$ref'), + $this->featureContext->getStepLineRef(), + $credentials["username"], + $credentials["password"], + ['Content-Type' => 'application/json'], + \json_encode($body) + ) + ); + } + /** * @When /^the administrator "([^"]*)" tries to add the following users to a nonexistent group at once using the Graph API$/ *