diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 64ca26fc6f..684ad2c932 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -1618,4 +1618,36 @@ class GraphHelper { \json_encode($body) ); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * @param string $spaceId + * @param string $itemId + * @param mixed $body + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function createLinkShare( + string $baseUrl, + string $xRequestId, + string $user, + string $password, + string $spaceId, + string $itemId, + $body + ): ResponseInterface { + $url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/createLink"); + return HttpRequestHelper::post( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders(), + $body + ); + } } diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index a8a56f05ef..ae74e32324 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -255,6 +255,9 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiLocks/lockFiles.feature:456](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiLocks/lockFiles.feature#L456) - [apiLocks/lockFiles.feature:457](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiLocks/lockFiles.feature#L457) +### [blocksDownload link type is not implemented yet (sharing-ng)](https://github.com/owncloud/ocis/issues/7879) +- [apiSharingNg/createLink.feature:78](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSharingNg/createLink.feature#L78) +- [apiSharingNg/createLink.feature:147](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSharingNg/createLink.feature#L147) - Note: always have an empty line at the end of this file. The bash script that processes this file requires that the last line has a newline on the end. diff --git a/tests/acceptance/features/apiSharingNg/createLink.feature b/tests/acceptance/features/apiSharingNg/createLink.feature new file mode 100644 index 0000000000..5eeadb4bdd --- /dev/null +++ b/tests/acceptance/features/apiSharingNg/createLink.feature @@ -0,0 +1,147 @@ +Feature: Create a share link for a resource + https://owncloud.dev/libre-graph-api/#/drives.permissions/CreateLink + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + + + Scenario Outline: create a link share of a folder + Given user "Alice" has created folder "folder" + When user "Alice" creates the following link share using the Graph API: + | resourceType | folder | + | resource | folder | + | space | Personal | + | role | | + | password | %public% | + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "hasPassword", + "id", + "link" + ], + "properties": { + "hasPassword": { + "type": "boolean", + "enum": [true] + }, + "id": { + "type": "string", + "pattern": "^[a-zA-Z]{15}$" + }, + "link": { + "type": "object", + "required": [ + "@libre.graph.displayName", + "@libre.graph.quickLink", + "preventsDownload", + "type", + "webUrl" + ], + "properties": { + "@libre.graph.displayName": { + "type": "string", + "enum": [""] + }, + "@libre.graph.quickLink": { + "type": "boolean", + "enum": [false] + }, + "preventsDownload": { + "type": "boolean", + "enum": [false] + }, + "type": { + "type": "string", + "enum": [""] + }, + "webUrl": { + "type": "string", + "pattern": "^%base_url%\/s\/[a-zA-Z]{15}$" + } + } + } + } + } + """ + Examples: + | role | + | view | + | edit | + | upload | + | createOnly | + | blocksDownload | + + + Scenario Outline: create a link share of a file + Given user "Alice" has uploaded file with content "other data" to "textfile1.txt" + When user "Alice" creates the following link share using the Graph API: + | resourceType | file | + | resource | textfile1.txt | + | space | Personal | + | role | | + | password | %public% | + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "hasPassword", + "id", + "link" + ], + "properties": { + "hasPassword": { + "type": "boolean", + "enum": [true] + }, + "id": { + "type": "string", + "pattern": "^[a-zA-Z]{15}$" + }, + "link": { + "type": "object", + "required": [ + "@libre.graph.displayName", + "@libre.graph.quickLink", + "preventsDownload", + "type", + "webUrl" + ], + "properties": { + "@libre.graph.displayName": { + "type": "string", + "enum": [""] + }, + "@libre.graph.quickLink": { + "type": "boolean", + "enum": [false] + }, + "preventsDownload": { + "type": "boolean", + "enum": [false] + }, + "type": { + "type": "string", + "enum": [""] + }, + "webUrl": { + "type": "string", + "pattern": "^%base_url%\/s\/[a-zA-Z]{15}$" + } + } + } + } + } + """ + Examples: + | role | + | view | + | edit | + | blocksDownload | diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index eb92be9a44..4116b6da04 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -21,6 +21,7 @@ use Behat\Behat\Context\Context; use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use PHPUnit\Framework\Assert; use TestHelpers\GraphHelper; use Behat\Gherkin\Node\TableNode; @@ -117,4 +118,48 @@ class SharingNgContext implements Context { ) ); } + + /** + * @When /^user "([^"]*)" creates the following link share using the Graph API:$/ + * + * @param string $user + * @param TableNode|null $body + * + * @return void + * @throws Exception + */ + public function userCreatesAPublicLinkShareWithSettings(string $user, TableNode $body):void { + $bodyRows = $body->getRowsHash(); + $space = $bodyRows['space']; + $resourceType = $bodyRows['resourceType']; + $resource = $bodyRows['resource']; + + $spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"]; + if ($resourceType === 'folder') { + $itemId = $this->spacesContext->getResourceId($user, $space, $resource); + } else { + $itemId = $this->spacesContext->getFileId($user, $space, $resource); + } + + $bodyRows['displayName'] = \array_key_exists('displayName', $bodyRows) ? $bodyRows['displayName'] : null; + $bodyRows['expirationDateTime'] = \array_key_exists('expirationDateTime', $bodyRows) ? $bodyRows['expirationDateTime'] : null; + $body = [ + 'type' => $bodyRows['role'], + 'displayName' => $bodyRows['displayName'], + 'expirationDateTime' => $bodyRows['expirationDateTime'], + 'password' => $this->featureContext->getActualPassword($bodyRows['password']) + ]; + + $this->featureContext->setResponse( + GraphHelper::createLinkShare( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user), + $spaceId, + $itemId, + \json_encode($body) + ) + ); + } }