From df1da2ca3d9de7d438293f4c55674e00b63a5ecd Mon Sep 17 00:00:00 2001 From: prashant-gurung899 Date: Tue, 1 Oct 2024 12:40:07 +0545 Subject: [PATCH] add tests to check activites of file after public edits it Signed-off-by: prashant-gurung899 --- .../bootstrap/PublicWebDavContext.php | 50 +- tests/acceptance/config/behat.yml | 1 + .../apiActivities/shareActivities.feature | 464 ++++++++++++++++++ 3 files changed, 501 insertions(+), 14 deletions(-) diff --git a/tests/acceptance/bootstrap/PublicWebDavContext.php b/tests/acceptance/bootstrap/PublicWebDavContext.php index 3d8c3e326cf..5e871115a47 100644 --- a/tests/acceptance/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/bootstrap/PublicWebDavContext.php @@ -123,24 +123,23 @@ public function thePublicDeletesFileFolderFromTheLastPublicLinkShareUsingThePubl /** * @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' @@ -154,6 +153,19 @@ public function deleteFileFromPublicShare(string $fileName, string $publicWebDAV ); } + /** + * @Given /^the public has deleted (?:file|folder|entry) "([^"]*)" from the last public link share with password "([^"]*)" using the public WebDAV API$/ + * + * @param string $file + * @param string $password + * + * @return void + */ + public function thePublicHasDeletedFileFromTheLastPublicLinkShareUsingThePasswordAndNewPublicWebdavApi(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 public link share using the password "([^"]*)" and (old|new) public WebDAV API$/ * @@ -534,7 +546,6 @@ public function thePublicHasUploadedFileWithContentWithAutoRenameMode(string $fi * @param string $filename target file name * @param string $password * @param string $body content to upload - * @param string $publicWebDAVAPIVersion * * @return ResponseInterface */ @@ -542,7 +553,6 @@ public function publiclyUploadingContentWithPassword( string $filename, string $password = '', string $body = 'test', - string $publicWebDAVAPIVersion = "old" ):ResponseInterface { return $this->publicUploadContent( $filename, @@ -550,10 +560,27 @@ public function publiclyUploadingContentWithPassword( $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 thePublicHasUploadedFileWithPasswordAndContentUsingTheNewPublicWebdavApi(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 +1717,6 @@ public function theMtimeOfFileInTheLastSharedPublicLinkUsingTheWebdavApiShouldNo * @param string $body * @param bool $autoRename * @param array $additionalHeaders - * @param string $publicWebDAVAPIVersion * * @return ResponseInterface|null */ @@ -1700,11 +1726,7 @@ public function publicUploadContent( 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 +1736,13 @@ public function publicUploadContent( $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( diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 77adc1a097e..476e8717c52 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -403,6 +403,7 @@ default: - FeatureContext: *common_feature_context_params - SharingNgContext: - GraphContext: + - PublicWebDavContext: apiCollaboration: paths: diff --git a/tests/acceptance/features/apiActivities/shareActivities.feature b/tests/acceptance/features/apiActivities/shareActivities.feature index 08e6df6c9cf..2357f5ebf51 100644 --- a/tests/acceptance/features/apiActivities/shareActivities.feature +++ b/tests/acceptance/features/apiActivities/shareActivities.feature @@ -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 public 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" + } + } + } + } + } + ] + } + } + } + } + """ +