Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci] added test to share resources concurrently to federated user #11039

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/acceptance/bootstrap/OcmContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
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
Expand Down Expand Up @@ -403,4 +406,52 @@ public function userSendsPropfindRequestToFederatedShareWithDepthUsingTheWebdavA
$response = $this->spacesContext->sendPropfindRequestToSpace($user, "", $share, null, $folderDepth, true);
$this->featureContext->setResponse($response);
}

/**
* @Then user :sharee should have the following federated share shared by user :sharer
*
* @param string $sharee
* @param string $sharer
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userShouldHaveTheFollowingFederatedShareSharedByUserFromSpace(
string $sharee,
string $sharer,
TableNode $table
): void {
$share = $table->getRowsHash();
$response = GraphHelper::getSharesSharedWithMe(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$sharee,
$this->featureContext->getPasswordForUser($sharee)
);
$sharedWithMeList = HttpRequestHelper::getJsonDecodedResponseBodyContent($response)->value;
$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($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"]
);
}
}
76 changes: 76 additions & 0 deletions tests/acceptance/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,82 @@ public function userSendsTheFollowingResourceShareInvitationToFederatedUserUsing
);
}

/**
* @When user :user sends the following resources share invitation concurrently 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:$/
*
Expand Down
122 changes: 122 additions & 0 deletions tests/acceptance/features/apiOcm/share.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1390,3 +1390,125 @@ 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 resources share invitation concurrently to federated user using the Graph API:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When user "Alice" sends the following resources share invitation concurrently to federated user using the Graph API:
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 share shared by user "Alice"
| resource | folderToShare1 |
| permissionsRole | Viewer |
Comment on lines +1412 to +1413
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do something like this

Suggested change
| resource | folderToShare1 |
| permissionsRole | Viewer |
| resource | permissionsRole |
| folderToShare1 | Viewer |
| folderToShare2 | Editor |
| folderToShare1 | Viewer |
...

Comment on lines +1411 to +1413
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
And user "Brian" should have the following federated share shared by user "Alice"
| resource | folderToShare1 |
| permissionsRole | Viewer |
And user "Brian" should have the following federated shares:
| resource | permissionsRole | sharer |
| folderToShare1 | Viewer | Alice |
| folderToShare2 | Editor | Alice |
| folderToShare1 | Viewer | Alice |

And user "Brian" should have the following federated share shared by user "Alice"
| resource | folderToShare2 |
| permissionsRole | Editor |
And user "Brian" should have the following federated share shared by user "Alice"
| resource | textfile1.txt |
| permissionsRole | Viewer |
And user "Brian" should have the following federated share shared by user "Alice"
| resource | textfile2.txt |
| permissionsRole | File Editor |


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 resources share invitation concurrently 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 share shared by user "Alice"
| resource | folderToShare1 |
| permissionsRole | Viewer |
And user "Brian" should have the following federated share shared by user "Alice"
| resource | folderToShare2 |
| permissionsRole | Editor |
And user "Brian" should have the following federated share shared by user "Alice"
| resource | textfile1.txt |
| permissionsRole | Viewer |
And user "Brian" should have the following federated share shared by user "Alice"
| resource | textfile2.txt |
| permissionsRole | File Editor |


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 resources share invitation concurrently 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 share shared by user "Alice"
| resource | folderToShare1 |
| permissionsRole | Viewer |
And user "Brian" should have the following federated share shared by user "Alice"
| resource | folderToShare2 |
| permissionsRole | Editor |
And user "Brian" should have the following federated share shared by user "Alice"
| resource | textfile1.txt |
| permissionsRole | Viewer |
And user "Brian" should have the following federated share shared by user "Alice"
| resource | textfile2.txt |
| permissionsRole | File Editor |


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 resources share invitation concurrently 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 share shared by user "Alice"
| resource | folderToShare1 |
| permissionsRole | Viewer |
And user "Carol" should have the following federated share shared by user "Alice"
| resource | folderToShare2 |
| permissionsRole | Editor |
And user "Brian" should have the following federated share shared by user "Alice"
| resource | textfile1.txt |
| permissionsRole | Viewer |
And user "Carol" should have the following federated share shared by user "Alice"
| resource | textfile2.txt |
| permissionsRole | File Editor |