[tests-only][full-ci] refactoring the user delete code from ocs to graphapi (#7020)

* addressing the reviews

* addressing the review

* refactored test code

* updated expected failures file
This commit is contained in:
Sabin Panta
2023-10-31 12:01:36 +05:45
committed by GitHub
parent b471895598
commit cc1f93eef1
4 changed files with 22 additions and 112 deletions
@@ -1425,7 +1425,8 @@ trait Provisioning {
*/
public function theAdministratorHasDeletedUserUsingTheProvisioningApi(?string $user):void {
$user = $this->getActualUsername($user);
$this->deleteTheUserUsingTheProvisioningApi($user);
$response = $this->deleteUser($user);
$this->theHttpStatusCodeShouldBe(204, "", $response);
WebDavHelper::removeSpaceIdReferenceForUser($user);
$this->userShouldNotExist($user);
}
@@ -1440,51 +1441,8 @@ trait Provisioning {
*/
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
*
* @param string $user
* @param string $otherUser
*
* @return void
* @throws Exception
*/
public function userDeletesUserUsingTheProvisioningApi(
string $user,
string $otherUser
):void {
$actualUser = $this->getActualUsername($user);
$actualPassword = $this->getUserPassword($actualUser);
$actualOtherUser = $this->getActualUsername($otherUser);
$this->response = UserHelper::deleteUser(
$this->getBaseUrl(),
$actualOtherUser,
$actualUser,
$actualPassword,
$this->getStepLineRef(),
$this->ocsApiVersion
);
$this->setResponse($this->deleteUser($user));
$this->pushToLastHttpStatusCodesArray();
}
/**
@@ -2333,28 +2291,13 @@ trait Provisioning {
if ($this->isTestingWithLdap() && \in_array($user, $this->ldapCreatedUsers)) {
$this->deleteLdapUser($user);
} else {
$this->deleteTheUserUsingTheProvisioningApi($user);
$response = $this->deleteUser($user);
$this->theHTTPStatusCodeShouldBe(204, "", $response);
}
}
$this->userShouldNotExist($user);
}
/**
* @Given the following users have been deleted
*
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function theFollowingUsersHaveBeenDeleted(TableNode $table):void {
$this->verifyTableNodeColumns($table, ["username"]);
$usernames = $table->getHash();
foreach ($usernames as $username) {
$this->userHasBeenDeleted($username["username"]);
}
}
/**
* @Given these users have been initialized:
* expects a table of users with the heading
@@ -2722,17 +2665,6 @@ trait Provisioning {
$this->initializeUser($user, $password);
}
/**
* @param string $user
*
* @return void
* @throws Exception
*/
public function deleteUser(string $user):void {
$this->deleteTheUserUsingTheProvisioningApi($user);
$this->userShouldNotExist($user);
}
/**
* Try to delete the group, catching anything bad that might happen.
* Use this method only in places where you want to try as best you
@@ -3538,15 +3470,13 @@ trait Provisioning {
* @return void
* @throws Exception
*/
public function deleteTheUserUsingTheProvisioningApi(string $user):void {
$this->emptyLastHTTPStatusCodesArray();
$this->emptyLastOCSStatusCodesArray();
public function deleteUser(string $user):ResponseInterface {
// Always try to delete the user
if (OcisHelper::isTestingWithGraphApi()) {
// users can be deleted using the username in the GraphApi too
$this->graphContext->adminDeletesUserUsingTheGraphApi($user);
$response = $this->graphContext->adminDeletesUserUsingTheGraphApi($user);
} else {
$this->response = UserHelper::deleteUser(
$response = UserHelper::deleteUser(
$this->getBaseUrl(),
$user,
$this->getAdminUsername(),
@@ -3555,22 +3485,7 @@ trait Provisioning {
$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);
return $response;
}
/**
@@ -4974,10 +4889,12 @@ trait Provisioning {
$this->usingServer('LOCAL');
foreach ($this->createdUsers as $userData) {
$this->deleteUser($userData['actualUsername']);
$this->userShouldNotExist($userData['actualUsername']);
}
$this->usingServer('REMOTE');
foreach ($this->createdRemoteUsers as $userData) {
$this->deleteUser($userData['actualUsername']);
$this->userShouldNotExist($userData['actualUsername']);
}
$this->usingServer($previousServer);
}