From c12ec0af3f1f0f5bd409d1d26b4433472c67d453 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 | 60 ++- tests/acceptance/config/behat.yml | 1 + .../apiActivities/shareActivities.feature | 464 ++++++++++++++++++ .../changingPublicLinkShare.feature | 8 +- .../updatePublicLinkShare.feature | 6 +- .../deleteFileFolder.feature | 4 +- 6 files changed, 513 insertions(+), 30 deletions(-) diff --git a/tests/acceptance/bootstrap/PublicWebDavContext.php b/tests/acceptance/bootstrap/PublicWebDavContext.php index 3d8c3e326cf..fccd271b6f7 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' @@ -155,20 +154,29 @@ public function deleteFileFromPublicShare(string $fileName, string $publicWebDAV } /** - * @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 @@ 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 +549,6 @@ public function publiclyUploadingContentWithPassword( string $filename, string $password = '', string $body = 'test', - string $publicWebDAVAPIVersion = "old" ):ResponseInterface { return $this->publicUploadContent( $filename, @@ -550,10 +556,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 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 @@ public function theMtimeOfFileInTheLastSharedPublicLinkUsingTheWebdavApiShouldNo * @param string $body * @param bool $autoRename * @param array $additionalHeaders - * @param string $publicWebDAVAPIVersion * * @return ResponseInterface|null */ @@ -1700,11 +1722,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 +1732,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..ac00d0403df 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 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" + } + } + } + } + } + ] + } + } + } + } + """ + diff --git a/tests/acceptance/features/coreApiSharePublicLink1/changingPublicLinkShare.feature b/tests/acceptance/features/coreApiSharePublicLink1/changingPublicLinkShare.feature index 3f2b3f1f8e5..3bcdbee939a 100644 --- a/tests/acceptance/features/coreApiSharePublicLink1/changingPublicLinkShare.feature +++ b/tests/acceptance/features/coreApiSharePublicLink1/changingPublicLinkShare.feature @@ -19,7 +19,7 @@ Feature: changing a public link share | space | Personal | | permissionsRole | | | 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 "" And as "Alice" file "PARENT/parent.txt" 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 diff --git a/tests/acceptance/features/coreApiSharePublicLink2/updatePublicLinkShare.feature b/tests/acceptance/features/coreApiSharePublicLink2/updatePublicLinkShare.feature index df7b316754e..36054daf538 100644 --- a/tests/acceptance/features/coreApiSharePublicLink2/updatePublicLinkShare.feature +++ b/tests/acceptance/features/coreApiSharePublicLink2/updatePublicLinkShare.feature @@ -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 diff --git a/tests/acceptance/features/coreApiWebdavEtagPropagation1/deleteFileFolder.feature b/tests/acceptance/features/coreApiWebdavEtagPropagation1/deleteFileFolder.feature index 0001b4642ef..2811a47eea6 100644 --- a/tests/acceptance/features/coreApiWebdavEtagPropagation1/deleteFileFolder.feature +++ b/tests/acceptance/features/coreApiWebdavEtagPropagation1/deleteFileFolder.feature @@ -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 |