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 11, 2023
1 parent db098fa commit 6f27302
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 100 deletions.
9 changes: 9 additions & 0 deletions tests/TestHelpers/HttpRequestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ public static function sendRequest(
$sendRetryLimit = self::numRetriesOnHttpTooEarly();
$sendCount = 0;
$sendExceptionHappened = false;
var_dump(
$url,
$xRequestId,
$method,
$user,
$password,
$headers,
$body,
);
do {
$response = self::sendRequestOnce(
$url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Feature: add user
See https://github.com/owncloud/ocis/issues/1542 and https://github.com/owncloud/ocis/pull/839


Scenario Outline: admin creates a user
Given using OCS API version "<ocs_api_version>"
Scenario: admin creates a user
Given using OCS API version "1"
And user "brand-new-user" has been deleted
When the administrator sends a user creation request for user "brand-new-user" password "%alt1%" using the provisioning API
Then the OCS status code should be "<ocs_status_code>"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "brand-new-user" should exist
And user "brand-new-user" should be able to access a skeleton file
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |
# Examples:
# | ocs_api_version | ocs_status_code |
# | 1 | 100 |
# | 2 | 200 |
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
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 deleteTheUserUsingTheProvisioningApi(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->response->getStatusCode(), [200, 204]))
) {
\error_log(
"INFORMATION: could not delete user '$user' "
. $this->response->getStatusCode() . " " . $this->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 provisioning API$/
*
* @param string|null $user
*
* @return void
* @throws Exception
*/
public function theAdministratorHasDeletedUserUsingTheProvisioningApi(?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 provisioning API$/
*
* @param string $user
*
* @return void
* @throws Exception
*/
public function theAdminDeletesUserUsingTheProvisioningApi(string $user):void {
$user = $this->featureContext->getActualUsername($user);
$this->deleteTheUserUsingTheProvisioningApi($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->verifyTableNodeColumns($table, ["username"]);
$usernames = $table->getHash();
foreach ($usernames as $username) {
$this->theAdminDeletesUserUsingTheProvisioningApi($username["username"]);
}
}

/**
* @When /^the user "([^"]*)" deletes a user "([^"]*)" using the Graph API$/
*
Expand Down
170 changes: 85 additions & 85 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -1609,50 +1609,50 @@ 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"]);
}
}
// /**
// * @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 +2528,7 @@ public function userHasBeenDeleted(string $user):void {
if ($this->isTestingWithLdap() && \in_array($user, $this->ldapCreatedUsers)) {
$this->deleteLdapUser($user);
} else {
$this->deleteTheUserUsingTheProvisioningApi($user);
$this->graphContext->deleteTheUserUsingTheProvisioningApi($user);
}
}
$this->userShouldNotExist($user);
Expand Down Expand Up @@ -3912,46 +3912,46 @@ 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 $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 @@ -646,8 +646,8 @@ Feature: sharing
| 2 | 200 |

@issue-903
Scenario Outline: shares to a deleted user should not be listed as shares for the sharer
Given using OCS API version "<ocs_api_version>"
Scenario: shares to a deleted user should not be listed as shares for the sharer
Given using OCS API version "1"
And these users have been created with default attributes and without skeleton files:
| username |
| Brian |
Expand All @@ -659,14 +659,14 @@ Feature: sharing
And user "Carol" has accepted share "/textfile0.txt" offered by user "Alice"
And the administrator has deleted user "Brian" using the provisioning 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>"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "Carol" should be included in the response
But user "Brian" should not be included in the response
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |
# Examples:
# | ocs_api_version | ocs_status_code |
# | 1 | 100 |
# | 2 | 200 |

@issue-719
Scenario Outline: creating a share of a renamed file when another share exists
Expand Down

0 comments on commit 6f27302

Please sign in to comment.