Skip to content

Commit

Permalink
refactoring the uder delete code from provisioning php file to graph.php
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Panta committed Aug 14, 2023
1 parent db098fa commit 8b78a61
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 95 deletions.
2 changes: 1 addition & 1 deletion tests/acceptance/features/apiGraph/createUser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
77 changes: 77 additions & 0 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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$/
*
Expand Down
90 changes: 2 additions & 88 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<ocs_status_code>"
And the HTTP status code should be "200"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8b78a61

Please sign in to comment.