diff --git a/tests/acceptance/features/apiLocks/unlockFiles.feature b/tests/acceptance/features/apiLocks/unlockFiles.feature index 3923a502112..b24ee8a282c 100644 --- a/tests/acceptance/features/apiLocks/unlockFiles.feature +++ b/tests/acceptance/features/apiLocks/unlockFiles.feature @@ -213,3 +213,64 @@ Feature: unlock locked items | lock-scope | | shared | | exclusive | + + + Scenario Outline: unlock a file using file-id + Given using spaces DAV path + And user "Alice" has uploaded a file inside space "Alice Hansen" with content "some content" to "textfile.txt" + And we save it into "FILEID" + And user "Alice" has locked file "textfile.txt" using file-id path "" setting the following properties + | lockscope | exclusive | + | timeout | Second-3600 | + When user "Alice" unlocks the last created lock of file "textfile.txt" using file-id path "" using the WebDAV API + Then the HTTP status code should be "204" + And 0 locks should be reported for file "textfile.txt" of user "Alice" by the WebDAV API + And user "Alice" should be able to upload file "filesForUpload/lorem.txt" to "textfile.txt" + Examples: + | dav-path | + | /remote.php/dav/spaces/<> | + | /dav/spaces/<> | + + + Scenario Outline: unlock a file in project space using file-id + Given using spaces DAV path + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "Project" with the default quota using the Graph API + And user "Alice" has uploaded a file inside space "Project" with content "some content" to "textfile.txt" + And we save it into "FILEID" + And user "Alice" has locked file "textfile.txt" inside the space "Project" setting the following properties + | lockscope | exclusive | + | timeout | Second-3600 | + When user "Alice" unlocks the last created lock of file "textfile.txt" using file-id path "" using the WebDAV API + Then the HTTP status code should be "204" + And 0 locks should be reported for file "textfile.txt" inside the space "Project" of user "Alice" + And user "Alice" should be able to upload file "filesForUpload/lorem.txt" to "textfile.txt" + Examples: + | dav-path | + | /remote.php/dav/spaces/<> | + | /dav/spaces/<> | + + + Scenario Outline: unlock a file in the shares using file-id + Given user "Brian" has been created with default attributes and without skeleton files + And using spaces DAV path + And user "Alice" has uploaded a file inside space "Alice Hansen" with content "some content" to "textfile.txt" + And we save it into "FILEID" + And user "Alice" has created a share inside of space "Alice Hansen" with settings: + | path | textfile.txt | + | shareWith | Brian | + | role | editor | + And user "Brian" has locked file "textfile.txt" using file-id path "" setting the following properties + | lockscope | exclusive | + | timeout | Second-3600 | + When user "Brian" unlocks the last created lock of file "textfile.txt" using file-id path "" using the WebDAV API + Then the HTTP status code should be "204" + And 0 locks should be reported for file "textfile.txt" inside the space "Personal" of user "Alice" + And 0 locks should be reported for file "textfile.txt" inside the space "Shares" of user "Brian" + And user "Alice" should be able to upload file "filesForUpload/lorem.txt" to "textfile.txt" + And using new DAV path + And user "Brian" should be able to upload file "filesForUpload/lorem.txt" to "Shares/textfile.txt" + Examples: + | dav-path | + | /remote.php/dav/spaces/<> | + | /dav/spaces/<> | diff --git a/tests/acceptance/features/bootstrap/WebDavLockingContext.php b/tests/acceptance/features/bootstrap/WebDavLockingContext.php index 70e756c857e..0e0f38d07e6 100644 --- a/tests/acceptance/features/bootstrap/WebDavLockingContext.php +++ b/tests/acceptance/features/bootstrap/WebDavLockingContext.php @@ -166,12 +166,42 @@ public function userTriesToLockFileSettingPropertiesUsingWebDavAPI(string $user, * @param TableNode $properties table with no heading with | property | value | * * @return void + * @throws GuzzleException */ public function userLocksFileInProjectSpaceUsingWebDavAPI(string $user, string $file, string $space, TableNode $properties) { + $this->featureContext->setResponse($this->userLocksFileInProjectSpace($user, $file, $space, $properties)); + } + + /** + * @param string $user + * @param string $file + * @param string $space + * @param TableNode $properties + * + * @return ResponseInterface|null + * + * @throws GuzzleException + */ + public function userLocksFileInProjectSpace(string $user, string $file, string $space, TableNode $properties): ?ResponseInterface { $spaceId = $this->spacesContext->getSpaceIdByName($user, $space); $fullUrl = $this->featureContext->getBaseUrl() . '/dav/spaces/' . $spaceId . '/' . $file; - $response = $this->lockFile($user, $file, $properties, $fullUrl); - $this->featureContext->setResponse($response); + return $this->lockFile($user, $file, $properties, $fullUrl); + } + + /** + * @Given user :user has locked file :file inside the space :space setting the following properties + * + * @param string $user + * @param string $file + * @param string $space + * @param TableNode $properties table with no heading with | property | value | + * + * @return void + * @throws GuzzleException + */ + public function userHasLockedFileInProjectSpaceUsingWebDavAPI(string $user, string $file, string $space, TableNode $properties): void { + $response = $this->userLocksFileInProjectSpace($user, $file, $space, $properties); + $this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); } /** @@ -391,6 +421,21 @@ public function userUnlocksTheLastCreatedLockOfFileInsideSpaceUsingTheWebdavApi( $this->featureContext->setResponse($response); } + /** + * @When user :user unlocks the last created lock of file :itemToUnlock using file-id path :filePath using the WebDAV API + * + * @param string $user + * @param string $itemToUnlock + * @param string $filePath + * + * @return void + */ + public function userUnlocksTheLastCreatedLockOfFileWithFileIdPathUsingTheWebdavApi(string $user, string $itemToUnlock, string $filePath) { + $fullUrl = $this->featureContext->getBaseUrl() . $filePath; + $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI($user, $itemToUnlock, $user, $itemToUnlock, false, $fullUrl); + $this->featureContext->setResponse($response); + } + /** * @When user :user unlocks file :itemToUnlock with the last created lock of file :itemToUseLockOf using the WebDAV API * @@ -518,15 +563,19 @@ public function hasUnlockItemWithTheLastCreatedLock( * @param string $lockOwner * @param string $itemToUseLockOf * @param boolean $public + * @param string|null $fullUrl * * @return ResponseInterface + * @throws GuzzleException + * @throws JsonException */ public function unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( string $user, string $itemToUnlock, string $lockOwner, string $itemToUseLockOf, - bool $public = false + bool $public = false, + string $fullUrl = null ):ResponseInterface { $user = $this->featureContext->getActualUsername($user); $lockOwner = $this->featureContext->getActualUsername($lockOwner); @@ -547,18 +596,30 @@ public function unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $headers = [ "Lock-Token" => $this->tokenOfLastLock[$lockOwner][$itemToUseLockOf] ]; - return WebDavHelper::makeDavRequest( - $baseUrl, - $user, - $password, - "UNLOCK", - $itemToUnlock, - $headers, - $this->featureContext->getStepLineRef(), - null, - $this->featureContext->getDavPathVersion(), - $type - ); + if (isset($fullUrl)) { + $response = HttpRequestHelper::sendRequest( + $fullUrl, + $this->featureContext->getStepLineRef(), + "UNLOCK", + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), + $headers + ); + } else { + $response = WebDavHelper::makeDavRequest( + $baseUrl, + $user, + $password, + "UNLOCK", + $itemToUnlock, + $headers, + $this->featureContext->getStepLineRef(), + null, + $this->featureContext->getDavPathVersion(), + $type + ); + } + return $response; } /** @@ -839,6 +900,34 @@ public function waitForCertainSecondsToExpireTheLock(int $time): void { \sleep($time); } + /** + * @Then :count locks should be reported for file :file inside the space :space of user :user + * + * @param int $count + * @param string $file + * @param string $spaceName + * @param string $user + * + * @return void + * @throws GuzzleException + */ + public function numberOfLockShouldBeReportedInProjectSpace(int $count, string $file, string $spaceName, string $user) { + $this->spacesContext->userSendsPropfindRequestToSpace($user, $spaceName, $file); + $this->featureContext->theHTTPStatusCodeShouldBe(207, ""); + $responseXml = $this->featureContext->getResponseXml(); + $xmlPart = $responseXml->xpath("//d:response//d:lockdiscovery/d:activelock"); + if (\is_array($xmlPart)) { + $lockCount = \count($xmlPart); + } else { + throw new Exception("xmlPart for 'd:activelock' was expected to be array but found: $xmlPart"); + } + Assert::assertEquals( + $count, + $lockCount, + "Expected $count lock(s) for '$file' inside space '$spaceName' but found '$lockCount'" + ); + } + /** * This will run before EVERY scenario. * It will set the properties for this object.