add tests to check activites of file after public edits it

Signed-off-by: prashant-gurung899 <prasantgrg777@gmail.com>
This commit is contained in:
prashant-gurung899
2024-10-01 12:40:07 +05:45
parent 2c03dd0807
commit c12ec0af3f
6 changed files with 513 additions and 30 deletions

View File

@@ -123,24 +123,23 @@ class PublicWebDavContext implements Context {
/**
* @param string $fileName
* @param string $publicWebDAVAPIVersion
* @param string $password
*
* @return ResponseInterface
*/
public function deleteFileFromPublicShare(string $fileName, string $publicWebDAVAPIVersion, string $password = ""):ResponseInterface {
public function deleteFileFromPublicShare(string $fileName, string $password = ""):ResponseInterface {
$token = ($this->featureContext->isUsingSharingNG()) ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() : $this->featureContext->getLastCreatedPublicShareToken();
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-$publicWebDAVAPIVersion"
"public-files-new"
);
$password = $this->featureContext->getActualPassword($password);
$fullUrl = $this->featureContext->getBaseUrl() . "/$davPath$fileName";
$userName = $this->getUsernameForPublicWebdavApi(
$token,
$password,
$publicWebDAVAPIVersion
"new"
);
$headers = [
'X-Requested-With' => 'XMLHttpRequest'
@@ -155,20 +154,29 @@ class PublicWebDavContext implements Context {
}
/**
* @When /^the public deletes (?:file|folder|entry) "([^"]*)" from the last public link share using the password "([^"]*)" and (old|new) public WebDAV API$/
* @Given /^the public has deleted (?:file|folder|entry) "([^"]*)" from the last link share with password "([^"]*)" using the public WebDAV API$/
*
* @param string $file
* @param string $password
* @param string $publicWebDAVAPIVersion
*
* @return void
*/
public function thePublicDeletesFileFromTheLastPublicShareUsingThePasswordPasswordAndOldPublicWebdavApi(string $file, string $password, string $publicWebDAVAPIVersion):void {
if ($publicWebDAVAPIVersion === "old") {
return;
}
public function thePublicHasDeletedFileFromTheLastLinkShareWithPasswordUsingPublicWebdavApi(string $file, string $password): void {
$response = $this->deleteFileFromPublicShare($file, $password);
$this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response);
}
/**
* @When /^the public deletes (?:file|folder|entry) "([^"]*)" from the last link share with password "([^"]*)" using the public WebDAV API$/
*
* @param string $file
* @param string $password
*
* @return void
*/
public function thePublicDeletesFileFromTheLastLinkShareWithPasswordUsingPublicWebdavApi(string $file, string $password): void {
$this->featureContext->setResponse(
$this->deleteFileFromPublicShare($file, $publicWebDAVAPIVersion, $password)
$this->deleteFileFromPublicShare($file, $password)
);
$this->featureContext->pushToLastStatusCodesArrays();
}
@@ -534,7 +542,6 @@ class PublicWebDavContext implements Context {
* @param string $filename target file name
* @param string $password
* @param string $body content to upload
* @param string $publicWebDAVAPIVersion
*
* @return ResponseInterface
*/
@@ -542,7 +549,6 @@ class PublicWebDavContext implements Context {
string $filename,
string $password = '',
string $body = 'test',
string $publicWebDAVAPIVersion = "old"
):ResponseInterface {
return $this->publicUploadContent(
$filename,
@@ -550,10 +556,27 @@ class PublicWebDavContext implements Context {
$body,
true,
[],
$publicWebDAVAPIVersion
);
}
/**
* @Given /^the public has uploaded file "([^"]*)" with content "([^"]*)" and password "([^"]*)" to the last link share using the public WebDAV API$/
*
* @param string $filename
* @param string $content
* @param string $password
*
* @return void
*/
public function thePublicHasUploadedFileWithContentAndPasswordToLastLinkShareUsingPublicWebdavApi(string $filename, string $content = 'test', string $password = ''): void {
$response = $this->publiclyUploadingContentWithPassword(
$filename,
$password,
$content,
);
$this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response);
}
/**
* @When /^the public uploads file "([^"]*)" with password "([^"]*)" and content "([^"]*)" using the (old|new) public WebDAV API$/
*
@@ -1690,7 +1713,6 @@ class PublicWebDavContext implements Context {
* @param string $body
* @param bool $autoRename
* @param array $additionalHeaders
* @param string $publicWebDAVAPIVersion
*
* @return ResponseInterface|null
*/
@@ -1700,11 +1722,7 @@ class PublicWebDavContext implements Context {
string $body = 'test',
bool $autoRename = false,
array $additionalHeaders = [],
string $publicWebDAVAPIVersion = "old"
):?ResponseInterface {
if ($publicWebDAVAPIVersion === "old") {
return null;
}
$password = $this->featureContext->getActualPassword($password);
if ($this->featureContext->isUsingSharingNG()) {
$token = $this->featureContext->shareNgGetLastCreatedLinkShareToken();
@@ -1714,13 +1732,13 @@ class PublicWebDavContext implements Context {
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-$publicWebDAVAPIVersion"
"public-files-new"
);
$url = $this->featureContext->getBaseUrl() . "/$davPath";
$userName = $this->getUsernameForPublicWebdavApi(
$token,
$password,
$publicWebDAVAPIVersion
"new"
);
$filename = \implode(

View File

@@ -403,6 +403,7 @@ default:
- FeatureContext: *common_feature_context_params
- SharingNgContext:
- GraphContext:
- PublicWebDavContext:
apiCollaboration:
paths:

View File

@@ -1104,3 +1104,467 @@ Feature: check share activity
| permissionsRole | Viewer |
When user "Brian" tries to list the activities of file "anotherTextfile.txt" from space "Personal" owned by user "Alice" using the Graph API
Then the HTTP status code should be "403"
@issue-9676
Scenario: user checks public activities of a link shared file
Given using SharingNG
And user "Alice" has created the following resource link share:
| resource | textfile.txt |
| space | Personal |
| permissionsRole | edit |
| password | %public% |
And the public has uploaded file "textfile.txt" with content "public test" and password "%public%" to the last link share using the public WebDAV API
When user "Alice" lists the activities of file "textfile.txt" from 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": ["value"],
"properties": {
"value": {
"type": "array",
"minItems": 3,
"maxItems": 3,
"uniqueItems": true,
"items": {
"oneOf": [
{
"type": "object",
"required": ["id","template","times"],
"properties": {
"template": {
"type": "object",
"required": ["message","variables"],
"properties": {
"message": {
"const": "{user} added {resource} to {folder}"
}
}
}
}
},
{
"type": "object",
"required": ["id","template","times"],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"template": {
"type": "object",
"required": ["message","variables"],
"properties": {
"message": {
"const": "{user} shared {resource} via link"
}
}
}
}
},
{
"type": "object",
"required": ["id","template","times"],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"template": {
"type": "object",
"required": ["message","variables"],
"properties": {
"message": {
"const": "{user} updated {resource} in {folder}"
},
"variables": {
"type": "object",
"required": ["folder","resource","user"],
"properties": {
"folder": {
"type": "object",
"required": ["id","name"],
"properties": {
"id": {
"type": "string",
"pattern": "%user_id_pattern%"
},
"name": {
"const": "Alice Hansen"
}
}
},
"resource": {
"type": "object",
"required": ["id","name"],
"properties": {
"id": {
"type": "string",
"pattern": "%file_id_pattern%"
},
"displayName": {
"const": "textfile.txt"
}
}
},
"user": {
"type": "object",
"required": ["id","displayName"],
"properties": {
"id": {
"type": "string",
"pattern": "[a-zA-z]{15}"
},
"displayName": {
"const": "Public"
}
}
}
}
}
}
},
"times": {
"type": "object",
"required": ["recordedTime"],
"properties": {
"recordedTime": {
"type": "string",
"format": "date-time"
}
}
}
}
}
]
}
}
}
}
"""
@issue-9676
Scenario: user checks public activities of a link shared folder
Given using SharingNG
And user "Alice" has created folder "/FOLDER"
And user "Alice" has created the following resource link share:
| resource | /FOLDER |
| space | Personal |
| permissionsRole | edit |
| password | %public% |
And the public has uploaded file "text.txt" with content "added by public user" and password "%public%" to the last link share using the public WebDAV API
And the public has uploaded file "text.txt" with content "updated by public user" and password "%public%" to the last link share using the public WebDAV API
And the public has deleted file "text.txt" from the last link share with password "%public%" using the public WebDAV API
When user "Alice" lists the activities of file "/FOLDER" from 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": ["value"],
"properties": {
"value": {
"type": "array",
"minItems": 5,
"maxItems": 5,
"uniqueItems": true,
"items": {
"oneOf": [
{
"type": "object",
"required": ["id","template","times"],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"template": {
"type": "object",
"required": ["message","variables"],
"properties": {
"message": {
"const": "{user} added {resource} to {folder}"
},
"variables": {
"type": "object",
"required": ["folder","resource","user"],
"properties": {
"folder": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "Alice Hansen"
}
}
},
"resource": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "FOLDER"
}
}
},
"user": {
"type": "object",
"required": ["id","displayName"],
"properties": {
"id": {
"type": "string",
"pattern": "%user_id_pattern%"
},
"displayName": {
"const": "Alice Hansen"
}
}
}
}
}
}
}
}
},
{
"type": "object",
"required": ["id","template","times"],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"template": {
"type": "object",
"required": ["message","variables"],
"properties": {
"message": {
"const": "{user} shared {resource} via link"
},
"variables": {
"type": "object",
"required": ["folder","resource","user"],
"properties": {
"folder": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "Alice Hansen"
}
}
},
"resource": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "FOLDER"
}
}
},
"user": {
"type": "object",
"required": ["id","displayName"],
"properties": {
"id": {
"type": "string",
"pattern": "%user_id_pattern%"
},
"displayName": {
"const": "Alice Hansen"
}
}
}
}
}
}
}
}
},
{
"type": "object",
"required": ["id","template","times"],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"template": {
"type": "object",
"required": ["message","variables"],
"properties": {
"message": {
"const": "{user} added {resource} to {folder}"
},
"variables": {
"type": "object",
"required": ["folder","resource","user"],
"properties": {
"folder": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "FOLDER"
}
}
},
"resource": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "text.txt"
}
}
},
"user": {
"type": "object",
"required": ["id","displayName"],
"properties": {
"id": {
"type": "string",
"pattern": "[a-zA-z]{15}"
},
"displayName": {
"const": "Public"
}
}
}
}
}
}
}
}
},
{
"type": "object",
"required": ["id","template","times"],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"template": {
"type": "object",
"required": ["message","variables"],
"properties": {
"message": {
"const": "{user} updated {resource} in {folder}"
},
"variables": {
"type": "object",
"required": ["folder","resource","user"],
"properties": {
"folder": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "FOLDER"
}
}
},
"resource": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "text.txt"
}
}
},
"user": {
"type": "object",
"required": ["id","displayName"],
"properties": {
"id": {
"type": "string",
"pattern": "[a-zA-z]{15}"
},
"displayName": {
"const": "Public"
}
}
}
}
}
}
}
}
},
{
"type": "object",
"required": ["id","template","times"],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"template": {
"type": "object",
"required": ["message","variables"],
"properties": {
"message": {
"const": "{user} deleted {resource} from {folder}"
},
"variables": {
"type": "object",
"required": ["folder","resource","user"],
"properties": {
"folder": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "Alice Hansen"
}
}
},
"resource": {
"type": "object",
"required": ["id","name"],
"properties": {
"name": {
"const": "text.txt"
}
}
},
"user": {
"type": "object",
"required": ["id","displayName"],
"properties": {
"id": {
"type": "string",
"pattern": "[a-zA-z]{15}"
},
"displayName": {
"const": "Public"
}
}
}
}
}
}
},
"times": {
"type": "object",
"required": ["recordedTime"],
"properties": {
"recordedTime": {
"type": "string",
"format": "date-time"
}
}
}
}
}
]
}
}
}
}
"""

View File

@@ -19,7 +19,7 @@ Feature: changing a public link share
| space | Personal |
| permissionsRole | <permissions-role> |
| password | %public% |
When the public deletes file "parent.txt" from the last public link share using the password "%public%" and new public WebDAV API
When the public deletes file "parent.txt" from the last link share with password "%public%" using the public WebDAV API
Then the HTTP status code should be "<http-status-code>"
And as "Alice" file "PARENT/parent.txt" <should-or-not> exist
Examples:
@@ -62,7 +62,7 @@ Feature: changing a public link share
| space | Personal |
| permissionsRole | edit |
| password | %public% |
When the public deletes file "parent.txt" from the last public link share using the password "invalid" and new public WebDAV API
When the public deletes file "parent.txt" from the last link share with password "invalid" using the public WebDAV API
Then the HTTP status code should be "401"
And as "Alice" file "PARENT/parent.txt" should exist
@@ -74,7 +74,7 @@ Feature: changing a public link share
| space | Personal |
| permissionsRole | edit |
| password | %public% |
When the public deletes file "parent.txt" from the last public link share using the password "%public%" and new public WebDAV API
When the public deletes file "parent.txt" from the last link share with password "%public%" using the public WebDAV API
Then the HTTP status code should be "204"
And as "Alice" file "PARENT/parent.txt" should not exist
@@ -149,7 +149,7 @@ Feature: changing a public link share
| space | Personal |
| permissionsRole | createOnly |
| password | %public% |
When the public deletes file "parent.txt" from the last public link share using the password "%public%" and new public WebDAV API
When the public deletes file "parent.txt" from the last link share with password "%public%" using the public WebDAV API
Then the HTTP status code should be "403"
And as "Alice" file "PARENT/parent.txt" should exist

View File

@@ -241,7 +241,7 @@ Feature: update a public link share
| resource | PARENT |
| space | Personal |
| permissionsRole | view |
When the public deletes file "CHILD/child.txt" from the last public link share using the password "%public%" and new public WebDAV API
When the public deletes file "CHILD/child.txt" from the last link share with password "%public%" using the public WebDAV API
Then the HTTP status code of responses on all endpoints should be "403"
And as "Alice" file "PARENT/CHILD/child.txt" should exist
Examples:
@@ -266,8 +266,8 @@ Feature: update a public link share
| resource | PARENT |
| space | Personal |
| permissionsRole | edit |
When the public deletes file "CHILD/child.txt" from the last public link share using the password "%public%" and new public WebDAV API
And the public deletes file "parent.txt" from the last public link share using the password "%public%" and new public WebDAV API
When the public deletes file "CHILD/child.txt" from the last link share with password "%public%" using the public WebDAV API
And the public deletes file "parent.txt" from the last link share with password "%public%" using the public WebDAV API
Then the HTTP status code of responses on all endpoints should be "204"
And as "Alice" file "PARENT/CHILD/child.txt" should not exist
And as "Alice" file "PARENT/parent.txt" should not exist

View File

@@ -227,7 +227,7 @@ Feature: propagation of etags when deleting a file or folder
| password | %public% |
And user "Alice" has stored etag of element "/"
And user "Alice" has stored etag of element "/upload"
When the public deletes file "file.txt" from the last public link share using the password "%public%" and new public WebDAV API
When the public deletes file "file.txt" from the last link share with password "%public%" using the public WebDAV API
Then the HTTP status code should be "204"
And these etags should have changed:
| user | path |
@@ -251,7 +251,7 @@ Feature: propagation of etags when deleting a file or folder
| password | %public% |
And user "Alice" has stored etag of element "/"
And user "Alice" has stored etag of element "/upload"
When the public deletes folder "sub" from the last public link share using the password "%public%" and new public WebDAV API
When the public deletes folder "sub" from the last link share with password "%public%" using the public WebDAV API
Then the HTTP status code should be "204"
And these etags should have changed:
| user | path |