From 9f10f0d3556e3eb0459425af3ad106fa0eba9ee5 Mon Sep 17 00:00:00 2001 From: Sabin Date: Tue, 26 Sep 2023 17:15:47 +0545 Subject: [PATCH 1/8] changed user addition to group to graphapi --- .../features/bootstrap/GraphContext.php | 16 +------- .../features/bootstrap/Provisioning.php | 39 +------------------ .../createShareReceivedInMultipleWays.feature | 2 +- .../createShareToSharesFolder.feature | 2 +- 4 files changed, 5 insertions(+), 54 deletions(-) diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 9cda27ea320..a1c894a5260 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -772,7 +772,7 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void { */ public function addUserToGroup(string $group, string $user, ?string $byUser = null): ResponseInterface { $credentials = $this->getAdminOrUserCredentials($byUser); - $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); + $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id") ?: WebDavHelper::generateUUIDv4(); $userId = $this->featureContext->getAttributeOfCreatedUser($user, "id"); return GraphHelper::addUserToGroup( $this->featureContext->getBaseUrl(), @@ -847,19 +847,7 @@ public function theAdministratorTriesToAddUserToGroupUsingTheGraphAPI(string $us * @throws GuzzleException | Exception */ public function theAdministratorTriesToAddUserToNonExistentGroupUsingTheGraphAPI(string $user, ?string $byUser = null): void { - $credentials = $this->getAdminOrUserCredentials($byUser); - $groupId = WebDavHelper::generateUUIDv4(); - $userId = $this->featureContext->getAttributeOfCreatedUser($user, "id"); - $this->featureContext->setResponse( - GraphHelper::addUserToGroup( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $credentials['username'], - $credentials['password'], - $userId, - $groupId - ) - ); + $this->featureContext->setResponse($this->addUserToGroup('', $user, $byUser)); } /** diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 5508abff0e6..b1348b063bc 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -2966,7 +2966,7 @@ public function userBelongsToGroup(string $user, string $group):bool { * @throws Exception */ public function adminAddsUserToGroupUsingTheProvisioningApi(string $user, string $group):void { - $this->addUserToGroup($user, $group, "api"); + $this->addUserToGroup($user, $group); } /** @@ -3107,33 +3107,9 @@ public function addUserToGroup(string $user, string $group, ?string $method = nu $method = "ldap"; } elseif ($method === null && OcisHelper::isTestingWithGraphApi()) { $method = "graph"; - } elseif ($method === null) { - $method = "api"; } $method = \trim(\strtolower($method)); switch ($method) { - case "api": - $result = UserHelper::addUserToGroup( - $this->getBaseUrl(), - $user, - $group, - $this->getAdminUsername(), - $this->getAdminPassword(), - $this->getStepLineRef(), - $this->ocsApiVersion - ); - if ($checkResult && ($result->getStatusCode() !== 200)) { - throw new Exception( - "could not add user to group. " - . $result->getStatusCode() . " " . $result->getBody() - ); - } - $this->response = $result; - if (!$checkResult) { - // for when step only - $this->pushToLastStatusCodesArrays(); - } - break; case "ldap": try { $this->addUserToLdapGroup( @@ -3159,19 +3135,6 @@ public function addUserToGroup(string $user, string $group, ?string $method = nu } } - /** - * @Given the administrator has been added to group :group - * - * @param string $group - * - * @return void - * @throws Exception - */ - public function theAdministratorHasBeenAddedToGroup(string $group):void { - $admin = $this->getAdminUsername(); - $this->addUserToGroup($admin, $group, null, true); - } - /** * @param string $group * @param bool $shouldExist - true if the group should exist diff --git a/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature b/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature index de3b4e97abd..71822ea9f78 100644 --- a/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature +++ b/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature @@ -160,7 +160,7 @@ Feature: share resources where the sharee receives the share in multiple ways | 1 | 100 | | 2 | 200 | - @skipOnGraph + Scenario Outline: share with a group and then add a user to that group that already has a file with the shared name Given using OCS API version "" And user "Carol" has been created with default attributes and without skeleton files diff --git a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature index c2408a0ffaa..3fa0edc66f7 100644 --- a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature +++ b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature @@ -466,7 +466,7 @@ Feature: sharing | 1 | 100 | | 2 | 200 | - @skipOnGraph + Scenario Outline: share with a group and then add a user to that group Given using OCS API version "" And these users have been created with default attributes and without skeleton files: From 420e1c444ec2ff6c25f7f50907ea8c29c434ad96 Mon Sep 17 00:00:00 2001 From: Sabin Date: Tue, 3 Oct 2023 15:38:46 +0545 Subject: [PATCH 2/8] addressing the review --- .../features/apiGraph/addUserToGroup.feature | 4 +- .../features/bootstrap/GraphContext.php | 19 ++++-- .../features/bootstrap/Provisioning.php | 62 ------------------- .../uploadToShare.feature | 2 +- 4 files changed, 17 insertions(+), 70 deletions(-) diff --git a/tests/acceptance/features/apiGraph/addUserToGroup.feature b/tests/acceptance/features/apiGraph/addUserToGroup.feature index ec69869ce77..7010b13d078 100644 --- a/tests/acceptance/features/apiGraph/addUserToGroup.feature +++ b/tests/acceptance/features/apiGraph/addUserToGroup.feature @@ -205,8 +205,8 @@ Feature: add users to group Scenario: admin tries to add a nonexistent user to a group Given group "groupA" has been created - When the administrator tries to add user "nonexistentuser" to group "groupA" using the provisioning API - Then the HTTP status code should be "405" + When the administrator tries to add nonexistent user "nonexistentuser" to group "groupA" using the Graph API + Then the HTTP status code should be "404" Scenario: admin tries to add user to a group without sending the group diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index a1c894a5260..9cde9c7535a 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -766,14 +766,23 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void { * @param string $group * @param string $user * @param string|null $byUser + * @param bool $createNonExistentGroup * * @return ResponseInterface * @throws GuzzleException */ - public function addUserToGroup(string $group, string $user, ?string $byUser = null): ResponseInterface { + public function addUserToGroup(string $group, string $user, ?string $byUser = null, bool $createNonExistentGroup = false): ResponseInterface { $credentials = $this->getAdminOrUserCredentials($byUser); - $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id") ?: WebDavHelper::generateUUIDv4(); - $userId = $this->featureContext->getAttributeOfCreatedUser($user, "id"); + if ($createNonExistentGroup) { + $groupId = WebDavHelper::generateUUIDv4(); + } else { + $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); + } + if ($this->featureContext->userExists($user)) { + $userId = $this->featureContext->getAttributeOfCreatedUser($user, "id"); + } else { + $userId = WebDavHelper::generateUUIDv4(); + } return GraphHelper::addUserToGroup( $this->featureContext->getBaseUrl(), $this->featureContext->getStepLineRef(), @@ -824,7 +833,7 @@ public function theAdministratorAddsTheFollowingUsersToTheFollowingGroupsUsingTh } /** - * @When the administrator tries to add user :user to group :group using the Graph API + * @When the administrator tries to add nonexistent user :user to group :group using the Graph API * * @param string $user * @param string $group @@ -847,7 +856,7 @@ public function theAdministratorTriesToAddUserToGroupUsingTheGraphAPI(string $us * @throws GuzzleException | Exception */ public function theAdministratorTriesToAddUserToNonExistentGroupUsingTheGraphAPI(string $user, ?string $byUser = null): void { - $this->featureContext->setResponse($this->addUserToGroup('', $user, $byUser)); + $this->featureContext->setResponse($this->addUserToGroup('', $user, $byUser, true)); } /** diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index b1348b063bc..68f6d4601dd 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -2969,22 +2969,6 @@ public function adminAddsUserToGroupUsingTheProvisioningApi(string $user, string $this->addUserToGroup($user, $group); } - /** - * @When the administrator adds the following users to the following groups using the provisioning API - * - * @param TableNode $table - * - * @return void - * @throws Exception - */ - public function theAdministratorAddsUserToTheFollowingGroupsUsingTheProvisioningApi(TableNode $table):void { - $this->verifyTableNodeColumns($table, ["username", "groupname"], ["comment"]); - $rows = $table->getHash(); - foreach ($rows as $row) { - $this->adminAddsUserToGroupUsingTheProvisioningApi($row["username"], $row["groupname"]); - } - } - /** * @When user :user tries to add user :otherUser to group :group using the provisioning API * @@ -3011,39 +2995,6 @@ public function userTriesToAddUserToGroupUsingTheProvisioningApi(string $user, s $this->response = $result; } - /** - * @When user :user tries to add himself to group :group using the provisioning API - * - * @param string $user - * @param string $group - * - * @return void - * @throws Exception - */ - public function userTriesToAddHimselfToGroupUsingTheProvisioningApi(string $user, string $group):void { - $this->userTriesToAddUserToGroupUsingTheProvisioningApi($user, $user, $group); - } - - /** - * @When the administrator tries to add user :user to group :group using the provisioning API - * - * @param string $user - * @param string $group - * - * @return void - * @throws Exception - */ - public function theAdministratorTriesToAddUserToGroupUsingTheProvisioningApi( - string $user, - string $group - ):void { - $this->userTriesToAddUserToGroupUsingTheProvisioningApi( - $this->getAdminUsername(), - $user, - $group - ); - } - /** * @Given /^user "([^"]*)" has been added to group "([^"]*)"$/ * @@ -3073,19 +3024,6 @@ public function theFollowingUserHaveBeenAddedToTheFollowingGroup(TableNode $tabl } } - /** - * @Given /^user "([^"]*)" has been added to database backend group "([^"]*)"$/ - * - * @param string $user - * @param string $group - * - * @return void - * @throws Exception - */ - public function userHasBeenAddedToDatabaseBackendGroup(string $user, string $group):void { - $this->addUserToGroup($user, $group, 'api', true); - } - /** * @param string $user * @param string $group diff --git a/tests/acceptance/features/coreApiShareOperationsToShares2/uploadToShare.feature b/tests/acceptance/features/coreApiShareOperationsToShares2/uploadToShare.feature index 8f8e540f3fd..02054ca4a11 100644 --- a/tests/acceptance/features/coreApiShareOperationsToShares2/uploadToShare.feature +++ b/tests/acceptance/features/coreApiShareOperationsToShares2/uploadToShare.feature @@ -171,7 +171,7 @@ Feature: sharing @skipOnGraph Scenario Outline: uploading to a user shared folder with read/write permission when the sharer has insufficient quota does not work Given using DAV path - And user "Brian" has been created with default attributes and small skeleton files + And user "Brian" has been created with default attributes and without skeleton files And user "Alice" has created folder "FOLDER" And user "Alice" has created a share with settings | path | FOLDER | From bd3414702ed92cc7dc170a2966ba751ec32e4ab0 Mon Sep 17 00:00:00 2001 From: Sabin Date: Wed, 4 Oct 2023 10:32:17 +0545 Subject: [PATCH 3/8] addressing review regarding nonexistent user --- .../features/apiGraph/addUserToGroup.feature | 2 +- .../features/bootstrap/GraphContext.php | 24 ++++++++++--------- .../uploadToShare.feature | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/acceptance/features/apiGraph/addUserToGroup.feature b/tests/acceptance/features/apiGraph/addUserToGroup.feature index 7010b13d078..f43df4b74f7 100644 --- a/tests/acceptance/features/apiGraph/addUserToGroup.feature +++ b/tests/acceptance/features/apiGraph/addUserToGroup.feature @@ -205,7 +205,7 @@ Feature: add users to group Scenario: admin tries to add a nonexistent user to a group Given group "groupA" has been created - When the administrator tries to add nonexistent user "nonexistentuser" to group "groupA" using the Graph API + When the administrator tries to add nonexistent user to group "groupA" using the Graph API Then the HTTP status code should be "404" diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 9cde9c7535a..ea609dcf184 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -762,26 +762,29 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void { /** * adds a user to a group + * Note that the string "nonexistent" shouldn't be used for username and groupname + * Only for nonexistent testcase * * @param string $group * @param string $user * @param string|null $byUser - * @param bool $createNonExistentGroup * * @return ResponseInterface * @throws GuzzleException */ - public function addUserToGroup(string $group, string $user, ?string $byUser = null, bool $createNonExistentGroup = false): ResponseInterface { + public function addUserToGroup(string $group, string $user, ?string $byUser = null): ResponseInterface { $credentials = $this->getAdminOrUserCredentials($byUser); - if ($createNonExistentGroup) { + //user shouldn't be created with "nonexistent" name but only used when for nonexistent group testcase + if ($group === "nonexistent") { $groupId = WebDavHelper::generateUUIDv4(); } else { $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); } - if ($this->featureContext->userExists($user)) { - $userId = $this->featureContext->getAttributeOfCreatedUser($user, "id"); - } else { + //user shouldn't be created with "nonexistent" name but used when for nonexistent users testcase + if ($user === "nonexistent") { $userId = WebDavHelper::generateUUIDv4(); + } else { + $userId = $this->featureContext->getAttributeOfCreatedUser($user, "id"); } return GraphHelper::addUserToGroup( $this->featureContext->getBaseUrl(), @@ -833,15 +836,14 @@ public function theAdministratorAddsTheFollowingUsersToTheFollowingGroupsUsingTh } /** - * @When the administrator tries to add nonexistent user :user to group :group using the Graph API + * @When the administrator tries to add nonexistent user to group :group using the Graph API * - * @param string $user * @param string $group * * @return void */ - public function theAdministratorTriesToAddUserToGroupUsingTheGraphAPI(string $user, string $group): void { - $this->featureContext->setResponse($this->addUserToGroup($group, $user)); + public function theAdministratorTriesToAddNonExistentUserToGroupUsingTheGraphAPI(string $group): void { + $this->featureContext->setResponse($this->addUserToGroup($group, "nonexistent")); } /** @@ -856,7 +858,7 @@ public function theAdministratorTriesToAddUserToGroupUsingTheGraphAPI(string $us * @throws GuzzleException | Exception */ public function theAdministratorTriesToAddUserToNonExistentGroupUsingTheGraphAPI(string $user, ?string $byUser = null): void { - $this->featureContext->setResponse($this->addUserToGroup('', $user, $byUser, true)); + $this->featureContext->setResponse($this->addUserToGroup("nonexistent", $user, $byUser)); } /** diff --git a/tests/acceptance/features/coreApiShareOperationsToShares2/uploadToShare.feature b/tests/acceptance/features/coreApiShareOperationsToShares2/uploadToShare.feature index 02054ca4a11..8f8e540f3fd 100644 --- a/tests/acceptance/features/coreApiShareOperationsToShares2/uploadToShare.feature +++ b/tests/acceptance/features/coreApiShareOperationsToShares2/uploadToShare.feature @@ -171,7 +171,7 @@ Feature: sharing @skipOnGraph Scenario Outline: uploading to a user shared folder with read/write permission when the sharer has insufficient quota does not work Given using DAV path - And user "Brian" has been created with default attributes and without skeleton files + And user "Brian" has been created with default attributes and small skeleton files And user "Alice" has created folder "FOLDER" And user "Alice" has created a share with settings | path | FOLDER | From 32eb5c88ae5f5e93e7a25e17f7471ba5fa367a15 Mon Sep 17 00:00:00 2001 From: Sabin Date: Mon, 9 Oct 2023 15:48:42 +0545 Subject: [PATCH 4/8] addressing the review --- tests/acceptance/features/bootstrap/GraphContext.php | 10 +++++----- tests/acceptance/features/bootstrap/Provisioning.php | 7 ++++--- .../createShareReceivedInMultipleWays.feature | 9 ++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index ea609dcf184..7f2e60c2548 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -762,8 +762,7 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void { /** * adds a user to a group - * Note that the string "nonexistent" shouldn't be used for username and groupname - * Only for nonexistent testcase + * NOTE: If you want to do request with non-existing user or group,use provide "nonexistent" as their name * * @param string $group * @param string $user @@ -774,13 +773,13 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void { */ public function addUserToGroup(string $group, string $user, ?string $byUser = null): ResponseInterface { $credentials = $this->getAdminOrUserCredentials($byUser); - //user shouldn't be created with "nonexistent" name but only used when for nonexistent group testcase + // NOTE: If you want to do request with non-existing group,use "nonexistent" as the name if ($group === "nonexistent") { $groupId = WebDavHelper::generateUUIDv4(); } else { $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); } - //user shouldn't be created with "nonexistent" name but used when for nonexistent users testcase + // NOTE: If you want to do request with non-existing user,use "nonexistent" as the name if ($user === "nonexistent") { $userId = WebDavHelper::generateUUIDv4(); } else { @@ -811,11 +810,12 @@ public function adminHasAddedUserToGroupUsingTheGraphApi( string $user, string $group, bool $checkResult = true - ): void { + ): ResponseInterface { $result = $this->addUserToGroup($group, $user); if ($checkResult && ($result->getStatusCode() !== 204)) { $this->throwHttpException($result, "Could not add user '$user' to group '$group'."); } + return $result; } /** diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 68f6d4601dd..0aa42f6cb56 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -2966,7 +2966,7 @@ public function userBelongsToGroup(string $user, string $group):bool { * @throws Exception */ public function adminAddsUserToGroupUsingTheProvisioningApi(string $user, string $group):void { - $this->addUserToGroup($user, $group); + $this->setResponse($this->addUserToGroup($user, $group)); } /** @@ -3035,7 +3035,7 @@ public function theFollowingUserHaveBeenAddedToTheFollowingGroup(TableNode $tabl * @return void * @throws Exception */ - public function addUserToGroup(string $user, string $group, ?string $method = null, bool $checkResult = false):void { + public function addUserToGroup(string $user, string $group, ?string $method = null, bool $checkResult = false):ResponseInterface { $user = $this->getActualUsername($user); if ($method === null && $this->isTestingWithLdap() @@ -3061,7 +3061,7 @@ public function addUserToGroup(string $user, string $group, ?string $method = nu }; break; case "graph": - $this->graphContext->adminHasAddedUserToGroupUsingTheGraphApi( + $result = $this->graphContext->adminHasAddedUserToGroupUsingTheGraphApi( $user, $group ); @@ -3071,6 +3071,7 @@ public function addUserToGroup(string $user, string $group, ?string $method = nu "Invalid method to add a user to a group" ); } + return $result; } /** diff --git a/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature b/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature index 71822ea9f78..02642bba885 100644 --- a/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature +++ b/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature @@ -176,16 +176,15 @@ Feature: share resources where the sharee receives the share in multiple ways | shareWith | grp1 | And user "Brian" has accepted share "/lorem.txt" offered by user "Alice" When the administrator adds user "Carol" to group "grp1" using the provisioning API - Then the OCS status code should be "" - And the HTTP status code should be "200" + Then the HTTP status code should be "204" And user "Carol" should be able to accept pending share "/lorem.txt" offered by user "Alice" And the content of file "Shares/lorem.txt" for user "Brian" should be "Shared content" And the content of file "lorem.txt" for user "Carol" should be "My content" And the content of file "Shares/lorem.txt" for user "Carol" should be "Shared content" Examples: - | ocs_api_version | ocs_status_code | - | 1 | 100 | - | 2 | 200 | + | ocs_api_version | + | 1 | + | 2 | @issue-2440 Scenario: sharing parent folder to user with all permissions and its child folder to group with read permission then check create operation From e7418f3ab8dc6f80b1bc72bc1a46c699dc520e50 Mon Sep 17 00:00:00 2001 From: Sabin Date: Tue, 10 Oct 2023 09:56:19 +0545 Subject: [PATCH 5/8] updated expected failures file --- tests/acceptance/expected-failures-API-on-OCIS-storage.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index a879e5f3563..b192aaba33b 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -284,10 +284,10 @@ cannot share a folder with create permission #### [Sharing folder and sub-folder with same user but different permission,the permission of sub-folder is not obeyed ](https://github.com/owncloud/ocis/issues/2440) -- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:221](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L221) -- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:351](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L351) -- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:252](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L252) -- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:382](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L382) +- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:220](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L220) +- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:350](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L350) +- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:251](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L251) +- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:381](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L381) #### [Empty OCS response for a share create request using a disabled user](https://github.com/owncloud/ocis/issues/2212) From 4a50ad139608ef96414e8d64300d60ab73215777 Mon Sep 17 00:00:00 2001 From: Sabin Date: Wed, 11 Oct 2023 15:01:02 +0545 Subject: [PATCH 6/8] changing code to make it pass in reva edge --- .../features/bootstrap/GraphContext.php | 33 ++++++----- .../features/bootstrap/Provisioning.php | 58 +++++++------------ 2 files changed, 38 insertions(+), 53 deletions(-) diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 7f2e60c2548..852200665bd 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -1428,19 +1428,17 @@ public function userTriesToGetOwnDriveInformation(string $user) { * @throws GuzzleException * @throws Exception */ - public function addMultipleUsersToGroup(string $user, array $userIds, string $groupId, TableNode $table): void { + public function addMultipleUsersToGroup(string $user, array $userIds, string $groupId, TableNode $table): ResponseInterface { $credentials = $this->getAdminOrUserCredentials($user); $this->featureContext->verifyTableNodeColumns($table, ['username']); - $this->featureContext->setResponse( - GraphHelper::addUsersToGroup( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $credentials["username"], - $credentials["password"], - $groupId, - $userIds - ) + return GraphHelper::addUsersToGroup( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials["username"], + $credentials["password"], + $groupId, + $userIds ); } @@ -1461,7 +1459,8 @@ public function theAdministratorAddsTheFollowingUsersToAGroupInASingleRequestUsi foreach ($table->getHash() as $row) { $userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id"); } - $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $this->featureContext->setResponse($response); } /** @@ -1551,7 +1550,8 @@ public function theAdministratorTriesToAddsTheFollowingUsersToANonExistingGroupA foreach ($table->getHash() as $row) { $userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id"); } - $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $this->featureContext->setResponse($response); } /** @@ -1571,7 +1571,8 @@ public function theAdministratorTriesToAddTheFollowingNonExistingUsersToAGroupAt foreach ($table->getHash() as $row) { $userIds[] = WebDavHelper::generateUUIDv4(); } - $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $this->featureContext->setResponse($response); } /** @@ -1593,7 +1594,8 @@ public function theAdministratorTriesToAddTheFollowingUsersToAGroupAtOnceUsingTh $userId = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id"); $userIds[] = $userId ?: WebDavHelper::generateUUIDv4(); } - $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $this->featureContext->setResponse($response); } /** @@ -1986,8 +1988,7 @@ public function theAdministratorHasAddedTheFollowingUsersToAGroupAtOnceUsingTheG foreach ($table->getHash() as $row) { $userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id"); } - $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); - $response = $this->featureContext->getResponse(); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); if ($response->getStatusCode() !== 204) { $this->throwHttpException($response, "Cannot add users to group '$group'"); } diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 0aa42f6cb56..13b6e96c7b1 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -2966,33 +2966,21 @@ public function userBelongsToGroup(string $user, string $group):bool { * @throws Exception */ public function adminAddsUserToGroupUsingTheProvisioningApi(string $user, string $group):void { - $this->setResponse($this->addUserToGroup($user, $group)); - } - - /** - * @When user :user tries to add user :otherUser to group :group using the provisioning API - * - * @param string $user - * @param string $otherUser - * @param string $group - * - * @return void - * @throws Exception - */ - public function userTriesToAddUserToGroupUsingTheProvisioningApi(string $user, string $otherUser, string $group):void { - $actualUser = $this->getActualUsername($user); - $actualPassword = $this->getUserPassword($actualUser); - $actualOtherUser = $this->getActualUsername($otherUser); - $result = UserHelper::addUserToGroup( - $this->getBaseUrl(), - $actualOtherUser, - $group, - $actualUser, - $actualPassword, - $this->getStepLineRef(), - $this->ocsApiVersion - ); - $this->response = $result; + if ($this->isTestingWithLdap() && !$this->isLocalAdminGroup($group)) { + try { + $this->addUserToLdapGroup( + $user, + $group + ); + } catch (LdapException $exception) { + throw new Exception( + "User $user cannot be added to $group Error: $exception" + ); + }; + } elseif (OcisHelper::isTestingWithGraphApi()) { + $response = $this->graphContext->addUserToGroup($group, $user); + $this->setResponse($response); + } } /** @@ -3006,7 +2994,7 @@ public function userTriesToAddUserToGroupUsingTheProvisioningApi(string $user, s */ public function userHasBeenAddedToGroup(string $user, string $group):void { $user = $this->getActualUsername($user); - $this->addUserToGroup($user, $group, null, true); + $this->addUserToGroup($user, $group, null); } /** @@ -3028,14 +3016,11 @@ public function theFollowingUserHaveBeenAddedToTheFollowingGroup(TableNode $tabl * @param string $user * @param string $group * @param string|null $method how to add the user to the group api|occ - * @param bool $checkResult if true, then check the status of the operation. default false. - * for given step checkResult is expected to be set as true - * for when step checkResult is expected to be set as false * * @return void * @throws Exception */ - public function addUserToGroup(string $user, string $group, ?string $method = null, bool $checkResult = false):ResponseInterface { + public function addUserToGroup(string $user, string $group, ?string $method = null):void { $user = $this->getActualUsername($user); if ($method === null && $this->isTestingWithLdap() @@ -3061,17 +3046,16 @@ public function addUserToGroup(string $user, string $group, ?string $method = nu }; break; case "graph": - $result = $this->graphContext->adminHasAddedUserToGroupUsingTheGraphApi( - $user, - $group - ); + $result = $this->graphContext->addUserToGroup($group, $user); + if ($result->getStatusCode() !== 204) { + $this->throwHttpException($result, "Could not add user '$user' to group '$group'."); + } break; default: throw new InvalidArgumentException( "Invalid method to add a user to a group" ); } - return $result; } /** From 8cea6fa627db1de75f3c5422931307bb65e4b40e Mon Sep 17 00:00:00 2001 From: Sabin Date: Thu, 12 Oct 2023 09:51:13 +0545 Subject: [PATCH 7/8] addressing review --- .../features/bootstrap/GraphContext.php | 39 +++++---- .../features/bootstrap/Provisioning.php | 79 ++++--------------- .../createShareReceivedInMultipleWays.feature | 2 +- .../createShareToSharesFolder.feature | 2 +- 4 files changed, 37 insertions(+), 85 deletions(-) diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 852200665bd..a879453435a 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -762,7 +762,7 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void { /** * adds a user to a group - * NOTE: If you want to do request with non-existing user or group,use provide "nonexistent" as their name + * NOTE: If you want to make a request with non-existing user or group,provide "nonexistent" as their name * * @param string $group * @param string $user @@ -773,13 +773,13 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void { */ public function addUserToGroup(string $group, string $user, ?string $byUser = null): ResponseInterface { $credentials = $this->getAdminOrUserCredentials($byUser); - // NOTE: If you want to do request with non-existing group,use "nonexistent" as the name + // NOTE: If you want to make a request with non-existing group,provide "nonexistent" as the name if ($group === "nonexistent") { $groupId = WebDavHelper::generateUUIDv4(); } else { $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); } - // NOTE: If you want to do request with non-existing user,use "nonexistent" as the name + // NOTE: If you want to make a request with non-existing user,provide "nonexistent" as the name if ($user === "nonexistent") { $userId = WebDavHelper::generateUUIDv4(); } else { @@ -810,12 +810,9 @@ public function adminHasAddedUserToGroupUsingTheGraphApi( string $user, string $group, bool $checkResult = true - ): ResponseInterface { - $result = $this->addUserToGroup($group, $user); - if ($checkResult && ($result->getStatusCode() !== 204)) { - $this->throwHttpException($result, "Could not add user '$user' to group '$group'."); - } - return $result; + ): void { + $response = $this->addUserToGroup($group, $user); + $this->featureContext->theHTTPStatusCodeShouldBe(204, '', $response); } /** @@ -1422,15 +1419,13 @@ public function userTriesToGetOwnDriveInformation(string $user) { * @param string $user * @param array $userIds * @param string $groupId - * @param TableNode $table * * @return void * @throws GuzzleException * @throws Exception */ - public function addMultipleUsersToGroup(string $user, array $userIds, string $groupId, TableNode $table): ResponseInterface { + public function addMultipleUsersToGroup(string $user, array $userIds, string $groupId): ResponseInterface { $credentials = $this->getAdminOrUserCredentials($user); - $this->featureContext->verifyTableNodeColumns($table, ['username']); return GraphHelper::addUsersToGroup( $this->featureContext->getBaseUrl(), @@ -1459,7 +1454,8 @@ public function theAdministratorAddsTheFollowingUsersToAGroupInASingleRequestUsi foreach ($table->getHash() as $row) { $userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id"); } - $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $this->featureContext->verifyTableNodeColumns($table, ['username']); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId); $this->featureContext->setResponse($response); } @@ -1550,7 +1546,8 @@ public function theAdministratorTriesToAddsTheFollowingUsersToANonExistingGroupA foreach ($table->getHash() as $row) { $userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id"); } - $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $this->featureContext->verifyTableNodeColumns($table, ['username']); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId); $this->featureContext->setResponse($response); } @@ -1571,7 +1568,8 @@ public function theAdministratorTriesToAddTheFollowingNonExistingUsersToAGroupAt foreach ($table->getHash() as $row) { $userIds[] = WebDavHelper::generateUUIDv4(); } - $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $this->featureContext->verifyTableNodeColumns($table, ['username']); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId); $this->featureContext->setResponse($response); } @@ -1594,7 +1592,8 @@ public function theAdministratorTriesToAddTheFollowingUsersToAGroupAtOnceUsingTh $userId = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id"); $userIds[] = $userId ?: WebDavHelper::generateUUIDv4(); } - $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); + $this->featureContext->verifyTableNodeColumns($table, ['username']); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId); $this->featureContext->setResponse($response); } @@ -1988,11 +1987,9 @@ public function theAdministratorHasAddedTheFollowingUsersToAGroupAtOnceUsingTheG foreach ($table->getHash() as $row) { $userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id"); } - $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); - if ($response->getStatusCode() !== 204) { - $this->throwHttpException($response, "Cannot add users to group '$group'"); - } - $this->featureContext->emptyLastHTTPStatusCodesArray(); + $this->featureContext->verifyTableNodeColumns($table, ['username']); + $response = $this->addMultipleUsersToGroup($user, $userIds, $groupId); + $this->featureContext->theHTTPStatusCodeShouldBe(204, '', $response); } /** diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 13b6e96c7b1..7a416650005 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -2966,21 +2966,8 @@ public function userBelongsToGroup(string $user, string $group):bool { * @throws Exception */ public function adminAddsUserToGroupUsingTheProvisioningApi(string $user, string $group):void { - if ($this->isTestingWithLdap() && !$this->isLocalAdminGroup($group)) { - try { - $this->addUserToLdapGroup( - $user, - $group - ); - } catch (LdapException $exception) { - throw new Exception( - "User $user cannot be added to $group Error: $exception" - ); - }; - } elseif (OcisHelper::isTestingWithGraphApi()) { - $response = $this->graphContext->addUserToGroup($group, $user); - $this->setResponse($response); - } + $response = $this->graphContext->addUserToGroup($group, $user); + $this->setResponse($response); } /** @@ -2994,7 +2981,21 @@ public function adminAddsUserToGroupUsingTheProvisioningApi(string $user, string */ public function userHasBeenAddedToGroup(string $user, string $group):void { $user = $this->getActualUsername($user); - $this->addUserToGroup($user, $group, null); + if ($this->isTestingWithLdap() && !$this->isLocalAdminGroup($group)) { + try { + $this->addUserToLdapGroup( + $user, + $group + ); + } catch (LdapException $exception) { + throw new Exception( + "User $user cannot be added to $group Error: $exception" + ); + } + } else { + $response = $this->graphContext->addUserToGroup($group, $user); + $this->theHTTPStatusCodeShouldBe(204, '', $response); + } } /** @@ -3012,52 +3013,6 @@ public function theFollowingUserHaveBeenAddedToTheFollowingGroup(TableNode $tabl } } - /** - * @param string $user - * @param string $group - * @param string|null $method how to add the user to the group api|occ - * - * @return void - * @throws Exception - */ - public function addUserToGroup(string $user, string $group, ?string $method = null):void { - $user = $this->getActualUsername($user); - if ($method === null - && $this->isTestingWithLdap() - && !$this->isLocalAdminGroup($group) - ) { - //guess yourself - $method = "ldap"; - } elseif ($method === null && OcisHelper::isTestingWithGraphApi()) { - $method = "graph"; - } - $method = \trim(\strtolower($method)); - switch ($method) { - case "ldap": - try { - $this->addUserToLdapGroup( - $user, - $group - ); - } catch (LdapException $exception) { - throw new Exception( - "User $user cannot be added to $group Error: $exception" - ); - }; - break; - case "graph": - $result = $this->graphContext->addUserToGroup($group, $user); - if ($result->getStatusCode() !== 204) { - $this->throwHttpException($result, "Could not add user '$user' to group '$group'."); - } - break; - default: - throw new InvalidArgumentException( - "Invalid method to add a user to a group" - ); - } - } - /** * @param string $group * @param bool $shouldExist - true if the group should exist diff --git a/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature b/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature index 02642bba885..ef7f4171438 100644 --- a/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature +++ b/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature @@ -160,7 +160,7 @@ Feature: share resources where the sharee receives the share in multiple ways | 1 | 100 | | 2 | 200 | - + @skipOnReva Scenario Outline: share with a group and then add a user to that group that already has a file with the shared name Given using OCS API version "" And user "Carol" has been created with default attributes and without skeleton files diff --git a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature index 3fa0edc66f7..c7457e9ae04 100644 --- a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature +++ b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature @@ -466,7 +466,7 @@ Feature: sharing | 1 | 100 | | 2 | 200 | - + @skipOnReva Scenario Outline: share with a group and then add a user to that group Given using OCS API version "" And these users have been created with default attributes and without skeleton files: From f98197b545c87e68b2d07f766b3288d4bfd9cab7 Mon Sep 17 00:00:00 2001 From: Sabin Date: Mon, 16 Oct 2023 12:01:54 +0545 Subject: [PATCH 8/8] addressing review --- tests/acceptance/features/bootstrap/GraphContext.php | 2 -- tests/acceptance/features/bootstrap/Provisioning.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index a879453435a..83eb0d73f95 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -773,13 +773,11 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void { */ public function addUserToGroup(string $group, string $user, ?string $byUser = null): ResponseInterface { $credentials = $this->getAdminOrUserCredentials($byUser); - // NOTE: If you want to make a request with non-existing group,provide "nonexistent" as the name if ($group === "nonexistent") { $groupId = WebDavHelper::generateUUIDv4(); } else { $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); } - // NOTE: If you want to make a request with non-existing user,provide "nonexistent" as the name if ($user === "nonexistent") { $userId = WebDavHelper::generateUUIDv4(); } else { diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 7a416650005..27f47ebcb43 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -2981,7 +2981,7 @@ public function adminAddsUserToGroupUsingTheProvisioningApi(string $user, string */ public function userHasBeenAddedToGroup(string $user, string $group):void { $user = $this->getActualUsername($user); - if ($this->isTestingWithLdap() && !$this->isLocalAdminGroup($group)) { + if ($this->isTestingWithLdap()) { try { $this->addUserToLdapGroup( $user,