From 29f879a3929ddbdf0230088f204a62b41857a5a3 Mon Sep 17 00:00:00 2001 From: "sagargurung1001@gmail.com" Date: Wed, 17 Aug 2022 16:52:39 +0545 Subject: [PATCH] Add lock realated tests for /Shares on ocis --- .../features/apiSpaces/lockSpaces.feature | 91 +++++++++++ .../features/bootstrap/SpacesContext.php | 146 +++++++++++++++++- 2 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 tests/acceptance/features/apiSpaces/lockSpaces.feature diff --git a/tests/acceptance/features/apiSpaces/lockSpaces.feature b/tests/acceptance/features/apiSpaces/lockSpaces.feature new file mode 100644 index 00000000000..492f7c0f786 --- /dev/null +++ b/tests/acceptance/features/apiSpaces/lockSpaces.feature @@ -0,0 +1,91 @@ +@api @skipOnOcV10 +Feature: lock + # Note: This Feature includes all the tests from core (apiWebdavLock suite) related to /Shares since in core no implementation is there for space Shares Jail + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + | Carol | + And user "Alice" has created folder "PARENT" + And user "Brian" has created folder "PARENT" + And user "Carol" has created folder "PARENT" + And using spaces DAV path + + Scenario Outline: lock should propagate correctly if a share is reshared when upload to a share that was locked by owner + Given user "Alice" has shared folder "PARENT" with user "Brian" + And user "Brian" has accepted share "/PARENT" offered by user "Alice" + And user "Brian" has shared folder "Shares/PARENT" with user "Carol" + And user "Carol" has accepted share "/PARENT" offered by user "Brian" + And user "Alice" has locked folder "/PARENT" inside space "Personal" setting the following properties + | lockscope | | + When user "Carol" uploads a file "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/textfile.txt" using the WebDAV API + When user "Brian" uploads a file "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/textfile.txt" using the WebDAV API + And user "Alice" uploads file "filesForUpload/textfile.txt" to "/PARENT/textfile.txt" using the WebDAV API + Then the HTTP status code of responses on all endpoints should be "423" + And as "Alice" file "/PARENT/textfile.txt" should not exist + Examples: + | lock-scope | + | shared | + | exclusive | + + + Scenario Outline: lock should propagate correctly if a share is reshared when upload overwriting to a share that was locked by owner + Given user "Alice" has uploaded file with content "ownCloud test text file parent" to "PARENT/parent.txt" + And user "Brian" has uploaded file with content "ownCloud test text file parent" to "PARENT/parent.txt" + And user "Carol" has uploaded file with content "ownCloud test text file parent" to "PARENT/parent.txt" + And user "Alice" has shared folder "PARENT" with user "Brian" + And user "Brian" has accepted share "/PARENT" offered by user "Alice" + And user "Brian" has shared folder "Shares/PARENT" with user "Carol" + And user "Carol" has accepted share "/PARENT" offered by user "Brian" + And user "Alice" has locked folder "/PARENT" inside space "Personal" setting the following properties + | lockscope | | + When user "Carol" uploads a file "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/parent.txt" using the WebDAV API + When user "Brian" uploads a file "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/parent.txt" using the WebDAV API + And user "Alice" uploads file "filesForUpload/textfile.txt" to "/PARENT/parent.txt" using the WebDAV API + Then the HTTP status code of responses on all endpoints should be "423" + And the content of file "/PARENT/parent.txt" for user "Alice" should be "ownCloud test text file parent" + Examples: + | lock-scope | + | shared | + | exclusive | + + + Scenario Outline: lock should propagate correctly if a share is reshared when public uploads to a reshared share that was locked by original owner + Given user "Alice" has shared folder "PARENT" with user "Brian" + And user "Brian" has accepted share "/PARENT" offered by user "Alice" + And user "Brian" has shared folder "Shares/PARENT" with user "Carol" + And user "Carol" has accepted share "/PARENT" offered by user "Brian" + And user "Carol" has created a public link share inside of space "Shares Jail" with settings: + | path | PARENT | + | shareType | 3 | + | permissions | 15 | + | name | public link | + And user "Alice" has locked folder "/PARENT" inside space "Personal" setting the following properties + | lockscope | | + When the public uploads file "test.txt" with content "test" using the new public WebDAV API + Then the HTTP status code should be "423" + And as "Alice" file "/PARENT/test.txt" should not exist + Examples: + | lock-scope | + | shared | + | exclusive | + + + Scenario Outline: lock should propagate correctly if a share is reshared when upload to a share that was locked by the resharing user + Given user "Alice" has shared folder "PARENT" with user "Brian" + And user "Brian" has accepted share "/PARENT" offered by user "Alice" + And user "Brian" has shared folder "Shares/PARENT" with user "Carol" + And user "Carol" has accepted share "/PARENT" offered by user "Brian" + And user "Brian" has locked folder "/PARENT" inside space "Shares Jail" setting the following properties + | lockscope | | + When user "Carol" uploads a file "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/textfile.txt" using the WebDAV API + And user "Brian" uploads a file "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/textfile.txt" using the WebDAV API + And user "Alice" uploads file "filesForUpload/textfile.txt" to "/PARENT/textfile.txt" using the WebDAV API + Then the HTTP status code should be "423" + And as "Alice" file "/PARENT/test.txt" should not exist + Examples: + | lock-scope | + | shared | + | exclusive | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 6d0f3c88580..83643cfc848 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -97,6 +97,12 @@ class SpacesContext implements Context { */ private $storedEtags = []; + /** + * + * @var string[][] + */ + private $tokenOfLastLock = []; + private $etagPropfindBody = '' . 'getSpaceByName($user, $spaceName); + $file = \fopen($this->featureContext->acceptanceTestsDirLocation() . $source, 'r'); + $this->featureContext->setResponse( + HttpRequestHelper::sendRequest( + $space["root"]["webDavUrl"] . "/" . $destination, + "", + 'PUT', + $user, + $this->featureContext->getPasswordForUser($user), + [], + $file + ) + ); + $this->featureContext->pushToLastHttpStatusCodesArray( + (string) $this->featureContext->getResponse()->getStatusCode() + ); + } + /** * @When /^user "([^"]*)" uploads a file inside space "([^"]*)" owned by the user "([^"]*)" with content "([^"]*)" to "([^"]*)" using the WebDAV API$/ * @@ -1903,6 +1945,28 @@ public function userMovesFileFromAndToSpaceBetweenSpaces( $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); } + /** + * @When /^user "([^"]*)" has moved (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $fileSource + * @param string $fromSpaceName + * @param string $fileDestination + * @param string $toSpaceName + * + * @return void + * @throws GuzzleException + */ + public function userHasMovedFileFromAndToSpaceBetweenSpaces( + string $user, + string $fileSource, + string $fromSpaceName, + string $fileDestination, + string $toSpaceName + ):void { + $this->userMovesFileFromAndToSpaceBetweenSpaces($user, $fileSource, $fromSpaceName, $fileDestination, $toSpaceName); + } + /** * returns a url for destination with spacename * @@ -2057,6 +2121,24 @@ public function sendShareEntityInsideOfSpaceRequest( ); } + /** + * @Given /^user "([^"]*)" has created a public link share inside of space "([^"]*)" with settings:$/ + * + * @param string $user + * @param string $spaceName + * @param TableNode|null $table + * + * @return void + * @throws GuzzleException + */ + public function hasCreatedPublicLinkToEntityInsideOfSpaceRequest( + string $user, + string $spaceName, + ?TableNode $table + ): void { + $this->createPublicLinkToEntityInsideOfSpaceRequest($user, $spaceName, $table); + } + /** * @When /^user "([^"]*)" creates a public link share inside of space "([^"]*)" with settings:$/ * @@ -2092,7 +2174,6 @@ public function createPublicLinkToEntityInsideOfSpaceRequest( ]; $fullUrl = $this->baseUrl . $this->ocsApiUrl; - $this->featureContext->setResponse( $this->sendPostRequestToUrl( $fullUrl, @@ -2101,6 +2182,12 @@ public function createPublicLinkToEntityInsideOfSpaceRequest( $body ) ); + // set last response as PublicShareData. using method from core + $this->featureContext->setLastPublicShareData($this->featureContext->getResponseXml(null, __METHOD__)); + // set last shareId if ShareData exists. using method from core + if (isset($this->featureContext->getLastPublicShareData()->data)) { + $this->featureContext->setLastPublicLinkShareId((string) $this->featureContext->getLastPublicShareData()->data[0]->id); + } } /** @@ -2873,6 +2960,59 @@ public function userHasStoredEtagOfElementOnPathFromSpace($user, $path, $storePa } } + /** + * @Given /^user "([^"]*)" has locked folder "([^"]*)" inside space "([^"]*)" setting the following properties$/ + * + * @param string $user + * @param string $resource + * @param TableNode $properties + * @param string $spaceName + * + * @throws Exception | GuzzleException + */ + public function userHasLockedResourceOfSpace(string $user, string $resource, TableNode $properties, string $spaceName) { + $body + = "" . + " "; + $headers = []; + $this->featureContext->verifyTableNodeRows($properties, [], ['lockscope', 'depth', 'timeout']); + $propertiesRows = $properties->getRowsHash(); + foreach ($propertiesRows as $property => $value) { + if ($property === "depth" || $property === "timeout") { + //properties that are set in the header not in the xml + $headers[$property] = $value; + } else { + $body .= ""; + } + } + $body .= ""; + $space = $this->getSpaceByName($user, $spaceName); + $fullUrl = $space['root']['webDavUrl'] . '/' . ltrim($resource, '/'); + $this->featureContext->setResponse( + HttpRequestHelper::sendRequest( + $fullUrl, + "", + 'LOCK', + $user, + $this->featureContext->getPasswordForUser($user), + [], + $body + ) + ); + $this->featureContext->theHTTPStatusCodeShouldBe( + 200, + "locking the resource failed !!!" + ); + $responseXml = $this->featureContext->getResponseXml(null, __METHOD__); + $this->featureContext->setResponseXmlObject($responseXml); + $xmlPart = $responseXml->xpath("//d:locktoken/d:href"); + if (isset($xmlPart[0])) { + $this->tokenOfLastLock[$user][$resource] = (string) $xmlPart[0]; + } else { + Assert::fail("could not find lock token after trying to lock '$resource'"); + } + } + /** * @When /^user "([^"]*)" creates a public link share of the space "([^"]*)" with settings:$/ * @@ -2988,7 +3128,7 @@ public function forUserSpaceShouldContainLinks( Assert::assertEmpty($responseArray, __METHOD__ . ' Response should be empty'); } } - + /** * @When /^user "([^"]*)" gets the following properties of (?:file|folder|entry|resource) "([^"]*)" inside space "([^"]*)" using the WebDAV API$/ *