Added test for sending share invitation to user with role

This commit is contained in:
Prarup Gurung
2023-12-18 13:08:45 +05:45
parent 39b6fe1750
commit 87d3762381
4 changed files with 233 additions and 1 deletions

View File

@@ -60,6 +60,13 @@ class GraphHelper {
return self::getUUIDv4Regex() . '\\\$' . self::getUUIDv4Regex();
}
/**
* @return string
*/
public static function getShareIdRegex(): string {
return self::getUUIDv4Regex() . ':' . self::getUUIDv4Regex() . ':' . self::getUUIDv4Regex();
}
/**
* Key name can consist of @@@
* This function separate such key and return its actual value from actual drive response which can be used for assertion
@@ -1532,4 +1539,79 @@ class GraphHelper {
self::getRequestHeaders()
);
}
/**
* Get the role id by name
*
* @param string $role
*
* @return string
*
*/
public static function getRoleIdByName(
string $role
): string {
switch ($role) {
case 'Viewer':
return 'b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5';
case 'Space Viewer':
return 'a8d5fe5e-96e3-418d-825b-534dbdf22b99';
case 'Editor':
return 'fb6c3e19-e378-47e5-b277-9732f9de6e21';
case 'Space Editor':
return '58c63c02-1d89-4572-916a-870abc5a1b7d';
case 'File Editor':
return '2d00ce52-1fc2-4dbc-8b95-a73b73395f5a';
case 'Co Owner':
return '3a4ba8e9-6a0d-4235-9140-0e7a34007abe';
case 'Uploader':
return '1c996275-f1c9-4e71-abdf-a42f6495e960';
case 'Manager':
return '312c0871-5ef7-4b3a-85b6-0e4074c64049';
}
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $spaceId
* @param string $itemId
* @param string $shareeId
* @param string|null $role
*
* @return ResponseInterface
* @throws \JsonException
*/
public static function sendSharingInvitation(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $spaceId,
string $itemId,
string $shareeId,
?string $role
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/invite");
$body = [];
$recipients['objectId'] = $shareeId;
$body['recipients'] = [$recipients];
if ($role !== null) {
$roleId = self::getRoleIdByName($role);
$body['roles'] = [$roleId];
}
return HttpRequestHelper::post(
$url,
$xRequestId,
$user,
$password,
self::getRequestHeaders(),
\json_encode($body)
);
}
}

View File

@@ -0,0 +1,98 @@
Feature: Send a sharing invitations
As the owner of a resource
I want to be able to send invitations to other users
So that they can have access to it
https://owncloud.dev/libre-graph-api/#/drives.permissions/Invite
Background:
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |
Scenario Outline: send sharing invitation to user with different roles via the Graph API
Given user "Alice" has uploaded file with content "to share" to "/textfile1.txt"
And user "Alice" has created folder "FolderToShare"
When user "Alice" sends the following share invitation using the Graph API:
| resourceType | <resource-type> |
| resource | <path> |
| space | Personal |
| sharee | Brian |
| shareType | user |
| role | <role> |
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
{
"type": "object",
"required": [
"value"
],
"properties": {
"value": {
"type": "array",
"items": {
"type": "object",
"required": [
"id",
"roles",
"grantedToV2"
],
"properties": {
"id": {
"type": "string",
"pattern": "^%share_id_pattern%$"
},
"roles": {
"type": "array",
"items": {
"type": "string",
"pattern": "^%role_id_pattern%$"
}
},
"grantedToV2": {
"type": "object",
"required": [
"user"
],
"properties": {
"user": {
"type": "object",
"required": [
"id",
"displayName"
],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"displayName": {
"type": "string",
"enum": [
"Brian Murphy"
]
}
}
}
}
}
}
}
}
}
}
"""
Examples:
| role | resource-type | path |
| Viewer | file | /textfile1.txt |
| File Editor | file | /textfile1.txt |
| Co Owner | file | /textfile1.txt |
| Manager | file | /textfile1.txt |
| Viewer | folder | FolderToShare |
| Editor | folder | FolderToShare |
| Co Owner | folder | FolderToShare |
| Uploader | folder | FolderToShare |
| Manager | folder | FolderToShare |

View File

@@ -2783,6 +2783,22 @@ class FeatureContext extends BehatVariablesContext {
$this, "getGroupIdByGroupName"
],
"parameter" => [$group]
],
[
"code" => "%role_id_pattern%",
"function" => [
__NAMESPACE__ . '\TestHelpers\GraphHelper',
"getUUIDv4Regex"
],
"parameter" => []
],
[
"code" => "%share_id_pattern%",
"function" => [
__NAMESPACE__ . '\TestHelpers\GraphHelper',
"getShareIdRegex"
],
"parameter" => []
]
];
if ($user !== null) {

View File

@@ -22,6 +22,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use TestHelpers\GraphHelper;
use Behat\Gherkin\Node\TableNode;
require_once 'bootstrap.php';
@@ -63,7 +64,7 @@ class SharingNgContext implements Context {
*/
public function theUserPermissionsListOfResource(string $user, string $fileOrFolder, string $resource, string $space):void {
$spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"];
if ($fileOrFolder === 'folder') {
$itemId = $this->spacesContext->getResourceId($user, $space, $resource);
} else {
@@ -80,4 +81,39 @@ class SharingNgContext implements Context {
)
);
}
/**
* @When /^user "([^"]*)" sends the following share invitation using the Graph API:$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function userSendsTheFollowingShareInvitationUsingTheGraphApi(string $user, TableNode $table) {
$rows = $table->getRowsHash();
$spaceId = ($this->spacesContext->getSpaceByName($user, $rows['space']))["id"];
$itemId = ($rows['resourceType'] === 'folder')
? $this->spacesContext->getResourceId($user, $rows['space'], $rows['resource'])
: $this->spacesContext->getFileId($user, $rows['space'], $rows['resource']);
$shareeId = ($rows['shareType'] === 'user')
? $this->featureContext->getAttributeOfCreatedUser($rows['sharee'], 'id')
: $this->featureContext->getAttributeOfCreatedGroup($rows['sharee'], 'id');
$this->featureContext->setResponse(
GraphHelper::sendSharingInvitation(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$spaceId,
$itemId,
$shareeId,
$rows['role']
)
);
}
}