Skip to content

Commit

Permalink
[tests-only][full-ci] refactoring the user delete code from ocs to gr…
Browse files Browse the repository at this point in the history
…aphapi (#7020)

* addressing the reviews

* addressing the review

* refactored test code

* updated expected failures file
  • Loading branch information
S-Panta authored Oct 31, 2023
1 parent b471895 commit cc1f93e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 112 deletions.
4 changes: 0 additions & 4 deletions tests/acceptance/expected-failures-API-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,6 @@ Not everything needs to be implemented for ocis. While the oc10 testsuite covers
- [coreApiFavorites/favorites.feature:150](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiFavorites/favorites.feature#L150)
- [coreApiFavorites/favorites.feature:227](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiFavorites/favorites.feature#L227)

#### [OCS status code zero](https://github.com/owncloud/ocis/issues/3621)

- [coreApiShareManagementToShares/moveReceivedShare.feature:13](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature#L13)

#### [HTTP status code differ while deleting file of another user's trash bin](https://github.com/owncloud/ocis/issues/3544)

- [coreApiTrashbin/trashbinDelete.feature:105](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiTrashbin/trashbinDelete.feature#L105)
Expand Down
21 changes: 9 additions & 12 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,14 @@ public function adminHasDeletedGroupUsingTheGraphApi(string $group): void {
* @return void
* @throws GuzzleException
*/
public function adminDeletesUserUsingTheGraphApi(string $user, ?string $byUser = null): void {
public function adminDeletesUserUsingTheGraphApi(string $user, ?string $byUser = null): ResponseInterface {
$credentials = $this->getAdminOrUserCredentials($byUser);

$this->featureContext->setResponse(
GraphHelper::deleteUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials["username"],
$credentials["password"],
$user
)
return GraphHelper::deleteUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials["username"],
$credentials["password"],
$user
);
}

Expand Down Expand Up @@ -442,8 +439,8 @@ public function theUserTriesToDeleteNonExistingUser(string $byUser): void {
* @throws GuzzleException
*/
public function theUserHasDeletesAUserUsingTheGraphAPI(string $byUser, string $user): void {
$this->adminDeletesUserUsingTheGraphApi($user, $byUser);
$this->featureContext->thenTheHTTPStatusCodeShouldBe(204);
$response = $this->adminDeletesUserUsingTheGraphApi($user, $byUser);
$this->featureContext->theHttpStatusCodeShouldBe(204, "", $response);
}

/**
Expand Down
107 changes: 12 additions & 95 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,8 @@ public function userHasTriedToResetPasswordOfUserUsingTheProvisioningApi(?string
*/
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);
}
Expand All @@ -1440,51 +1441,8 @@ public function theAdministratorHasDeletedUserUsingTheProvisioningApi(?string $u
*/
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();
}

/**
Expand Down Expand Up @@ -2333,28 +2291,13 @@ public function userHasBeenDeleted(string $user):void {
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
Expand Down Expand Up @@ -2722,17 +2665,6 @@ public function userHasBeenCreated(
$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
Expand Down Expand Up @@ -3538,15 +3470,13 @@ public function userTriesToEnableUserUsingTheProvisioningApi(
* @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(),
Expand All @@ -3555,22 +3485,7 @@ public function deleteTheUserUsingTheProvisioningApi(string $user):void {
$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;
}

/**
Expand Down Expand Up @@ -4974,10 +4889,12 @@ public function cleanupDatabaseUsers():void {
$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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: sharing
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 HTTP status code of responses on each endpoint should be "200, 201, 204" respectively
And user "Brian" should see the following elements
| /Shares/new/|

Expand Down

0 comments on commit cc1f93e

Please sign in to comment.