[tests-only][full-ci]Added tests for creating link for a resource (#7982)

* Added tests for creating link for a resource

* review adress and refactor
This commit is contained in:
Sagar Gurung
2023-12-20 17:01:02 +05:45
committed by GitHub
parent 439d963e7d
commit 65b8c1a767
4 changed files with 227 additions and 0 deletions
+32
View File
@@ -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
);
}
}
@@ -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.
@@ -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 | <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": ["<role>"]
},
"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 | <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": ["<role>"]
},
"webUrl": {
"type": "string",
"pattern": "^%base_url%\/s\/[a-zA-Z]{15}$"
}
}
}
}
}
"""
Examples:
| role |
| view |
| edit |
| blocksDownload |
@@ -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)
)
);
}
}