diff --git a/.drone.star b/.drone.star index ae5dc3f9b6..faa2eb9643 100644 --- a/.drone.star +++ b/.drone.star @@ -77,6 +77,7 @@ config = { "apiSpacesDavOperation", "apiDepthInfinity", "apiLocks", + "apiSharingNg", ], "skip": False, }, diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index f5dbbc762b..524e9862b0 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -97,6 +97,17 @@ class GraphHelper { return $fullUrl; } + /** + * @param string $baseUrl + * @param string $path + * + * @return string + */ + public static function getBetaFullUrl(string $baseUrl, string $path): string { + $baseUrl = rtrim($baseUrl, "/"); + return $baseUrl . '/graph/v1beta1/' . $path; + } + /** * @param string $baseUrl * @param string $xRequestId @@ -1492,4 +1503,33 @@ class GraphHelper { $payload['preferredLanguage'] = $language; return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PATCH', $user, $password, null, \json_encode($payload)); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * @param string $spaceId + * @param string $itemId + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function getPermissionsList( + string $baseUrl, + string $xRequestId, + string $user, + string $password, + string $spaceId, + string $itemId + ): ResponseInterface { + $url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/permissions"); + return HttpRequestHelper::get( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders() + ); + } } diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 7f68eec93b..e955d84748 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -253,6 +253,15 @@ default: - WebDavLockingContext: - PublicWebDavContext: + apiSharingNg: + paths: + - '%paths.base%/../features/apiSharingNg' + context: *common_ldap_suite_context + contexts: + - FeatureContext: *common_feature_context_params + - SpacesContext: + - SharingNgContext: + extensions: rdx\behatvars\BehatVariablesExtension: ~ diff --git a/tests/acceptance/features/apiSharingNg/listPermissions.feature b/tests/acceptance/features/apiSharingNg/listPermissions.feature new file mode 100644 index 0000000000..a46edd99a6 --- /dev/null +++ b/tests/acceptance/features/apiSharingNg/listPermissions.feature @@ -0,0 +1,269 @@ +Feature: List a sharing permissions + https://owncloud.dev/libre-graph-api/#/drives.permissions/ListPermissions + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + + + Scenario: user lists permissions via the Graph API + Given user "Alice" has created folder "folder" + When user "Alice" gets permissions list for folder "folder" of the space "Personal" using the Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "@libre.graph.permissions.actions.allowedValues", + "@libre.graph.permissions.roles.allowedValues" + ], + "properties": { + "@libre.graph.permissions.actions.allowedValues": { + "type": "array", + "items": [ + { + "type": "string", + "required": [ + "libre.graph/driveItem/permissions/create", + "libre.graph/driveItem/children/create", + "libre.graph/driveItem/standard/delete", + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/quota/read", + "libre.graph/driveItem/content/read", + "libre.graph/driveItem/upload/create", + "libre.graph/driveItem/permissions/read", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/versions/read", + "libre.graph/driveItem/deleted/read", + "libre.graph/driveItem/path/update", + "libre.graph/driveItem/permissions/delete", + "libre.graph/driveItem/deleted/delete", + "libre.graph/driveItem/versions/update", + "libre.graph/driveItem/deleted/update", + "libre.graph/driveItem/basic/read", + "libre.graph/driveItem/permissions/update", + "libre.graph/driveItem/permissions/deny" + ] + } + ] + }, + "@libre.graph.permissions.roles.allowedValues": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id" + ], + "properties": { + "@libre.graph.weight": { + "type": "integer", + "enum": [ + 1 + ] + }, + "description": { + "type": "string", + "enum": [ + "Allows upload file or folder" + ] + }, + "displayName": { + "type": "string", + "enum": [ + "Uploader" + ] + }, + "id": { + "type": "string", + "enum": [ + "1c996275-f1c9-4e71-abdf-a42f6495e960" + ] + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id" + ], + "properties": { + "@libre.graph.weight": { + "type": "integer", + "enum": [ + 2 + ] + }, + "description": { + "type": "string", + "enum": [ + "Allows reading the shared file or folder" + ] + }, + "displayName": { + "type": "string", + "enum": [ + "Viewer" + ] + }, + "id": { + "type": "string", + "enum": [ + "b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5" + ] + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id" + ], + "properties": { + "@libre.graph.weight": { + "type": "integer", + "enum": [ + 3 + ] + }, + "description": { + "type": "string", + "enum": [ + "Allows reading and updating file" + ] + }, + "displayName": { + "type": "string", + "enum": [ + "Editor" + ] + }, + "id": { + "type": "string", + "enum": [ + "2d00ce52-1fc2-4dbc-8b95-a73b73395f5a" + ] + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id" + ], + "properties": { + "@libre.graph.weight": { + "type": "integer", + "enum": [ + 4 + ] + }, + "description": { + "type": "string", + "enum": [ + "Allows creating, reading, updating and deleting the shared file or folder" + ] + }, + "displayName": { + "type": "string", + "enum": [ + "Editor" + ] + }, + "id": { + "type": "string", + "enum": [ + "fb6c3e19-e378-47e5-b277-9732f9de6e21" + ] + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id" + ], + "properties": { + "@libre.graph.weight": { + "type": "integer", + "enum": [ + 5 + ] + }, + "description": { + "type": "string", + "enum": [ + "Grants co-owner permissions on a resource" + ] + }, + "displayName": { + "type": "string", + "enum": [ + "Co Owner" + ] + }, + "id": { + "type": "string", + "enum": [ + "3a4ba8e9-6a0d-4235-9140-0e7a34007abe" + ] + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id" + ], + "properties": { + "@libre.graph.weight": { + "type": "integer", + "enum": [ + 6 + ] + }, + "description": { + "type": "string", + "enum": [ + "Grants manager permissions on a resource. Semantically equivalent to co-owner" + ] + }, + "displayName": { + "type": "string", + "enum": [ + "Manager" + ] + }, + "id": { + "type": "string", + "enum": [ + "312c0871-5ef7-4b3a-85b6-0e4074c64049" + ] + } + } + } + ] + } + } + } + """ diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php new file mode 100644 index 0000000000..c3de67cd57 --- /dev/null +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -0,0 +1,83 @@ + + * + * @copyright Copyright (c) 2023, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +use Behat\Behat\Context\Context; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use TestHelpers\GraphHelper; + +require_once 'bootstrap.php'; + +/** + * Acceptance test steps related to testing sharing ng features + */ +class SharingNgContext implements Context { + private FeatureContext $featureContext; + private SpacesContext $spacesContext; + + /** + * This will run before EVERY scenario. + * It will set the properties for this object. + * + * @BeforeScenario + * + * @param BeforeScenarioScope $scope + * + * @return void + */ + public function before(BeforeScenarioScope $scope): void { + // Get the environment + $environment = $scope->getEnvironment(); + // Get all the contexts you need in this context from here + $this->featureContext = $environment->getContext('FeatureContext'); + $this->spacesContext = $environment->getContext('SpacesContext'); + } + + /** + * @When /^user "([^"]*)" gets permissions list for (folder|file) "([^"]*)" of the space "([^"]*)" using the Graph API$/ + * + * @param string $user + * @param string $fileOrFolder (file|folder) + * @param string $resource + * @param string $space + * + * @return void + * @throws Exception + */ + 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 { + $itemId = $this->spacesContext->getFileId($user, $space, $resource); + } + $this->featureContext->setResponse( + GraphHelper::getPermissionsList( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user), + $spaceId, + $itemId + ) + ); + } +}