Skip to content

Commit ef32f48

Browse files
committed
added test to share resources concurrently to federated user
1 parent 84a91b3 commit ef32f48

File tree

3 files changed

+252
-0
lines changed

3 files changed

+252
-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

+122
Original file line numberDiff line numberDiff line change
@@ -1297,3 +1297,125 @@ 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: local 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 the following federated share shared by user "Alice"
1328+
| resource | textfile2.txt |
1329+
| permissionsRole | File Editor |
1330+
1331+
1332+
Scenario: local user shares multiple resources concurrently to a single federated user (Project Space)
1333+
Given using server "LOCAL"
1334+
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
1335+
And user "Alice" has created a space "new-space" with the default quota using the Graph API
1336+
And user "Alice" has created a folder "folderToShare1" in space "new-space"
1337+
And user "Alice" has created a folder "folderToShare2" in space "new-space"
1338+
And user "Alice" has uploaded a file inside space "new-space" with content "some content" to "textfile1.txt"
1339+
And user "Alice" has uploaded a file inside space "new-space" with content "hello world" to "textfile2.txt"
1340+
When user "Alice" sends the following resources share invitation concurrently to federated user using the Graph API:
1341+
| resource | space | sharee | shareType | permissionsRole |
1342+
| folderToShare1 | new-space | Brian | user | Viewer |
1343+
| folderToShare2 | new-space | Brian | user | Editor |
1344+
| textfile1.txt | new-space | Brian | user | Viewer |
1345+
| textfile2.txt | new-space | Brian | user | File Editor |
1346+
Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively
1347+
And using server "REMOTE"
1348+
And user "Brian" should have the following federated share shared by user "Alice"
1349+
| resource | folderToShare1 |
1350+
| permissionsRole | Viewer |
1351+
And user "Brian" should have the following federated share shared by user "Alice"
1352+
| resource | folderToShare2 |
1353+
| permissionsRole | Editor |
1354+
And user "Brian" should have the following federated share shared by user "Alice"
1355+
| resource | textfile1.txt |
1356+
| permissionsRole | Viewer |
1357+
And user "Brian" should have the following federated share shared by user "Alice"
1358+
| resource | textfile2.txt |
1359+
| permissionsRole | File Editor |
1360+
1361+
1362+
Scenario: local user shares multiple resources form different spaces concurrently to a single federated user
1363+
Given using server "LOCAL"
1364+
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
1365+
And user "Alice" has created a space "new-space" with the default quota using the Graph API
1366+
And user "Alice" has created folder "folderToShare1"
1367+
And user "Alice" has uploaded file with content "some content" to "textfile1.txt"
1368+
And user "Alice" has created a folder "folderToShare2" in space "new-space"
1369+
And user "Alice" has uploaded a file inside space "new-space" with content "hello world" to "textfile2.txt"
1370+
When user "Alice" sends the following resources share invitation concurrently to federated user using the Graph API:
1371+
| resource | space | sharee | shareType | permissionsRole |
1372+
| folderToShare1 | Personal | Brian | user | Viewer |
1373+
| folderToShare2 | new-space | Brian | user | Editor |
1374+
| textfile1.txt | Personal | Brian | user | Viewer |
1375+
| textfile2.txt | new-space | Brian | user | File Editor |
1376+
Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively
1377+
And using server "REMOTE"
1378+
And user "Brian" should have the following federated share shared by user "Alice"
1379+
| resource | folderToShare1 |
1380+
| permissionsRole | Viewer |
1381+
And user "Brian" should have the following federated share shared by user "Alice"
1382+
| resource | folderToShare2 |
1383+
| permissionsRole | Editor |
1384+
And user "Brian" should have the following federated share shared by user "Alice"
1385+
| resource | textfile1.txt |
1386+
| permissionsRole | Viewer |
1387+
And user "Brian" should have the following federated share shared by user "Alice"
1388+
| resource | textfile2.txt |
1389+
| permissionsRole | File Editor |
1390+
1391+
1392+
Scenario: local user shares multiple resources concurrently to multiple federated users
1393+
Given user "Carol" has been created with default attributes
1394+
And "Carol" has accepted invitation
1395+
And using server "LOCAL"
1396+
And user "Alice" has created the following folders
1397+
| path |
1398+
| folderToShare1 |
1399+
| folderToShare2 |
1400+
And user "Alice" has uploaded file with content "some content" to "textfile1.txt"
1401+
And user "Alice" has uploaded file with content "hello world" to "textfile2.txt"
1402+
When user "Alice" sends the following resources share invitation concurrently to federated user using the Graph API:
1403+
| resource | space | sharee | shareType | permissionsRole |
1404+
| folderToShare1 | Personal | Brian | user | Viewer |
1405+
| folderToShare2 | Personal | Carol | user | Editor |
1406+
| textfile1.txt | Personal | Brian | user | Viewer |
1407+
| textfile2.txt | Personal | Carol | user | File Editor |
1408+
Then the HTTP status code of responses on each endpoint should be "200, 200, 200, 200" respectively
1409+
And using server "REMOTE"
1410+
And user "Brian" should have the following federated share shared by user "Alice"
1411+
| resource | folderToShare1 |
1412+
| permissionsRole | Viewer |
1413+
And user "Carol" should have the following federated share shared by user "Alice"
1414+
| resource | folderToShare2 |
1415+
| permissionsRole | Editor |
1416+
And user "Brian" should have the following federated share shared by user "Alice"
1417+
| resource | textfile1.txt |
1418+
| permissionsRole | Viewer |
1419+
And user "Carol" should have the following federated share shared by user "Alice"
1420+
| resource | textfile2.txt |
1421+
| permissionsRole | File Editor |

0 commit comments

Comments
 (0)