From 2e5af9767a4a9d2695ad5429183751752be27a27 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Tue, 29 Jan 2019 17:27:25 +0545 Subject: [PATCH] API acceptance tests to unlock files/folders --- .../features/apiWebdavLocks/unlock.feature | 324 ++++++++++++++++++ .../bootstrap/WebDavLockingContext.php | 106 +++++- 2 files changed, 425 insertions(+), 5 deletions(-) create mode 100644 tests/acceptance/features/apiWebdavLocks/unlock.feature diff --git a/tests/acceptance/features/apiWebdavLocks/unlock.feature b/tests/acceptance/features/apiWebdavLocks/unlock.feature new file mode 100644 index 000000000000..1e6f54e70133 --- /dev/null +++ b/tests/acceptance/features/apiWebdavLocks/unlock.feature @@ -0,0 +1,324 @@ +@api +Feature: UNLOCK locked items + + Background: + Given user "user0" has been created with default attributes + + Scenario Outline: unlock a single lock set by the user itself + Given using DAV path + And user "user0" has locked folder "PARENT" setting following properties + | lockscope | | + When user "user0" unlocks the last created lock of folder "PARENT" using the WebDAV API + Then 0 locks should be reported for folder "PARENT" of user "user0" by the WebDAV API + And 0 locks should be reported for folder "PARENT/CHILD" of user "user0" by the WebDAV API + And 0 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: unlock one of multiple locks set by the user itself + Given using DAV path + And user "user0" has locked file "textfile0.txt" setting following properties + | lockscope | shared | + And user "user0" has locked file "textfile0.txt" setting following properties + | lockscope | shared | + When user "user0" unlocks the last created lock of file "textfile0.txt" using the WebDAV API + Then 1 locks should be reported for file "textfile0.txt" of user "user0" by the WebDAV API + Examples: + | dav-path | + | old | + | new | + + Scenario Outline: unlocking a file that was locked by the user locking the folder above is not possible + Given using DAV path + And user "user0" has locked folder "PARENT/CHILD" setting following properties + | lockscope | | + When user "user0" unlocks file "PARENT/CHILD/child.txt" with the last created lock of folder "PARENT/CHILD" using the WebDAV API + Then 1 locks should be reported for file "PARENT/CHILD/child.txt" of user "user0" by the WebDAV API + And 2 locks should be reported for folder "PARENT/CHILD" of user "user0" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as share receiver unlocking a shared file locked by the file owner is not possible. To unlock use the owners locktoken + Given using DAV path + And user "user1" has been created with default attributes + And user "user0" has locked file "PARENT/parent.txt" setting following properties + | lockscope | | + And user "user0" has shared file "PARENT/parent.txt" with user "user1" + When user "user1" unlocks file "parent.txt" with the last created lock of file "PARENT/parent.txt" of user "user0" using the WebDAV API + Then the HTTP status code should be "403" + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + And 1 locks should be reported for file "parent.txt" of user "user1" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as share receiver unlocking a file in a share locked by the file owner is not possible. To unlock use the owners locktoken + Given using DAV path + And user "user1" has been created with default attributes + And user "user0" has locked file "PARENT/parent.txt" setting following properties + | lockscope | | + And user "user0" has shared folder "PARENT" with user "user1" + When user "user1" unlocks file "PARENT (2)/parent.txt" with the last created lock of file "PARENT/parent.txt" of user "user0" using the WebDAV API + Then the HTTP status code should be "403" + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + And 1 locks should be reported for file "PARENT (2)/parent.txt" of user "user1" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as share receiver unlocking a shared folder locked by the file owner is not possible. To unlock use the owners locktoken + Given using DAV path + And user "user1" has been created with default attributes + And user "user0" has locked folder "PARENT" setting following properties + | lockscope | | + And user "user0" has shared folder "PARENT" with user "user1" + When user "user1" unlocks folder "PARENT (2)" with the last created lock of folder "PARENT" of user "user0" using the WebDAV API + Then the HTTP status code should be "403" + And 3 locks should be reported for folder "PARENT" of user "user0" by the WebDAV API + And 2 locks should be reported for folder "PARENT/CHILD" of user "user0" by the WebDAV API + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + And 3 locks should be reported for folder "PARENT (2)" of user "user1" by the WebDAV API + And 2 locks should be reported for folder "PARENT (2)/CHILD" of user "user1" by the WebDAV API + And 1 locks should be reported for file "PARENT (2)/parent.txt" of user "user1" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as share receiver unlocking a shared file locked by the file owner is not possible. To unlock use the owners locktoken + Given using DAV path + And user "user1" has been created with default attributes + And user "user0" has locked file "PARENT/parent.txt" setting following properties + | lockscope | | + And user "user0" has shared file "PARENT/parent.txt" with user "user1" + When user "user1" unlocks file "parent.txt" with the last created lock of file "PARENT/parent.txt" of user "user0" using the WebDAV API + Then the HTTP status code should be "403" + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + And 1 locks should be reported for file "parent.txt" of user "user1" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as share receiver unlock a shared file + Given using DAV path + And user "user1" has been created with default attributes + And user "user0" has shared file "PARENT/parent.txt" with user "user1" + And user "user1" has locked file "parent.txt" setting following properties + | lockscope | | + When user "user1" unlocks the last created lock of file "parent.txt" using the WebDAV API + Then the HTTP status code should be "204" + And 0 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + And 0 locks should be reported for file "parent.txt" of user "user1" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as owner unlocking a shared file locked by the receiver is not possible. To unlock use the receivers locktoken + Given using DAV path + And user "user1" has been created with default attributes + And user "user0" has shared file "PARENT/parent.txt" with user "user1" + And user "user1" has locked file "parent.txt" setting following properties + | lockscope | | + When user "user0" unlocks file "PARENT/parent.txt" with the last created lock of file "parent.txt" of user "user1" using the WebDAV API + Then the HTTP status code should be "403" + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + And 1 locks should be reported for file "parent.txt" of user "user1" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as owner unlocking a file in a share that was locked by the share receiver is not possible. To unlock use the receivers locktoken + Given using DAV path + And user "user1" has been created with default attributes + And user "user0" has shared folder "PARENT" with user "user1" + And user "user1" has locked file "PARENT (2)/parent.txt" setting following properties + | lockscope | | + When user "user0" unlocks file "PARENT/parent.txt" with the last created lock of file "PARENT (2)/parent.txt" of user "user1" using the WebDAV API + Then the HTTP status code should be "403" + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + And 1 locks should be reported for file "PARENT (2)/parent.txt" of user "user1" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as owner unlocking a shared folder locked by the share receiver is not possible. To unlock use the receivers locktoken + Given using DAV path + And user "user1" has been created with default attributes + And user "user0" has shared folder "PARENT" with user "user1" + And user "user1" has locked folder "PARENT (2)" setting following properties + | lockscope | | + When user "user0" unlocks folder "PARENT" with the last created lock of folder "PARENT (2)" of user "user1" using the WebDAV API + Then the HTTP status code should be "403" + And 3 locks should be reported for folder "PARENT" of user "user0" by the WebDAV API + And 2 locks should be reported for folder "PARENT/CHILD" of user "user0" by the WebDAV API + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + And 3 locks should be reported for folder "PARENT (2)" of user "user1" by the WebDAV API + And 2 locks should be reported for folder "PARENT (2)/CHILD" of user "user1" by the WebDAV API + And 1 locks should be reported for file "PARENT (2)/parent.txt" of user "user1" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + @issue-34302 + Scenario Outline: as public unlocking a file in a share that was locked by the file owner is not possible. To unlock use the owners locktoken + Given user "user0" has created a public link share of folder "PARENT" with change permission + And user "user0" has locked file "PARENT/parent.txt" setting following properties + | lockscope | | + When the public unlocks file "/parent.txt" with the last created lock of file "PARENT/parent.txt" of user "user0" using the WebDAV API + Then the HTTP status code should be "409" + #Then the HTTP status code should be "403" + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + Examples: + | lock-scope | + | shared | + | exclusive | + + @issue-34302 + Scenario Outline: as public unlocking a shared folder locked by the file owner is not possible. To unlock use the owners locktoken + Given user "user0" has created a public link share of folder "PARENT" with change permission + And user "user0" has locked folder "PARENT" setting following properties + | lockscope | | + When the public unlocks folder "/PARENT" with the last created lock of file "PARENT" of user "user0" using the WebDAV API + Then the HTTP status code should be "409" + #Then the HTTP status code should be "403" + And 3 locks should be reported for folder "PARENT" of user "user0" by the WebDAV API + And 2 locks should be reported for folder "PARENT/CHILD" of user "user0" by the WebDAV API + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + Examples: + | lock-scope | + | shared | + | exclusive | + + @issue-34302 + Scenario Outline: as public unlocking a shared file locked by the file owner is not possible. To unlock use the owners locktoken + Given user "user0" has created a public link share of file "PARENT/parent.txt" with change permission + And user "user0" has locked file "PARENT/parent.txt" setting following properties + | lockscope | | + When the public unlocks folder "/" with the last created lock of file "PARENT/parent.txt" of user "user0" using the WebDAV API + Then the HTTP status code should be "409" + #Then the HTTP status code should be "403" + And 1 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + Examples: + | lock-scope | + | shared | + | exclusive | + + Scenario Outline: as owner unlock a publicly shared file that was locked by the public + Given using DAV path + And user "user0" has created a public link share of file "PARENT/parent.txt" with change permission + And the public has locked the last public shared file setting following properties + | lockscope | | + When user "user0" unlocks file "PARENT/parent.txt" with the last created public lock of file "/" using the WebDAV API + Then the HTTP status code should be "204" + And 0 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as owner unlock a file in a public folder that was locked by the public + Given using DAV path + And user "user0" has created a public link share of folder "PARENT" with change permission + And the public has locked "parent.txt" in the last public shared folder setting following properties + | lockscope | | + When user "user0" unlocks file "PARENT/parent.txt" with the last created public lock of file "parent.txt" using the WebDAV API + Then the HTTP status code should be "204" + And 0 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + Scenario Outline: as owner unlock a folder in a public folder that was locked by the public + Given using DAV path + And user "user0" has created a public link share of folder "PARENT" with change permission + And the public has locked "CHILD" in the last public shared folder setting following properties + | lockscope | | + When user "user0" unlocks folder "PARENT/CHILD" with the last created public lock of file "CHILD" using the WebDAV API + Then the HTTP status code should be "204" + And 0 locks should be reported for folder "PARENT/CHILD" of user "user0" by the WebDAV API + And 0 locks should be reported for file "PARENT/CHILD/child.txt" of user "user0" by the WebDAV API + Examples: + | dav-path | lock-scope | + | old | shared | + | old | exclusive | + | new | shared | + | new | exclusive | + + @issue-34302 + Scenario Outline: as public unlock a publicly shared file that was locked by the public + Given user "user0" has created a public link share of file "PARENT/parent.txt" with change permission + And the public has locked the last public shared file setting following properties + | lockscope | | + When the public unlocks file "/" using the WebDAV API + Then the HTTP status code should be "409" + #Then the HTTP status code should be "204" + #And 0 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + Examples: + | lock-scope | + | shared | + | exclusive | + + @issue-34302 + Scenario Outline: as public unlock a file in a public folder that was locked by the public + Given user "user0" has created a public link share of folder "PARENT" with change permission + And the public has locked "parent.txt" in the last public shared folder setting following properties + | lockscope | | + When the public unlocks file "parent.txt" using the WebDAV API + Then the HTTP status code should be "409" + #Then the HTTP status code should be "204" + #And 0 locks should be reported for file "PARENT/parent.txt" of user "user0" by the WebDAV API + Examples: + | lock-scope | + | shared | + | exclusive | + + @issue-34302 + Scenario Outline: as public unlock a subfolder of a public folder that was locked by the public + Given user "user0" has created a public link share of folder "PARENT" with change permission + And the public has locked "CHILD" in the last public shared folder setting following properties + | lockscope | | + When the public unlocks folder "CHILD" using the WebDAV API + Then the HTTP status code should be "409" + #Then the HTTP status code should be "204" + #And 0 locks should be reported for file "PARENT/CHILD/child.txt" of user "user0" by the WebDAV API + #And 0 locks should be reported for file "PARENT/CHILD" of user "user0" by the WebDAV API + Examples: + | lock-scope | + | shared | + | exclusive | \ No newline at end of file diff --git a/tests/acceptance/features/bootstrap/WebDavLockingContext.php b/tests/acceptance/features/bootstrap/WebDavLockingContext.php index edae4e1ea9ee..6b4b30f88254 100644 --- a/tests/acceptance/features/bootstrap/WebDavLockingContext.php +++ b/tests/acceptance/features/bootstrap/WebDavLockingContext.php @@ -170,12 +170,108 @@ public function publicLocksFileLastSharedFolder($file, TableNode $properties) { * @return void */ public function unlockLastLockUsingWebDavAPI($user, $file) { + $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $user, $file, $user, $file + ); + } + + /** + * @When user :user unlocks file/folder :itemToUnlock with the last created lock of file/folder :itemToUseLockOf using the WebDAV API + * + * @param string $user + * @param string $itemToUnlock + * @param string $itemToUseLockOf + * + * @return void + */ + public function unlockItemWithLastLockOfOtherItemUsingWebDavAPI( + $user, $itemToUnlock, $itemToUseLockOf + ) { + $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $user, $itemToUnlock, $user, $itemToUseLockOf + ); + } + + /** + * @When user :user unlocks file/folder :itemToUnlock with the last created public lock of file/folder :itemToUseLockOf using the WebDAV API + * + * @param string $user + * @param string $itemToUnlock + * @param string $itemToUseLockOf + * + * @return void + */ + public function unlockItemWithLastPublicLockOfOtherItemUsingWebDavAPI( + $user, $itemToUnlock, $itemToUseLockOf + ) { + $lockOwner = (string)$this->featureContext->getLastShareData()->data->token; + $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $user, $itemToUnlock, $lockOwner, $itemToUseLockOf + ); + } + + /** + * @When user :user unlocks file/folder :itemToUnlock with the last created lock of file/folder :itemToUseLockOf of user :lockOwner using the WebDAV API + * + * @param string $user + * @param string $itemToUnlock + * @param string $lockOwner + * @param string $itemToUseLockOf + * @param boolean $public + * + * @return void + */ + public function unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $user, $itemToUnlock, $lockOwner, $itemToUseLockOf, $public = false + ) { + if ($public === true) { + $type = "public-files"; + $password = null; + } else { + $type = "files"; + $password = $this->featureContext->getPasswordForUser($user); + } $baseUrl = $this->featureContext->getBaseUrl(); - $password = $this->featureContext->getPasswordForUser($user); - $headers = ["Lock-Token" => $this->tokenOfLastLock[$user][$file]]; - WebDavHelper::makeDavRequest( - $baseUrl, $user, $password, "UNLOCK", $file, $headers, null, null, - $this->featureContext->getDavPathVersion() + $headers = [ + "Lock-Token" => $this->tokenOfLastLock[$lockOwner][$itemToUseLockOf] + ]; + $this->featureContext->setResponse( + WebDavHelper::makeDavRequest( + $baseUrl, $user, $password, "UNLOCK", $itemToUnlock, $headers, + null, null, $this->featureContext->getDavPathVersion(), $type + ) + ); + } + + /** + * @When the public unlocks file/folder :itemToUnlock with the last created lock of file/folder :itemToUseLockOf of user :lockOwner using the WebDAV API + * + * @param string $itemToUnlock + * @param string $lockOwner + * @param string $itemToUseLockOf + * + * @return void + */ + public function unlockItemAsPublicWithLastLockOfUserAndItemUsingWebDavAPI( + $itemToUnlock, $lockOwner, $itemToUseLockOf + ) { + $user = (string)$this->featureContext->getLastShareData()->data->token; + $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $user, $itemToUnlock, $lockOwner, $itemToUseLockOf, true + ); + } + + /** + * @When the public unlocks file/folder :itemToUnlock using the WebDAV API + * + * @param string $itemToUnlock + * + * @return void + */ + public function unlockItemAsPublicUsingWebDavAPI($itemToUnlock) { + $user = (string)$this->featureContext->getLastShareData()->data->token; + $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $user, $itemToUnlock, $user, $itemToUnlock, true ); }