[tests-only] do not try to delete already deleted groups (#8886)

* fix(test): do not try to delete already deleted groups

* test: remove redundant steps

* test: fix php code style

* fix typo
This commit is contained in:
Sawjan Gurung
2024-04-18 17:28:38 +05:45
committed by GitHub
parent 2e8708816f
commit 2f32fa3e36
7 changed files with 52 additions and 90 deletions

View File

@@ -863,7 +863,7 @@ Feature: Send a sharing invitations
| Carol | grp1 |
And user "Alice" has uploaded file with content "to share" to "/textfile1.txt"
And user "Alice" has created folder "FolderToShare"
And the administrator has deleted group "grp1"
And group "grp1" has been deleted
When user "Alice" sends the following share invitation using the Graph API:
| resource | <resource> |
| space | Personal |

View File

@@ -1463,7 +1463,7 @@ Feature: resources shared by user
| sharee | Brian |
| shareType | user |
| permissionsRole | Viewer |
And the administrator has deleted user "Brian" using the provisioning API
And user "Brian" has been deleted
When user "Alice" lists the shares shared by her after clearing user cache using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match

View File

@@ -274,7 +274,7 @@ class GraphContext implements Context {
* @return ResponseInterface
* @throws GuzzleException
*/
public function userDeletesGroupWithGroupId(
public function deleteGroupWithId(
string $groupId,
?string $user = null
): ResponseInterface {
@@ -289,31 +289,18 @@ class GraphContext implements Context {
);
}
/**
* @param string $groupId
*
* @return void
* @throws GuzzleException
*/
public function adminDeletesGroupWithGroupId(
string $groupId
): void {
$response = $this->userDeletesGroupWithGroupId($groupId);
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
}
/**
* @param string $group
*
* @return void
* @return ResponseInterface
* @throws Exception
* @throws GuzzleException
*/
public function adminDeletesGroupUsingTheGraphApi(
public function deleteGroupWithName(
string $group
): void {
): ResponseInterface {
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
$this->adminDeletesGroupWithGroupId($groupId);
return $this->deleteGroupWithId($groupId);
}
/**
@@ -1054,23 +1041,13 @@ class GraphContext implements Context {
*/
public function userDeletesGroupUsingTheGraphApi(string $group, ?string $user = null): void {
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
$response = $this->userDeletesGroupWithGroupId($groupId, $user);
$response = $this->deleteGroupWithId($groupId, $user);
if ($response->getStatusCode() === 204) {
$this->featureContext->rememberThatGroupIsNotExpectedToExist($group);
}
$this->featureContext->setResponse($response);
}
/**
* @Given the administrator has deleted group :group
*
* @param string $group
*
* @return void
*/
public function theAdministratorHasDeletedGroup(string $group): void {
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
$response = $this->userDeletesGroupWithGroupId($groupId);
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
}
/**
* @Then the following users should be listed in the following groups
*

View File

@@ -222,18 +222,11 @@ trait Provisioning {
$usersList = $this->getCreatedUsers();
$normalizedUsername = $this->normalizeUsername($user);
if (\array_key_exists($normalizedUsername, $usersList)) {
// provide attributes only if the user exists
if ($usersList[$normalizedUsername]["shouldExist"]) {
if (\array_key_exists($attribute, $usersList[$normalizedUsername])) {
return $usersList[$normalizedUsername][$attribute];
} else {
throw new Exception(
__METHOD__ . ": User '$user' has no attribute with name '$attribute'."
);
}
if (\array_key_exists($attribute, $usersList[$normalizedUsername])) {
return $usersList[$normalizedUsername][$attribute];
} else {
throw new Exception(
__METHOD__ . ": User '$user' has been deleted."
__METHOD__ . ": User '$user' has no attribute with name '$attribute'."
);
}
} else {
@@ -251,18 +244,11 @@ trait Provisioning {
public function getAttributeOfCreatedGroup(string $group, string $attribute) {
$groupsList = $this->getCreatedGroups();
if (\array_key_exists($group, $groupsList)) {
// provide attributes only if the group exists
if ($groupsList[$group]["shouldExist"]) {
if (\array_key_exists($attribute, $groupsList[$group])) {
return $groupsList[$group][$attribute];
} else {
throw new Exception(
__METHOD__ . ": Group '$group' has no attribute with name '$attribute'."
);
}
if (\array_key_exists($attribute, $groupsList[$group])) {
return $groupsList[$group][$attribute];
} else {
throw new Exception(
__METHOD__ . ": Group '$group' has been deleted."
__METHOD__ . ": Group '$group' has no attribute with name '$attribute'."
);
}
} else {
@@ -1361,22 +1347,6 @@ trait Provisioning {
$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);
$response = $this->deleteUser($user);
$this->theHttpStatusCodeShouldBe(204, "", $response);
WebDavHelper::removeSpaceIdReferenceForUser($user);
$this->userShouldNotExist($user);
}
/**
* @When /^the administrator deletes user "([^"]*)" using the provisioning API$/
*
@@ -1929,8 +1899,10 @@ trait Provisioning {
} else {
$response = $this->deleteUser($user);
$this->theHTTPStatusCodeShouldBe(204, "", $response);
WebDavHelper::removeSpaceIdReferenceForUser($user);
}
}
$this->rememberThatUserIsNotExpectedToExist($user);
$this->userShouldNotExist($user);
}
@@ -2213,6 +2185,7 @@ trait Provisioning {
$normalizedUsername = $this->normalizeUsername($user);
if (\array_key_exists($normalizedUsername, $this->createdUsers)) {
$this->createdUsers[$normalizedUsername]['shouldExist'] = false;
$this->createdUsers[$normalizedUsername]['possibleToDelete'] = false;
}
}
@@ -2316,7 +2289,8 @@ trait Provisioning {
if ($this->isTestingWithLdap()) {
$this->deleteLdapGroup($group);
} else {
$this->graphContext->adminDeletesGroupUsingTheGraphApi($group);
$response = $this->graphContext->deleteGroupWithName($group);
$this->theHTTPStatusCodeShouldBe(204, "", $response);
}
} catch (Exception $e) {
\error_log(
@@ -2623,6 +2597,7 @@ trait Provisioning {
public function rememberThatGroupIsNotExpectedToExist(string $group):void {
if (\array_key_exists($group, $this->createdGroups)) {
$this->createdGroups[$group]['shouldExist'] = false;
$this->createdGroups[$group]['possibleToDelete'] = false;
}
}
@@ -3121,8 +3096,10 @@ trait Provisioning {
if ($this->isTestingWithLdap()) {
$this->deleteLdapGroup($group);
} else {
$this->graphContext->adminDeletesGroupUsingTheGraphApi($group);
$response = $this->graphContext->deleteGroupWithName($group);
$this->theHTTPStatusCodeShouldBe(204, "", $response);
}
$this->rememberThatGroupIsNotExpectedToExist($group);
$this->groupShouldNotExist($group);
}
@@ -4247,22 +4224,24 @@ trait Provisioning {
$previousServer = $this->currentServer;
$this->usingServer('LOCAL');
foreach ($this->createdGroups as $group => $groupData) {
if ($this->isTestingWithLdap()) {
$this->cleanupGroup((string)$group);
} else {
$this->graphContext->adminDeletesGroupWithGroupId(
$groupData['id']
);
if ($groupData["possibleToDelete"]) {
if ($this->isTestingWithLdap()) {
$this->cleanupGroup((string)$group);
} else {
$response = $this->graphContext->deleteGroupWithId($groupData['id']);
$this->theHTTPStatusCodeShouldBe(204, "", $response);
}
}
}
$this->usingServer('REMOTE');
foreach ($this->createdRemoteGroups as $remoteGroup => $groupData) {
if ($this->isTestingWithLdap()) {
$this->cleanupGroup((string)$remoteGroup);
} else {
$this->graphContext->adminDeletesGroupWithGroupId(
$groupData['id']
);
if ($groupData["possibleToDelete"]) {
if ($this->isTestingWithLdap()) {
$this->cleanupGroup((string)$remoteGroup);
} else {
$response = $this->graphContext->deleteGroupWithId($groupData['id']);
$this->theHTTPStatusCodeShouldBe(204, "", $response);
}
}
}
$this->usingServer($previousServer);

View File

@@ -193,10 +193,16 @@ class SharingNgContext implements Context {
$sharees = array_map('trim', explode(',', $rows['sharee']));
$shareTypes = array_map('trim', explode(',', $rows['shareType']));
foreach ($sharees as $sharee) {
// for non-exiting group or user, generate random id
$shareeIds[] = $this->featureContext->getAttributeOfCreatedUser($sharee, 'id')
?: ($this->featureContext->getAttributeOfCreatedGroup($sharee, 'id') ?: WebDavHelper::generateUUIDv4());
foreach ($sharees as $index => $sharee) {
$shareType = $shareTypes[$index];
$shareeId = "";
if ($shareType === "user") {
$shareeId = $this->featureContext->getAttributeOfCreatedUser($sharee, 'id');
} elseif ($shareType === "group") {
$shareeId = $this->featureContext->getAttributeOfCreatedGroup($sharee, 'id');
}
// for non-existing group or user, generate random id
$shareeIds[] = $shareeId ?: WebDavHelper::generateUUIDv4();
}
}

View File

@@ -533,7 +533,7 @@ Feature: sharing
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
And user "Alice" has shared file "textfile0.txt" with user "Brian"
And user "Alice" has shared file "textfile0.txt" with user "Carol"
And the administrator has deleted user "Brian" using the provisioning API
And user "Brian" has been deleted
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"

View File

@@ -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 user "testtrashbin102" has been deleted
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"