Skip to content

Commit

Permalink
[tests-only] do not try to delete already deleted groups (#8886)
Browse files Browse the repository at this point in the history
* fix(test): do not try to delete already deleted groups

* test: remove redundant steps

* test: fix php code style

* fix typo
  • Loading branch information
saw-jan authored Apr 18, 2024
1 parent 2e87088 commit 2f32fa3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/features/apiSharingNg/sharedByMe.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 9 additions & 32 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function adminHasRetrievedUserUsingTheGraphApi(string $user): ResponseInt
* @return ResponseInterface
* @throws GuzzleException
*/
public function userDeletesGroupWithGroupId(
public function deleteGroupWithId(
string $groupId,
?string $user = null
): ResponseInterface {
Expand All @@ -289,31 +289,18 @@ public function userDeletesGroupWithGroupId(
);
}

/**
* @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);
}

/**
Expand Down Expand Up @@ -1054,23 +1041,13 @@ public function userRetrievesAllMemberInformationOfSingleOrAllGroups(string $use
*/
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
*
Expand Down
79 changes: 29 additions & 50 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,11 @@ public function getAttributeOfCreatedUser(string $user, string $attribute) {
$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 {
Expand All @@ -251,18 +244,11 @@ public function getAttributeOfCreatedUser(string $user, string $attribute) {
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 {
Expand Down Expand Up @@ -1361,22 +1347,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);
$response = $this->deleteUser($user);
$this->theHttpStatusCodeShouldBe(204, "", $response);
WebDavHelper::removeSpaceIdReferenceForUser($user);
$this->userShouldNotExist($user);
}

/**
* @When /^the administrator deletes user "([^"]*)" using the provisioning API$/
*
Expand Down Expand Up @@ -1929,8 +1899,10 @@ public function userHasBeenDeleted(string $user):void {
} else {
$response = $this->deleteUser($user);
$this->theHTTPStatusCodeShouldBe(204, "", $response);
WebDavHelper::removeSpaceIdReferenceForUser($user);
}
}
$this->rememberThatUserIsNotExpectedToExist($user);
$this->userShouldNotExist($user);
}

Expand Down Expand Up @@ -2213,6 +2185,7 @@ public function rememberThatUserIsNotExpectedToExist(string $user):void {
$normalizedUsername = $this->normalizeUsername($user);
if (\array_key_exists($normalizedUsername, $this->createdUsers)) {
$this->createdUsers[$normalizedUsername]['shouldExist'] = false;
$this->createdUsers[$normalizedUsername]['possibleToDelete'] = false;
}
}

Expand Down Expand Up @@ -2316,7 +2289,8 @@ public function cleanupGroup(string $group):void {
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(
Expand Down Expand Up @@ -2623,6 +2597,7 @@ public function addGroupToCreatedGroupsList(
public function rememberThatGroupIsNotExpectedToExist(string $group):void {
if (\array_key_exists($group, $this->createdGroups)) {
$this->createdGroups[$group]['shouldExist'] = false;
$this->createdGroups[$group]['possibleToDelete'] = false;
}
}

Expand Down Expand Up @@ -3121,8 +3096,10 @@ public function groupHasBeenDeleted(string $group):void {
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);
}

Expand Down Expand Up @@ -4247,22 +4224,24 @@ public function cleanupDatabaseGroups():void {
$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);
Expand Down
14 changes: 10 additions & 4 deletions tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,16 @@ public function sendShareInvitation(string $user, TableNode $table, string $file
$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();
}
}

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

0 comments on commit 2f32fa3

Please sign in to comment.