From 76cc388e4546d4e588515c6c7d624829a674163a Mon Sep 17 00:00:00 2001 From: Amrita <54478846+amrita-shrestha@users.noreply.github.com> Date: Fri, 31 Mar 2023 08:59:25 +0545 Subject: [PATCH] Expand tests scenario for adding multiple user at once (#5864) (#5963) --- ...ected-failures-localAPI-on-OCIS-storage.md | 7 +- .../features/apiGraph/addUserToGroup.feature | 41 +++++++++ .../features/bootstrap/GraphContext.php | 84 ++++++++++++++++++- 3 files changed, 128 insertions(+), 4 deletions(-) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 65056b0654..ba7e72b6f3 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -161,6 +161,8 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiGraph/removeUserFromGroup.feature:172](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L172) - [apiGraph/removeUserFromGroup.feature:173](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L173) - [apiGraph/removeUserFromGroup.feature:174](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L174) +- [apiSpaces/createSpace.feature:18](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/createSpace.feature#L18) +- [apiSpaces/createSpace.feature:19](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/createSpace.feature#L19) #### [API requests for a non-existent resources should return 404](https://github.com/owncloud/ocis/issues/5939) - [apiGraph/addUserToGroup.feature:162](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L162) @@ -174,9 +176,8 @@ The expected failures in this file are from features in the owncloud/ocis repo. #### [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) -#### [https://github.com/owncloud/ocis/issues/5938](https://github.com/owncloud/ocis/issues/5938) -- [apiSpaces/createSpace.feature:18](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/createSpace.feature#L18) -- [apiSpaces/createSpace.feature:19](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/createSpace.feature#L19) +### [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:367](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L367) 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 5c8ec22c62..9b1d9fd0a4 100644 --- a/tests/acceptance/features/apiGraph/addUserToGroup.feature +++ b/tests/acceptance/features/apiGraph/addUserToGroup.feature @@ -335,3 +335,44 @@ Feature: add users to group 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" + + + Scenario Outline: try to add invalid user id to a group + Given the administrator has given "Alice" the role "Admin" using the settings api + And user "Alice" has created a group "grp1" using the Graph API + When the administrator "Alice" tries to add an invalid user id "" to a group "grp1" using the Graph API + Then the HTTP status code should be "404" + Examples: + | invalid-uuidv4 | comment | + | �ϰ�Ϧ-@$@^-¶Ëøœ-ɧɸɱʨΌϖЁϿ | UTF characters | + | 4c510ada-c86b-4815-8820-42cdf82c3d511 | adding an extra character at end of valid UUID pattern | + | 4c510adac8-6b-4815-882042cdf-82c3d51 | invalid UUID pattern | + + + Scenario Outline: try to add invalid user ids to a group at once + Given the administrator has given "Alice" the role "Admin" using the settings api + And user "Alice" has created a group "grp1" using the Graph API + When the administrator "Alice" tries to add the following invalid user ids to a group "grp1" at once using the Graph API + | user-id | + | | + | | + Then the HTTP status code should be "404" + Examples: + | invalid-uuidv4 | comment | + | �ϰ�Ϧ-@$@^-¶Ëøœ-ɧɸɱʨΌϖЁϿ | UTF characters | + | 4c510ada-c86b-4815-8820-42cdf82c3d511 | adding an extra character at end of valid UUID pattern | + | 4c510adac8-6b-4815-882042cdf-82c3d51 | invalid UUID pattern | + + @issue-5855 + Scenario: add same user twice to a group at once + 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 the administrator "Alice" adds the following users to a group "grp1" at once using the Graph API + | username | + | Brian | + | Brian | + Then the HTTP status code should be "204" + And the user "Brian" should be listed once in the group "grp1" diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 56622a0881..efe666e713 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -1792,7 +1792,7 @@ class GraphContext implements Context { $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"); } @@ -2356,4 +2356,86 @@ class GraphContext implements Context { ) ); } + + /** + * @When /^the administrator "([^"]*)" tries to add the following invalid user ids to a group "([^"]*)" at once using the Graph API$/ + * + * @param string $user + * @param string $group + * @param TableNode $table + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function theAdministratorTriesToAddTheFollowingUserIdWithInvalidCharacterToAGroup(string $user, string $group, TableNode $table) { + $userIds = []; + $credentials = $this->getAdminOrUserCredentials($user); + $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); + foreach ($table->getHash() as $row) { + $userIds[] = \implode(" ", $row); + } + $this->featureContext->setResponse( + GraphHelper::addUsersToGroup( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials["username"], + $credentials["password"], + $groupId, + $userIds + ) + ); + } + + /** + * @When /^the administrator "([^"]*)" tries to add an invalid user id "([^"]*)" to a group "([^"]*)" using the Graph API$/ + * + * @param string $user + * @param string $userId + * @param string $group + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function theAdministratorTriesToAddUserIdWithInvalidCharactersToAGroup(string $user, string $userId, string $group): void { + $credentials = $this->getAdminOrUserCredentials($user); + $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); + $this->featureContext->setResponse( + GraphHelper::addUserToGroup( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials['username'], + $credentials['password'], + $userId, + $groupId + ) + ); + } + + /** + * @Then the user :user should be listed once in the group :group + * + * @param string $user + * @param string $group + * + * @return void + * @throws GuzzleException + */ + public function theUsersShouldBeListedOnceToAGroup(string $user, string $group): void { + $count = 0; + $members = $this->listGroupMembers($group); + $members = $this->featureContext->getJsonDecodedResponse($members); + + foreach ($members as $member) { + if ($member['onPremisesSamAccountName'] === $user) { + $count++; + } + } + Assert::assertEquals( + 1, + $count, + "Expected user '" . $user . "' to be added once to group '" . $group . "' but the user is listed '" . $count . "' times" + ); + } }