From 8b78a61057a39acd8092afe00ef1fb0d4f354782 Mon Sep 17 00:00:00 2001 From: Sabin Date: Fri, 11 Aug 2023 17:15:50 +0545 Subject: [PATCH] refactoring the uder delete code from provisioning php file to graph.php --- .../features/apiGraph/createUser.feature | 2 +- .../features/bootstrap/FeatureContext.php | 2 +- .../features/bootstrap/GraphContext.php | 77 ++++++++++++++++ .../features/bootstrap/Provisioning.php | 90 +------------------ .../createShareToSharesFolder.feature | 2 +- .../moveReceivedShare.feature | 5 +- .../trashbinFilesFolders.feature | 2 +- 7 files changed, 85 insertions(+), 95 deletions(-) diff --git a/tests/acceptance/features/apiGraph/createUser.feature b/tests/acceptance/features/apiGraph/createUser.feature index 9d9b5b555e0..08947404a6a 100644 --- a/tests/acceptance/features/apiGraph/createUser.feature +++ b/tests/acceptance/features/apiGraph/createUser.feature @@ -129,7 +129,7 @@ Feature: create user When the administrator retrieves the assigned role of user "sam" using the Graph API Then the HTTP status code should be "200" And the Graph API response should have no role - + @env-config Scenario: create user with setting OCIS assign the default user role diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 0f263e66b39..b212f5a35d7 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -143,7 +143,7 @@ class FeatureContext extends BehatVariablesContext { */ private bool $federatedServerExists = false; private int $ocsApiVersion = 1; - private ?ResponseInterface $response = null; + public ?ResponseInterface $response = null; private string $responseUser = ''; private ?string $responseBodyContent = null; private array $userResponseBodyContents = []; diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index acadf6010e5..daf3ad3c0b3 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -360,6 +360,36 @@ public function adminDeletesUserUsingTheGraphApi(string $user, ?string $byUser = ); } + /** + * @param string $user + * + * @return void + * @throws Exception + */ + public function deleteTheUserUsingTheGraphApi(string $user):void { + $this->featureContext->emptyLastHTTPStatusCodesArray(); + $this->featureContext->emptyLastOCSStatusCodesArray(); + // Always try to delete the user + // users can be deleted using the username in the GraphApi too + $this->adminDeletesUserUsingTheGraphApi($user); + $this->featureContext->pushToLastStatusCodesArrays(); + + // Only log a message if the test really expected the user to have been + // successfully created (i.e. the delete is expected to work) and + // there was a problem deleting the user. Because in this case there + // might be an effect on later tests. + if ($this->featureContext->theUserShouldExist($user) + && (!\in_array($this->featureContext->response->getStatusCode(), [200, 204])) + ) { + \error_log( + "INFORMATION: could not delete user '$user' " + . $this->featureContext->response->getStatusCode() . " " . $this->featureContext->response->getBody() + ); + } + + $this->featureContext->rememberThatUserIsNotExpectedToExist($user); + } + /** * remove user from group * @@ -402,6 +432,53 @@ public function deleteUserByUserIdUsingTheGraphApi(string $userId, string $byUse ); } + /** + * @Given /^the administrator has deleted user "([^"]*)" using the Graph API$/ + * + * @param string|null $user + * + * @return void + * @throws Exception + */ + public function theAdministratorHasDeletedUserUsingTheGraphApi(?string $user):void { + $this->featureContext->emptyLastHTTPStatusCodesArray(); + $this->featureContext->emptyLastOCSStatusCodesArray(); + $user = $this->featureContext->getActualUsername($user); + $this->adminDeletesUserUsingTheGraphApi($user); + WebDavHelper::removeSpaceIdReferenceForUser($user); + $this->featureContext->userShouldNotExist($user); + } + + /** + * @When /^the administrator deletes user "([^"]*)" using the Graph API$/ + * + * @param string $user + * + * @return void + * @throws Exception + */ + public function theAdminDeletesUserUsingTheGraphApi(string $user):void { + $user = $this->featureContext->getActualUsername($user); + $this->deleteTheUserUsingTheGraphApi($user); + $this->featureContext->rememberThatUserIsNotExpectedToExist($user); + } + + /** + * @When the administrator deletes the following users using the provisioning API + * + * @param TableNode $table + * + * @return void + * @throws Exception + */ + public function theAdministratorDeletesTheFollowingUsersUsingTheProvisioningApi(TableNode $table):void { + $this->featureContext->verifyTableNodeColumns($table, ["username"]); + $usernames = $table->getHash(); + foreach ($usernames as $username) { + $this->theAdminDeletesUserUsingTheGraphApi($username["username"]); + } + } + /** * @When /^the user "([^"]*)" deletes a user "([^"]*)" using the Graph API$/ * diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index bb539b0e865..9e6401725c4 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -1609,51 +1609,6 @@ public function userHasTriedToResetPasswordOfUserUsingTheProvisioningApi(?string $this->theHTTPStatusCodeShouldBeSuccess(); } - /** - * @Given /^the administrator has deleted user "([^"]*)" using the provisioning API$/ - * - * @param string|null $user - * - * @return void - * @throws Exception - */ - public function theAdministratorHasDeletedUserUsingTheProvisioningApi(?string $user):void { - $user = $this->getActualUsername($user); - $this->deleteTheUserUsingTheProvisioningApi($user); - WebDavHelper::removeSpaceIdReferenceForUser($user); - $this->userShouldNotExist($user); - } - - /** - * @When /^the administrator deletes user "([^"]*)" using the provisioning API$/ - * - * @param string $user - * - * @return void - * @throws Exception - */ - public function theAdminDeletesUserUsingTheProvisioningApi(string $user):void { - $user = $this->getActualUsername($user); - $this->deleteTheUserUsingTheProvisioningApi($user); - $this->rememberThatUserIsNotExpectedToExist($user); - } - - /** - * @When the administrator deletes the following users using the provisioning API - * - * @param TableNode $table - * - * @return void - * @throws Exception - */ - public function theAdministratorDeletesTheFollowingUsersUsingTheProvisioningApi(TableNode $table):void { - $this->verifyTableNodeColumns($table, ["username"]); - $usernames = $table->getHash(); - foreach ($usernames as $username) { - $this->theAdminDeletesUserUsingTheProvisioningApi($username["username"]); - } - } - /** * @When user :user deletes user :otherUser using the provisioning API * @@ -2528,7 +2483,7 @@ public function userHasBeenDeleted(string $user):void { if ($this->isTestingWithLdap() && \in_array($user, $this->ldapCreatedUsers)) { $this->deleteLdapUser($user); } else { - $this->deleteTheUserUsingTheProvisioningApi($user); + $this->graphContext->deleteTheUserUsingTheGraphApi($user); } } $this->userShouldNotExist($user); @@ -2936,7 +2891,7 @@ public function createUser( * @throws Exception */ public function deleteUser(string $user):void { - $this->deleteTheUserUsingTheProvisioningApi($user); + $this->graphContext->deleteTheUserUsingTheGraphApi($user); $this->userShouldNotExist($user); } @@ -3912,47 +3867,6 @@ public function userTriesToEnableUserUsingTheProvisioningApi( $this->disableOrEnableUser($user, $otherUser, 'enable'); } - /** - * @param string $user - * - * @return void - * @throws Exception - */ - public function deleteTheUserUsingTheProvisioningApi(string $user):void { - $this->emptyLastHTTPStatusCodesArray(); - $this->emptyLastOCSStatusCodesArray(); - // Always try to delete the user - if (OcisHelper::isTestingWithGraphApi()) { - // users can be deleted using the username in the GraphApi too - $this->graphContext->adminDeletesUserUsingTheGraphApi($user); - } else { - $this->response = UserHelper::deleteUser( - $this->getBaseUrl(), - $user, - $this->getAdminUsername(), - $this->getAdminPassword(), - $this->getStepLineRef(), - $this->ocsApiVersion - ); - } - $this->pushToLastStatusCodesArrays(); - - // Only log a message if the test really expected the user to have been - // successfully created (i.e. the delete is expected to work) and - // there was a problem deleting the user. Because in this case there - // might be an effect on later tests. - if ($this->theUserShouldExist($user) - && (!\in_array($this->response->getStatusCode(), [200, 204])) - ) { - \error_log( - "INFORMATION: could not delete user '$user' " - . $this->response->getStatusCode() . " " . $this->response->getBody() - ); - } - - $this->rememberThatUserIsNotExpectedToExist($user); - } - /** * @param string $group group name * diff --git a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature index 69533063721..5ae418a356a 100644 --- a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature +++ b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature @@ -657,7 +657,7 @@ Feature: sharing And user "Alice" has shared file "textfile0.txt" with user "Carol" And user "Brian" has accepted share "/textfile0.txt" offered by user "Alice" And user "Carol" has accepted share "/textfile0.txt" offered by user "Alice" - And the administrator has deleted user "Brian" using the provisioning API + And the administrator has deleted user "Brian" using the Graph API When user "Alice" gets all the shares of the file "textfile0.txt" using the sharing API Then the OCS status code should be "" And the HTTP status code should be "200" diff --git a/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature b/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature index 76c46d9fb00..16091d04c30 100644 --- a/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature +++ b/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature @@ -19,9 +19,8 @@ Feature: sharing And user "Brian" accepts share "/TMP" offered by user "Alice" using the sharing API And user "Carol" accepts share "/TMP" offered by user "Alice" using the sharing API And user "Brian" moves folder "/Shares/TMP" to "/Shares/new" using the WebDAV API - And the administrator deletes user "Carol" using the provisioning API - Then the OCS status code of responses on all endpoints should be "100" - And the HTTP status code of responses on all endpoints should be "200" + And the administrator deletes user "Carol" using the Graph API + And the HTTP status code of responses on all endpoints should be "204" And user "Brian" should see the following elements | /Shares/new/| diff --git a/tests/acceptance/features/coreApiTrashbin/trashbinFilesFolders.feature b/tests/acceptance/features/coreApiTrashbin/trashbinFilesFolders.feature index 7653c0359ba..88305fc1c5a 100644 --- a/tests/acceptance/features/coreApiTrashbin/trashbinFilesFolders.feature +++ b/tests/acceptance/features/coreApiTrashbin/trashbinFilesFolders.feature @@ -206,7 +206,7 @@ Feature: files and folders exist in the trashbin after being deleted And user "Brian" has been created with default attributes and without skeleton files And user "testtrashbin102" has deleted file "/textfile0.txt" And user "testtrashbin102" has deleted file "/textfile2.txt" - And the administrator has deleted user "testtrashbin102" using the provisioning API + And the administrator has deleted user "testtrashbin102" using the Graph API And user "testtrashbin102" has been created with default attributes and without skeleton files And user "testtrashbin102" has uploaded file "filesForUpload/textfile.txt" to "/textfile3.txt" And user "testtrashbin102" has deleted file "/textfile3.txt"