Skip to content

Commit 09b93d6

Browse files
committed
added test to share resources concurrently to federated user
1 parent 04875ba commit 09b93d6

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

tests/acceptance/bootstrap/SharingNgContext.php

+122
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,86 @@ 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+
* @return void
534+
*/
535+
public function userSendsTheFollowingResourcesShareInvitationConcurrentlyToFederatedUserUsingTheGraphApi(
536+
string $user,
537+
TableNode $table
538+
): void {
539+
$results = $this->sendConcurrentShareInvitation($user, $table);
540+
foreach ($results as $result) {
541+
var_dump($result->getBody()->getContents());
542+
$this->featureContext->pushToLastHttpStatusCodesArray((string)$result->getStatusCode());
543+
if ($result->getStatusCode() === 200) {
544+
$this->featureContext->shareNgAddToCreatedUserGroupShares($result);
545+
}
546+
}
547+
}
548+
549+
/**
550+
* @param string $user
551+
* @param TableNode $table
552+
*
553+
* @return array
554+
* @throws GuzzleException
555+
* @throws JsonException
556+
*/
557+
public function sendConcurrentShareInvitation(string $user, TableNode $table): array {
558+
$table = $table->getColumnsHash();
559+
foreach ($table as $shareInfo) {
560+
$space = $this->spacesContext->getSpaceByName($user, $shareInfo['space']);
561+
$spaceId = $space['id'];
562+
563+
$resource = $shareInfo['resource'] ?? '';
564+
$itemId = $this->spacesContext->getResourceId($user, $shareInfo['space'], $resource);
565+
566+
$shareeId = (
567+
$this->featureContext->ocmContext->getAcceptedUserByName(
568+
$user,
569+
$shareInfo["sharee"]
570+
)
571+
)['user_id'];
572+
573+
$shareType = $shareInfo['shareType'];
574+
$permissionsRole = $shareInfo['permissionsRole'] ?? null;
575+
$roleId = GraphHelper::getPermissionsRoleIdByName($permissionsRole);
576+
577+
$body = [];
578+
$body['recipients'][] = [
579+
"@libre.graph.recipient.type" => $shareType,
580+
"objectId" => $shareeId
581+
];
582+
$body['roles'] = [$roleId];
583+
584+
$fullUrl = GraphHelper::getBetaFullUrl(
585+
$this->featureContext->getBaseUrl(),
586+
"drives/$spaceId/items/$itemId/invite"
587+
);
588+
589+
$request = HttpRequestHelper::createRequest(
590+
$fullUrl,
591+
$this->featureContext->getStepLineRef(),
592+
"POST",
593+
['Content-Type' => 'application/json'],
594+
\json_encode($body)
595+
);
596+
$requests[] = $request;
597+
}
598+
599+
$client = HttpRequestHelper::createClient(
600+
$this->featureContext->getActualUsername($user),
601+
$this->featureContext->getPasswordForUser($user)
602+
);
603+
604+
return HttpRequestHelper::sendBatchRequest($requests, $client);
605+
}
606+
527607
/**
528608
* @When /^user "([^"]*)" sends the following space share invitation using permissions endpoint of the Graph API:$/
529609
*
@@ -2043,6 +2123,48 @@ public function userShouldOrShouldNotHaveFederatedShareSharedByUserFromSpace(
20432123
$this->checkIfShareExists($share, $sharee, $sharer, $space, $shouldOrNot === "should", true);
20442124
}
20452125

2126+
/**
2127+
* @Then user :sharee should have the following federated share shared by user :sharer
2128+
*
2129+
* @param string $sharee
2130+
* @param string $sharer
2131+
* @param TableNode $table
2132+
*
2133+
* @return void
2134+
*/
2135+
public function userShouldHaveTheFollowingFederatedShareSharedByUserFromSpace(
2136+
string $sharee,
2137+
string $sharer,
2138+
TableNode $table
2139+
): void {
2140+
$share = $table->getRowsHash();
2141+
$response = GraphHelper::getSharesSharedWithMe(
2142+
$this->featureContext->getBaseUrl(),
2143+
$this->featureContext->getStepLineRef(),
2144+
$sharee,
2145+
$this->featureContext->getPasswordForUser($sharee)
2146+
);
2147+
$sharedWithMeList = HttpRequestHelper::getJsonDecodedResponseBodyContent($response)->value;
2148+
foreach ($sharedWithMeList as $item) {
2149+
if ($item->name === $share["resource"]) {
2150+
foreach ($item->remoteItem->permissions as $permission) {
2151+
$shareCreator = $permission->invitation->invitedBy->user->displayName;
2152+
$permissionsRole = $permission->roles[0];
2153+
Assert::assertEquals(
2154+
$this->featureContext->getDisplayNameForUser($sharer),
2155+
$shareCreator,
2156+
"Expected sharer to be '$sharer' but got '$shareCreator'"
2157+
);
2158+
Assert::assertEquals(
2159+
$share["permissionsRole"],
2160+
GraphHelper::getPermissionNameByPermissionRoleId($permissionsRole),
2161+
"Error "
2162+
);
2163+
}
2164+
}
2165+
}
2166+
}
2167+
20462168
/**
20472169
* @Given /^user "([^"]*)" has shared the following (?:files|folders) from space "([^"]*)" with user "([^"]*)" and role "([^"]*)":$/
20482170
*

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"
1209+
| resource | folderToShare1 |
1210+
| permissionsRole | Viewer |
1211+
And user "Brian" should have the following federated share shared by user "Alice"
1212+
| resource | folderToShare2 |
1213+
| permissionsRole | Editor |
1214+
And user "Brian" should have the following federated share shared by user "Alice"
1215+
| resource | folderToShare3 |
1216+
| permissionsRole | Uploader |

0 commit comments

Comments
 (0)