Skip to content

Commit 6d43a0a

Browse files
committed
added test to share resources concurrently to federated user
1 parent 444f2cf commit 6d43a0a

File tree

3 files changed

+244
-0
lines changed

3 files changed

+244
-0
lines changed

tests/acceptance/bootstrap/OcmContext.php

+51
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
use TestHelpers\WebDavHelper;
2929
use TestHelpers\BehatHelper;
3030
use TestHelpers\HttpRequestHelper;
31+
use Behat\Gherkin\Node\TableNode;
32+
use TestHelpers\GraphHelper;
33+
use PHPUnit\Framework\Assert;
3134

3235
/**
3336
* Acceptance test steps related to testing federation share(ocm) features
@@ -403,4 +406,52 @@ public function userSendsPropfindRequestToFederatedShareWithDepthUsingTheWebdavA
403406
$response = $this->spacesContext->sendPropfindRequestToSpace($user, "", $share, null, $folderDepth, true);
404407
$this->featureContext->setResponse($response);
405408
}
409+
410+
/**
411+
* @Then user :sharee should have the following federated share shared by user :sharer
412+
*
413+
* @param string $sharee
414+
* @param string $sharer
415+
* @param TableNode $table
416+
*
417+
* @return void
418+
* @throws Exception
419+
* @throws GuzzleException
420+
*/
421+
public function userShouldHaveTheFollowingFederatedShareSharedByUserFromSpace(
422+
string $sharee,
423+
string $sharer,
424+
TableNode $table
425+
): void {
426+
$share = $table->getRowsHash();
427+
$response = GraphHelper::getSharesSharedWithMe(
428+
$this->featureContext->getBaseUrl(),
429+
$this->featureContext->getStepLineRef(),
430+
$sharee,
431+
$this->featureContext->getPasswordForUser($sharee)
432+
);
433+
$sharedWithMeList = HttpRequestHelper::getJsonDecodedResponseBodyContent($response)->value;
434+
$foundShareInSharedWithMe = false;
435+
foreach ($sharedWithMeList as $item) {
436+
if ($item->name === $share["resource"]) {
437+
foreach ($item->remoteItem->permissions as $permission) {
438+
$shareCreator = $permission->invitation->invitedBy->user->displayName;
439+
if ($shareCreator === $this->featureContext->getDisplayNameForUser($sharer)) {
440+
$foundShareInSharedWithMe = true;
441+
}
442+
$permissionsRole = $permission->roles[0];
443+
}
444+
}
445+
}
446+
Assert::assertSame(
447+
true,
448+
$foundShareInSharedWithMe,
449+
"Share " . $share["resource"] . " was not found in the shared-with-me list"
450+
);
451+
Assert::assertSame(
452+
$share["permissionsRole"],
453+
GraphHelper::getPermissionNameByPermissionRoleId($permissionsRole),
454+
"Expected permissions role " . $share["permissionsRole"] . " was not set for resource " . $share["resource"]
455+
);
456+
}
406457
}

tests/acceptance/bootstrap/SharingNgContext.php

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

tests/acceptance/features/apiOcm/share.feature

+114
Original file line numberDiff line numberDiff line change
@@ -1297,3 +1297,117 @@ Feature: an user shares resources using ScienceMesh application
12971297
And as user "Alice" the PROPFIND response should contain a resource "newFolder" with these key and value pairs:
12981298
| key | value |
12991299
| oc:name | newFolder |
1300+
1301+
1302+
Scenario: user shares multiple resources concurrently to a single federated user (Personal Space)
1303+
Given using server "LOCAL"
1304+
And user "Alice" has created the following folders
1305+
| path |
1306+
| folderToShare1 |
1307+
| folderToShare2 |
1308+
And user "Alice" has uploaded file with content "some content" to "textfile1.txt"
1309+
And user "Alice" has uploaded file with content "hello world" to "textfile2.txt"
1310+
When user "Alice" sends the following resources share invitation concurrently to federated user using the Graph API:
1311+
| resource | space | sharee | shareType | permissionsRole |
1312+
| folderToShare1 | Personal | Brian | user | Viewer |
1313+
| folderToShare2 | Personal | Brian | user | Editor |
1314+
| textfile1.txt | Personal | Brian | user | Viewer |
1315+
| textfile2.txt | Personal | Brian | user | File Editor |
1316+
Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively
1317+
And using server "REMOTE"
1318+
And user "Brian" should have the following federated share shared by user "Alice"
1319+
| resource | folderToShare1 |
1320+
| permissionsRole | Viewer |
1321+
And user "Brian" should have the following federated share shared by user "Alice"
1322+
| resource | folderToShare2 |
1323+
| permissionsRole | Editor |
1324+
And user "Brian" should have the following federated share shared by user "Alice"
1325+
| resource | textfile1.txt |
1326+
| permissionsRole | Viewer |
1327+
And user "Brian" should have a federated share "textfile2.txt" shared by user "Alice" from space "Personal"
1328+
1329+
1330+
Scenario: user shares multiple resources concurrently to a single federated user (Project Space)
1331+
Given using server "LOCAL"
1332+
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
1333+
And user "Alice" has created a space "new-space" with the default quota using the Graph API
1334+
And user "Alice" has created a folder "folderToShare1" in space "new-space"
1335+
And user "Alice" has created a folder "folderToShare2" in space "new-space"
1336+
And user "Alice" has uploaded a file inside space "new-space" with content "some content" to "textfile1.txt"
1337+
And user "Alice" has uploaded a file inside space "new-space" with content "hello world" to "textfile2.txt"
1338+
When user "Alice" sends the following resources share invitation concurrently to federated user using the Graph API:
1339+
| resource | space | sharee | shareType | permissionsRole |
1340+
| folderToShare1 | new-space | Brian | user | Viewer |
1341+
| folderToShare2 | new-space | Brian | user | Editor |
1342+
| textfile1.txt | new-space | Brian | user | Viewer |
1343+
| textfile2.txt | new-space | Brian | user | File Editor |
1344+
Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively
1345+
And using server "REMOTE"
1346+
And user "Brian" should have the following federated share shared by user "Alice"
1347+
| resource | folderToShare1 |
1348+
| permissionsRole | Viewer |
1349+
And user "Brian" should have the following federated share shared by user "Alice"
1350+
| resource | folderToShare2 |
1351+
| permissionsRole | Editor |
1352+
And user "Brian" should have the following federated share shared by user "Alice"
1353+
| resource | textfile1.txt |
1354+
| permissionsRole | Viewer |
1355+
And user "Brian" should have a federated share "textfile2.txt" shared by user "Alice" from space "new-space"
1356+
1357+
1358+
Scenario: user shares multiple resources concurrently to a single federated user
1359+
Given using server "LOCAL"
1360+
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
1361+
And user "Alice" has created a space "new-space" with the default quota using the Graph API
1362+
And user "Alice" has created folder "folderToShare1"
1363+
And user "Alice" has uploaded file with content "some content" to "textfile1.txt"
1364+
And user "Alice" has created a folder "folderToShare2" in space "new-space"
1365+
And user "Alice" has uploaded a file inside space "new-space" with content "hello world" to "textfile2.txt"
1366+
When user "Alice" sends the following resources share invitation concurrently to federated user using the Graph API:
1367+
| resource | space | sharee | shareType | permissionsRole |
1368+
| folderToShare1 | Personal | Brian | user | Viewer |
1369+
| folderToShare2 | new-space | Brian | user | Editor |
1370+
| textfile1.txt | Personal | Brian | user | Viewer |
1371+
| textfile2.txt | new-space | Brian | user | File Editor |
1372+
Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively
1373+
And using server "REMOTE"
1374+
And user "Brian" should have the following federated share shared by user "Alice"
1375+
| resource | folderToShare1 |
1376+
| permissionsRole | Viewer |
1377+
And user "Brian" should have the following federated share shared by user "Alice"
1378+
| resource | folderToShare2 |
1379+
| permissionsRole | Editor |
1380+
And user "Brian" should have the following federated share shared by user "Alice"
1381+
| resource | textfile1.txt |
1382+
| permissionsRole | Viewer |
1383+
And user "Brian" should have a federated share "textfile2.txt" shared by user "Alice" from space "new-space"
1384+
1385+
1386+
Scenario: user shares multiple resources concurrently to multiple federated users
1387+
Given user "Carol" has been created with default attributes
1388+
And "Carol" has accepted invitation
1389+
And using server "LOCAL"
1390+
And user "Alice" has created the following folders
1391+
| path |
1392+
| folderToShare1 |
1393+
| folderToShare2 |
1394+
And user "Alice" has uploaded file with content "some content" to "textfile1.txt"
1395+
And user "Alice" has uploaded file with content "hello world" to "textfile2.txt"
1396+
When user "Alice" sends the following resources share invitation concurrently to federated user using the Graph API:
1397+
| resource | space | sharee | shareType | permissionsRole |
1398+
| folderToShare1 | Personal | Brian | user | Viewer |
1399+
| folderToShare2 | Personal | Carol | user | Editor |
1400+
| textfile1.txt | Personal | Brian | user | Viewer |
1401+
| textfile2.txt | Personal | Carol | user | File Editor |
1402+
Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively
1403+
And using server "REMOTE"
1404+
And user "Brian" should have the following federated share shared by user "Alice"
1405+
| resource | folderToShare1 |
1406+
| permissionsRole | Viewer |
1407+
And user "Carol" should have the following federated share shared by user "Alice"
1408+
| resource | folderToShare2 |
1409+
| permissionsRole | Editor |
1410+
And user "Brian" should have the following federated share shared by user "Alice"
1411+
| resource | textfile1.txt |
1412+
| permissionsRole | Viewer |
1413+
And user "Carol" should have a federated share "textfile2.txt" shared by user "Alice" from space "Personal"

0 commit comments

Comments
 (0)