Skip to content

Commit 2a1df28

Browse files
committed
added test to share resources concurrently to federated user
1 parent d19378c commit 2a1df28

File tree

3 files changed

+135
-3
lines changed

3 files changed

+135
-3
lines changed

tests/acceptance/TestHelpers/GraphHelper.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public static function getBetaFullUrl(string $baseUrl, string $path): string {
213213
* @param string $xRequestId
214214
* @param string $method
215215
* @param string $path
216-
* @param string|null $body
216+
* @param string|array|null $body
217217
* @param array|null $headers
218218
*
219219
* @return RequestInterface
@@ -223,7 +223,7 @@ public static function createRequest(
223223
string $xRequestId,
224224
string $method,
225225
string $path,
226-
?string $body = null,
226+
$body = null,
227227
?array $headers = []
228228
): RequestInterface {
229229
$fullUrl = self::getFullUrl($baseUrl, $path);
@@ -1790,7 +1790,7 @@ public static function createShareInviteBody(
17901790
array $shareTypes,
17911791
?string $permissionsRole,
17921792
?string $permissionsAction,
1793-
?string $expirationDateTime
1793+
?string $expirationDateTime = null
17941794
): array {
17951795
$body = [];
17961796

@@ -1855,6 +1855,7 @@ public static function sendSharingInvitation(
18551855
$permissionsAction,
18561856
$expirationDateTime
18571857
);
1858+
var_dump($body);
18581859
return HttpRequestHelper::post(
18591860
$url,
18601861
$xRequestId,

tests/acceptance/bootstrap/SharingNgContext.php

+106
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,74 @@ public function userSendsTheFollowingResourceShareInvitationToFederatedUserUsing
524524
);
525525
}
526526

527+
/**
528+
* @When user :user sends the following resources share invitation concurrently to federated user using the Graph API:
529+
*
530+
* @param string $user
531+
* @param TableNode $table
532+
*/
533+
public function userSendsTheFollowingResourcesShareInvitationConcurrentlyToFederatedUserUsingTheGraphApi(string $user, TableNode $table): void {
534+
$table = $table->getColumnsHash();
535+
foreach ($table as $shareInfo) {
536+
if ($shareInfo['space'] === 'Personal' || $shareInfo['space'] === 'Shares') {
537+
$space = $this->spacesContext->getSpaceByName($user, $shareInfo['space']);
538+
} else {
539+
$space = $this->spacesContext->getCreatedSpace($shareInfo['space']);
540+
}
541+
$spaceId = $space['id'];
542+
543+
$resource = $shareInfo['resource'] ?? '';
544+
$itemId = $this->spacesContext->getResourceId($user, $shareInfo['space'], $resource);
545+
546+
$shareeId = (
547+
$this->featureContext->ocmContext->getAcceptedUserByName(
548+
$user,
549+
$shareInfo["sharee"]
550+
)
551+
)['user_id'];
552+
553+
$shareType = $shareInfo['shareType'];
554+
$permissionsRole = $shareInfo['permissionsRole'] ?? null;
555+
$roleId = GraphHelper::getPermissionsRoleIdByName($permissionsRole);
556+
557+
$body = [];
558+
$body['recipients'][] = [
559+
"@libre.graph.recipient.type" => $shareType,
560+
"objectId" => $shareeId
561+
];
562+
$body['roles'] = [$roleId];
563+
564+
$fullUrl = GraphHelper::getBetaFullUrl(
565+
$this->featureContext->getBaseUrl(),
566+
"drives/$spaceId/items/$itemId/invite"
567+
);
568+
569+
$request = HttpRequestHelper::createRequest(
570+
$fullUrl,
571+
$this->featureContext->getStepLineRef(),
572+
"POST",
573+
['Content-Type' => 'application/json'],
574+
\json_encode($body)
575+
);
576+
$requests[] = $request;
577+
}
578+
579+
$client = HttpRequestHelper::createClient(
580+
$this->featureContext->getActualUsername($user),
581+
$this->featureContext->getPasswordForUser($user)
582+
);
583+
584+
$results = HttpRequestHelper::sendBatchRequest($requests, $client);
585+
// var_dump($results);
586+
foreach ($results as $result) {
587+
var_dump($result->getBody()->getContents());
588+
$this->featureContext->pushToLastHttpStatusCodesArray((string)$result->getStatusCode());
589+
if ($result->getStatusCode() === 200) {
590+
$this->featureContext->shareNgAddToCreatedUserGroupShares($result);
591+
}
592+
}
593+
}
594+
527595
/**
528596
* @When /^user "([^"]*)" sends the following space share invitation using permissions endpoint of the Graph API:$/
529597
*
@@ -2043,6 +2111,44 @@ public function userShouldOrShouldNotHaveFederatedShareSharedByUserFromSpace(
20432111
$this->checkIfShareExists($share, $sharee, $sharer, $space, $shouldOrNot === "should", true);
20442112
}
20452113

2114+
/**
2115+
* @Then user :sharee should have the following federated share shared by user :sharer from space :space
2116+
*
2117+
* @param string $sharee
2118+
* @param string $sharer
2119+
* @param string $space
2120+
* @param TableNode $table
2121+
*/
2122+
public function userShouldHaveTheFollowingFederatedShareSharedByUserFromSpace(string $sharee, string $sharer, string $space, TableNode $table): void
2123+
{
2124+
$share = $table->getRowsHash();
2125+
$response = GraphHelper::getSharesSharedWithMe(
2126+
$this->featureContext->getBaseUrl(),
2127+
$this->featureContext->getStepLineRef(),
2128+
$sharee,
2129+
$this->featureContext->getPasswordForUser($sharee)
2130+
);
2131+
$sharedWithMeList = HttpRequestHelper::getJsonDecodedResponseBodyContent($response)->value;
2132+
foreach ($sharedWithMeList as $item) {
2133+
if ($item->name === $share["resource"]) {
2134+
foreach ($item->remoteItem->permissions as $permission) {
2135+
$shareCreator = $permission->invitation->invitedBy->user->displayName;
2136+
$permissionsRole = $permission->roles[0];
2137+
Assert::assertEquals(
2138+
$this->featureContext->getDisplayNameForUser($sharer),
2139+
$shareCreator,
2140+
"Expected sharer to be '$sharer' but got '$shareCreator'"
2141+
);
2142+
Assert::assertEquals(
2143+
$share["permissionsRole"],
2144+
GraphHelper::getPermissionNameByPermissionRoleId($permissionsRole),
2145+
"Error "
2146+
);
2147+
}
2148+
}
2149+
}
2150+
}
2151+
20462152
/**
20472153
* @Given /^user "([^"]*)" has shared the following (?:files|folders) from space "([^"]*)" with user "([^"]*)" and role "([^"]*)":$/
20482154
*

tests/acceptance/features/apiOcm/share.feature

+25
Original file line numberDiff line numberDiff line change
@@ -1189,3 +1189,28 @@ Feature: an user shares resources using ScienceMesh application
11891189
And user "Brian" should not have a federated share "folderToShare" shared by user "Alice" from space "Personal"
11901190
And using server "LOCAL"
11911191
And as "Alice" file "folderToShare/file.txt" should not exist
1192+
1193+
1194+
Scenario: concurrent sharing
1195+
Given using server "LOCAL"
1196+
And user "Alice" has created the following folders
1197+
| path |
1198+
| folderToShare1 |
1199+
| folderToShare2 |
1200+
| folderToShare3 |
1201+
When user "Alice" sends the following resources share invitation concurrently to federated user using the Graph API:
1202+
| resource | space | sharee | shareType | permissionsRole |
1203+
| folderToShare1 | Personal | Brian | user | Viewer |
1204+
| folderToShare2 | Personal | Brian | user | Editor |
1205+
| folderToShare3 | Personal | Brian | user | Uploader |
1206+
Then the HTTP status code of responses on each endpoint should be "200, 200, 200" respectively
1207+
And using server "REMOTE"
1208+
And user "Brian" should have the following federated share shared by user "Alice" from space "Personal"
1209+
| resource | folderToShare |
1210+
| permissionsRole | Viewer |
1211+
# And user "Brian" should have the following federated share shared by user "Alice" from space "Personal"
1212+
# | resource | folderToShare2 |
1213+
# | permissionsRole | Editor |
1214+
# And user "Brian" should have the following federated share shared by user "Alice" from space "Personal"
1215+
# | resource | folderToShare3 |
1216+
# | permissionsRole | Uploader |

0 commit comments

Comments
 (0)