From f21c668312760857b600a99dc237acd5140cbc27 Mon Sep 17 00:00:00 2001 From: Prajwol Amatya Date: Thu, 20 Feb 2025 14:51:30 +0545 Subject: [PATCH] added test to share resources concurrently to federated user --- tests/acceptance/bootstrap/OcmContext.php | 49 +++++++++ .../acceptance/bootstrap/SharingNgContext.php | 76 +++++++++++++ .../acceptance/features/apiOcm/share.feature | 100 ++++++++++++++++++ 3 files changed, 225 insertions(+) diff --git a/tests/acceptance/bootstrap/OcmContext.php b/tests/acceptance/bootstrap/OcmContext.php index 11db1054608..09a56b6f230 100644 --- a/tests/acceptance/bootstrap/OcmContext.php +++ b/tests/acceptance/bootstrap/OcmContext.php @@ -28,6 +28,9 @@ use TestHelpers\OcmHelper; use TestHelpers\WebDavHelper; use TestHelpers\BehatHelper; use TestHelpers\HttpRequestHelper; +use Behat\Gherkin\Node\TableNode; +use TestHelpers\GraphHelper; +use PHPUnit\Framework\Assert; /** * Acceptance test steps related to testing federation share(ocm) features @@ -403,4 +406,50 @@ class OcmContext implements Context { $response = $this->spacesContext->sendPropfindRequestToSpace($user, "", $share, null, $folderDepth, true); $this->featureContext->setResponse($response); } + + /** + * @Then user :sharee should have the following federated shares: + * + * @param string $sharee + * @param TableNode $table + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function userShouldHaveTheFollowingFederatedShares(string $sharee, TableNode $table): void { + $shares = $table->getColumnsHash(); + $response = GraphHelper::getSharesSharedWithMe( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $sharee, + $this->featureContext->getPasswordForUser($sharee) + ); + $sharedWithMeList = HttpRequestHelper::getJsonDecodedResponseBodyContent($response)->value; + foreach ($shares as $share) { + $foundShareInSharedWithMe = false; + foreach ($sharedWithMeList as $item) { + if ($item->name === $share["resource"]) { + foreach ($item->remoteItem->permissions as $permission) { + $shareCreator = $permission->invitation->invitedBy->user->displayName; + if ($shareCreator === $this->featureContext->getDisplayNameForUser($share["sharer"])) { + $foundShareInSharedWithMe = true; + $permissionsRole = $permission->roles[0]; + } + } + } + } + Assert::assertSame( + true, + $foundShareInSharedWithMe, + "Share " . $share["resource"] . " was not found in the shared-with-me list" + ); + Assert::assertSame( + $share["permissionsRole"], + GraphHelper::getPermissionNameByPermissionRoleId($permissionsRole), + "Expected permissions role " . $share["permissionsRole"] . + " was not set for resource " . $share["resource"] + ); + } + } } diff --git a/tests/acceptance/bootstrap/SharingNgContext.php b/tests/acceptance/bootstrap/SharingNgContext.php index 746b74d6106..725e1af24de 100644 --- a/tests/acceptance/bootstrap/SharingNgContext.php +++ b/tests/acceptance/bootstrap/SharingNgContext.php @@ -524,6 +524,82 @@ class SharingNgContext implements Context { ); } + /** + * @When user :user sends the following concurrent resource share invitations to federated user using the Graph API: + * + * @param string $user + * @param TableNode $table + * + * @return void + */ + public function userSendsTheFollowingResourcesShareInvitationConcurrentlyToFederatedUserUsingTheGraphApi( + string $user, + TableNode $table + ): void { + $results = $this->sendConcurrentShareInvitation($user, $table); + foreach ($results as $result) { + $this->featureContext->pushToLastHttpStatusCodesArray((string)$result->getStatusCode()); + } + } + + /** + * @param string $user + * @param TableNode $table + * + * @return array + * @throws GuzzleException + * @throws JsonException + */ + public function sendConcurrentShareInvitation(string $user, TableNode $table): array { + $table = $table->getColumnsHash(); + foreach ($table as $shareInfo) { + $space = $this->spacesContext->getSpaceByName($user, $shareInfo['space']); + $spaceId = $space['id']; + + $resource = $shareInfo['resource'] ?? ''; + $itemId = $this->spacesContext->getResourceId($user, $shareInfo['space'], $resource); + + $shareeId = ( + $this->featureContext->ocmContext->getAcceptedUserByName( + $user, + $shareInfo["sharee"] + ) + )['user_id']; + + $shareType = $shareInfo['shareType']; + $permissionsRole = $shareInfo['permissionsRole'] ?? null; + $roleId = GraphHelper::getPermissionsRoleIdByName($permissionsRole); + + $body = []; + $body['recipients'][] = [ + "@libre.graph.recipient.type" => $shareType, + "objectId" => $shareeId + ]; + $body['roles'] = [$roleId]; + + $fullUrl = GraphHelper::getBetaFullUrl( + $this->featureContext->getBaseUrl(), + "drives/$spaceId/items/$itemId/invite" + ); + + $request = HttpRequestHelper::createRequest( + $fullUrl, + $this->featureContext->getStepLineRef(), + "POST", + ['Content-Type' => 'application/json'], + \json_encode($body) + ); + $requests[] = $request; + } + + $client = HttpRequestHelper::createClient( + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user) + ); + + return HttpRequestHelper::sendBatchRequest($requests, $client); + } + /** * @When /^user "([^"]*)" sends the following space share invitation using permissions endpoint of the Graph API:$/ * diff --git a/tests/acceptance/features/apiOcm/share.feature b/tests/acceptance/features/apiOcm/share.feature index 0d4018f8aaf..ec5effa8f7b 100755 --- a/tests/acceptance/features/apiOcm/share.feature +++ b/tests/acceptance/features/apiOcm/share.feature @@ -1390,3 +1390,103 @@ Feature: an user shares resources using ScienceMesh application } } """ + + + Scenario: local user shares multiple resources concurrently to a single federated user (Personal Space) + Given using server "LOCAL" + And user "Alice" has created the following folders + | path | + | folderToShare1 | + | folderToShare2 | + And user "Alice" has uploaded file with content "some content" to "textfile1.txt" + And user "Alice" has uploaded file with content "hello world" to "textfile2.txt" + When user "Alice" sends the following concurrent resource share invitations to federated user using the Graph API: + | resource | space | sharee | shareType | permissionsRole | + | folderToShare1 | Personal | Brian | user | Viewer | + | folderToShare2 | Personal | Brian | user | Editor | + | textfile1.txt | Personal | Brian | user | Viewer | + | textfile2.txt | Personal | Brian | user | File Editor | + Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively + And using server "REMOTE" + And user "Brian" should have the following federated shares: + | resource | permissionsRole | sharer | + | folderToShare1 | Viewer | Alice | + | folderToShare2 | Editor | Alice | + | textfile1.txt | Viewer | Alice | + | textfile2.txt | File Editor | Alice | + + + Scenario: local user shares multiple resources concurrently to a single federated user (Project Space) + Given using server "LOCAL" + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "new-space" with the default quota using the Graph API + And user "Alice" has created a folder "folderToShare1" in space "new-space" + And user "Alice" has created a folder "folderToShare2" in space "new-space" + And user "Alice" has uploaded a file inside space "new-space" with content "some content" to "textfile1.txt" + And user "Alice" has uploaded a file inside space "new-space" with content "hello world" to "textfile2.txt" + When user "Alice" sends the following concurrent resource share invitations to federated user using the Graph API: + | resource | space | sharee | shareType | permissionsRole | + | folderToShare1 | new-space | Brian | user | Viewer | + | folderToShare2 | new-space | Brian | user | Editor | + | textfile1.txt | new-space | Brian | user | Viewer | + | textfile2.txt | new-space | Brian | user | File Editor | + Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively + And using server "REMOTE" + And user "Brian" should have the following federated shares: + | resource | permissionsRole | sharer | + | folderToShare1 | Viewer | Alice | + | folderToShare2 | Editor | Alice | + | textfile1.txt | Viewer | Alice | + | textfile2.txt | File Editor | Alice | + + + Scenario: local user shares multiple resources form different spaces concurrently to a single federated user + Given using server "LOCAL" + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "new-space" with the default quota using the Graph API + And user "Alice" has created folder "folderToShare1" + And user "Alice" has uploaded file with content "some content" to "textfile1.txt" + And user "Alice" has created a folder "folderToShare2" in space "new-space" + And user "Alice" has uploaded a file inside space "new-space" with content "hello world" to "textfile2.txt" + When user "Alice" sends the following concurrent resource share invitations to federated user using the Graph API: + | resource | space | sharee | shareType | permissionsRole | + | folderToShare1 | Personal | Brian | user | Viewer | + | folderToShare2 | new-space | Brian | user | Editor | + | textfile1.txt | Personal | Brian | user | Viewer | + | textfile2.txt | new-space | Brian | user | File Editor | + Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively + And using server "REMOTE" + And user "Brian" should have the following federated shares: + | resource | permissionsRole | sharer | + | folderToShare1 | Viewer | Alice | + | folderToShare2 | Editor | Alice | + | textfile1.txt | Viewer | Alice | + | textfile2.txt | File Editor | Alice | + + + Scenario: local user shares multiple resources concurrently to multiple federated users + Given user "Carol" has been created with default attributes + And "Carol" has accepted invitation + And using server "LOCAL" + And user "Alice" has created the following folders + | path | + | folderToShare1 | + | folderToShare2 | + And user "Alice" has uploaded file with content "some content" to "textfile1.txt" + And user "Alice" has uploaded file with content "hello world" to "textfile2.txt" + When user "Alice" sends the following concurrent resource share invitations to federated user using the Graph API: + | resource | space | sharee | shareType | permissionsRole | + | folderToShare1 | Personal | Brian | user | Viewer | + | folderToShare2 | Personal | Carol | user | Editor | + | textfile1.txt | Personal | Brian | user | Viewer | + | textfile2.txt | Personal | Carol | user | File Editor | + Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively + And using server "REMOTE" + And user "Brian" should have the following federated shares: + | resource | permissionsRole | sharer | + | folderToShare1 | Viewer | Alice | + | textfile1.txt | Viewer | Alice | + And user "Carol" should have the following federated shares: + | resource | permissionsRole | sharer | + | folderToShare2 | Editor | Alice | + | textfile2.txt | File Editor | Alice |