[test-only] Add more lock test (#7624)

* add more lock test

* Update WebDavLockingContext.php

* fix
This commit is contained in:
Viktor Scharf
2023-11-01 06:02:08 +01:00
committed by GitHub
parent 16b6f58af6
commit dfc55c39ef
5 changed files with 144 additions and 209 deletions

View File

@@ -56,24 +56,6 @@ Synchronization features like etag propagation, setting mtime and locking files
#### [Webdav LOCK operations](https://github.com/owncloud/ocis/issues/1284)
- [coreApiWebdavLocks/exclusiveLocks.feature:49](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L49)
- [coreApiWebdavLocks/exclusiveLocks.feature:50](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L50)
- [coreApiWebdavLocks/exclusiveLocks.feature:51](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L51)
- [coreApiWebdavLocks/exclusiveLocks.feature:52](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L52)
- [coreApiWebdavLocks/exclusiveLocks.feature:57](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L57)
- [coreApiWebdavLocks/exclusiveLocks.feature:58](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L58)
- [coreApiWebdavLocks/exclusiveLocks.feature:76](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L76)
- [coreApiWebdavLocks/exclusiveLocks.feature:77](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L77)
- [coreApiWebdavLocks/exclusiveLocks.feature:78](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L78)
- [coreApiWebdavLocks/exclusiveLocks.feature:79](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L79)
- [coreApiWebdavLocks/exclusiveLocks.feature:84](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L84)
- [coreApiWebdavLocks/exclusiveLocks.feature:85](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L85)
- [coreApiWebdavLocks/exclusiveLocks.feature:103](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L103)
- [coreApiWebdavLocks/exclusiveLocks.feature:104](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L104)
- [coreApiWebdavLocks/exclusiveLocks.feature:105](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L105)
- [coreApiWebdavLocks/exclusiveLocks.feature:106](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L106)
- [coreApiWebdavLocks/exclusiveLocks.feature:111](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L111)
- [coreApiWebdavLocks/exclusiveLocks.feature:112](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/exclusiveLocks.feature#L112)
- [coreApiWebdavLocks/requestsWithToken.feature:31](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/requestsWithToken.feature#L31)
- [coreApiWebdavLocks/requestsWithToken.feature:32](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/requestsWithToken.feature#L32)
- [coreApiWebdavLocks/requestsWithToken.feature:37](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavLocks/requestsWithToken.feature#L37)

View File

@@ -143,11 +143,6 @@ The expected failures in this file are from features in the owncloud/ocis repo.
- [apiGraph/addUserToGroup.feature:420](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L420)
### [500 error if viewer tries to lock file](https://github.com/owncloud/ocis/issues/7600)
- [apiSpaces/lockFiles.feature:144](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockFiles.feature#L144)
- [apiSpaces/lockFiles.feature:207](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockFiles.feature#L207)
### [Shared file locking is not possible using different path](https://github.com/owncloud/ocis/issues/7599)
- [apiSpaces/lockFiles.feature:179](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockFiles.feature#L179)

View File

@@ -55,7 +55,7 @@ Feature: lock files
Scenario Outline: lock a file using file-id
Given user "Alice" has uploaded a file inside space "Alice Hansen" with content "some content" to "textfile.txt"
And we save it into "FILEID"
When user "Alice" locks file using file-id path "<dav-path>" using the WebDAV API setting the following properties
When user "Alice" locks file "textfile.txt" using file-id path "<dav-path>" using the WebDAV API setting the following properties
| lockscope | exclusive |
| timeout | Second-3600 |
Then the HTTP status code should be "200"
@@ -123,7 +123,7 @@ Feature: lock files
And user "Alice" has shared a space "Project" with settings:
| shareWith | Brian |
| role | <role> |
When user "Brian" locks file using file-id path "<dav-path>" using the WebDAV API setting the following properties
When user "Brian" locks file "textfile.txt" using file-id path "<dav-path>" using the WebDAV API setting the following properties
| lockscope | exclusive |
| timeout | Second-3600 |
Then the HTTP status code should be "200"
@@ -150,10 +150,10 @@ Feature: lock files
And user "Alice" has shared a space "Project" with settings:
| shareWith | Brian |
| role | viewer |
When user "Brian" locks file "textfile.txt" inside the space "Project" using the WebDAV API setting the following properties
When user "Brian" tries to lock file "textfile.txt" using file-id path "/dav/spaces/<<FILEID>>" using the WebDAV API setting the following properties
| lockscope | exclusive |
Then the HTTP status code should be "403"
When user "Brian" locks file using file-id path "/dav/spaces/<<FILEID>>" using the WebDAV API setting the following properties
When user "Brian" tries to lock file "textfile.txt" inside the space "Project" using the WebDAV API setting the following properties
| lockscope | exclusive |
Then the HTTP status code should be "403"
@@ -188,7 +188,7 @@ Feature: lock files
| path | textfile.txt |
| shareWith | Brian |
| role | editor |
When user "Brian" locks file using file-id path "<dav-path>" using the WebDAV API setting the following properties
When user "Brian" locks file "textfile.txt" using file-id path "<dav-path>" using the WebDAV API setting the following properties
| lockscope | exclusive |
| timeout | Second-3600 |
Then the HTTP status code should be "200"
@@ -204,13 +204,55 @@ Feature: lock files
| /dav/spaces/<<FILEID>> |
Scenario: viewer cannot lock a file in the shares using file-id
Scenario: viewer cannot lock a file in the shares using file-id
Given 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 | viewer |
When user "Brian" locks file using file-id path "<dav-path>" using the WebDAV API setting the following properties
| lockscope | exclusive |
When user "Brian" tries to lock file "textfile.txt" using file-id path "/dav/spaces/<<FILEID>>" using the WebDAV API setting the following properties
| lockscope | exclusive |
Then the HTTP status code should be "403"
Scenario: sharee cannot lock a resource exclusively locked by a sharer
Given 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 "Alice" has locked file "textfile.txt" setting the following properties
| lockscope | exclusive |
When user "Brian" tries to lock file "textfile.txt" using file-id path "/dav/spaces/<<FILEID>>" using the WebDAV API setting the following properties
| lockscope | exclusive |
| timeout | Second-3600 |
Then the HTTP status code should be "423"
When user "Alice" sends PROPFIND request from the space "Alice Hansen" to the resource "textfile.txt" using the WebDAV API
Then the HTTP status code should be "207"
And the "PROPFIND" response to user "Alice" should contain a space "Alice Hansen" with these key and value pairs:
| key | value |
| d:lockdiscovery/d:activelock/d:lockscope/d:exclusive | |
| d:lockdiscovery/d:activelock/oc:ownername | Alice Hansen |
Scenario: sharer cannot lock a resource exclusively locked by a sharee
Given 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 "/dav/spaces/<<FILEID>>" setting the following properties
| lockscope | exclusive |
When user "Alice" tries to lock file "textfile.txt" using file-id path "/dav/spaces/<<FILEID>>" using the WebDAV API setting the following properties
| lockscope | exclusive |
| timeout | Second-3600 |
Then the HTTP status code should be "423"
When user "Alice" sends PROPFIND request from the space "Alice Hansen" to the resource "textfile.txt" using the WebDAV API
Then the HTTP status code should be "207"
And the "PROPFIND" response to user "Alice" should contain a space "Alice Hansen" with these key and value pairs:
| key | value |
| d:lockdiscovery/d:activelock/d:lockscope/d:exclusive | |
| d:lockdiscovery/d:activelock/oc:ownername | Brian Murphy |

View File

@@ -51,6 +51,7 @@ class WebDavLockingContext implements Context {
* @param string $user
* @param string $file
* @param TableNode $properties table with no heading with | property | value |
* @param string $fullUrl
* @param boolean $public if the file is in a public share or not
* @param boolean $expectToSucceed
*
@@ -60,6 +61,7 @@ class WebDavLockingContext implements Context {
string $user,
string $file,
TableNode $properties,
string $fullUrl = null,
bool $public = false,
bool $expectToSucceed = true
):ResponseInterface {
@@ -88,20 +90,33 @@ class WebDavLockingContext implements Context {
$body .= "<d:$property><d:$value/></d:$property>";
}
}
$body .= "</d:lockinfo>";
$response = WebDavHelper::makeDavRequest(
$baseUrl,
$user,
$password,
"LOCK",
$file,
$headers,
$this->featureContext->getStepLineRef(),
$body,
$this->featureContext->getDavPathVersion(),
$type
);
if (isset($fullUrl)) {
$response = HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
"LOCK",
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
$headers,
$body
);
} else {
$response = WebDavHelper::makeDavRequest(
$baseUrl,
$user,
$password,
"LOCK",
$file,
$headers,
$this->featureContext->getStepLineRef(),
$body,
$this->featureContext->getDavPathVersion(),
$type
);
}
$responseXml = $this->featureContext->getResponseXml($response, __METHOD__);
$xmlPart = $responseXml->xpath("//d:locktoken/d:href");
if (isset($xmlPart[0])) {
@@ -115,61 +130,20 @@ class WebDavLockingContext implements Context {
}
/**
* @When user :user locks file :file using the WebDAV API setting the following properties
*
* @param string $user
* @param string $fullUrl
* @param string $file
* @param TableNode $properties table with no heading with | property | value |
* @param boolean $expectToSucceed
*
* @return void
*/
private function lockFileInSpace(
string $user,
string $fullUrl,
TableNode $properties,
bool $expectToSucceed = true
):ResponseInterface {
$body
= "<?xml version='1.0' encoding='UTF-8'?>" .
"<d:lockinfo xmlns:d='DAV:'> ";
$headers = [];
// depth is only 0 or infinity. We don't need to set it more, as there is no lock for the folder
$this->featureContext->verifyTableNodeRows($properties, [], ['lockscope', 'timeout']);
$propertiesRows = $properties->getRowsHash();
foreach ($propertiesRows as $property => $value) {
if ($property === "timeout") {
//properties that are set in the header not in the xml
$headers[$property] = $value;
} else {
$body .= "<d:$property><d:$value/></d:$property>";
}
}
$body .= "</d:lockinfo>";
$response = HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
"LOCK",
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
$headers,
$body
);
$responseXml = $this->featureContext->getResponseXml($response, __METHOD__);
$xmlPart = $responseXml->xpath("//d:locktoken/d:href");
if (isset($xmlPart[0])) {
$this->tokenOfLastLock[$user] = (string) $xmlPart[0];
} else {
if ($expectToSucceed === true) {
Assert::fail("could not find lock token after the last lock");
}
}
return $response;
public function userLocksFileSettingPropertiesUsingWebDavAPI(string $user, string $file, TableNode $properties) {
$response = $this->lockFile($user, $file, $properties);
$this->featureContext->setResponse($response);
}
/**
* @When user :user locks file :file using the WebDAV API setting the following properties
* @When user :user tries to lock file :file using the WebDAV API setting the following properties
*
* @param string $user
@@ -178,8 +152,8 @@ class WebDavLockingContext implements Context {
*
* @return void
*/
public function lockFileUsingWebDavAPI(string $user, string $file, TableNode $properties) {
$response = $this->lockFile($user, $file, $properties, false, false);
public function userTriesToLockFileSettingPropertiesUsingWebDavAPI(string $user, string $file, TableNode $properties) {
$response = $this->lockFile($user, $file, $properties, null, false, false);
$this->featureContext->setResponse($response);
}
@@ -193,25 +167,59 @@ class WebDavLockingContext implements Context {
*
* @return void
*/
public function lockFileInProjectSpaceUsingWebDavAPI(string $user, string $file, string $space, TableNode $properties) {
public function userLocksFileInProjectSpaceUsingWebDavAPI(string $user, string $file, string $space, TableNode $properties) {
$spaceId = $this->spacesContext->getSpaceIdByName($user, $space);
$fullUrl = $this->featureContext->getBaseUrl() . '/dav/spaces/' . $spaceId . '/' . $file;
$response = $this->lockFileInSpace($user, $fullUrl, $properties);
$response = $this->lockFile($user, $file, $properties, $fullUrl);
$this->featureContext->setResponse($response);
}
/**
* @When user :user locks file using file-id path :path using the WebDAV API setting the following properties
* @When user :user tries to lock file :file inside the space :space using the WebDAV API 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
*/
public function userTriesToLockFileInProjectSpaceUsingWebDavAPI(string $user, string $file, string $space, TableNode $properties) {
$spaceId = $this->spacesContext->getSpaceIdByName($user, $space);
$fullUrl = $this->featureContext->getBaseUrl() . '/dav/spaces/' . $spaceId . '/' . $file;
$response = $this->lockFile($user, $file, $properties, $fullUrl, false, false);
$this->featureContext->setResponse($response);
}
/**
* @When user :user locks file :file using file-id path :path using the WebDAV API setting the following properties
*
* @param string $user
* @param string $file
* @param string $filePath
* @param TableNode $properties table with no heading with | property | value |
*
* @return void
*/
public function lockFileUsingFileIdUsingWebDavAPI(string $user, string $filePath, TableNode $properties) {
public function userLocksFileUsingFileIdUsingWebDavAPI(string $user, string $file, string $filePath, TableNode $properties) {
$fullUrl = $this->featureContext->getBaseUrl() . $filePath;
$response = $this->lockFileInSpace($user, $fullUrl, $properties);
$response = $this->lockFile($user, $file, $properties, $fullUrl);
$this->featureContext->setResponse($response);
}
/**
* @When user :user tries to lock file :file using file-id path :path using the WebDAV API setting the following properties
*
* @param string $user
* @param string $file
* @param string $filePath
* @param TableNode $properties table with no heading with | property | value |
*
* @return void
*/
public function userTriesToLockFileUsingFileIdUsingWebDavAPI(string $user, string $file, string $filePath, TableNode $properties) {
$fullUrl = $this->featureContext->getBaseUrl() . $filePath;
$response = $this->lockFile($user, $file, $properties, $fullUrl, false, false);
$this->featureContext->setResponse($response);
}
@@ -229,6 +237,22 @@ class WebDavLockingContext implements Context {
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
}
/**
* @Given user :user has locked file :file using file-id path :path setting the following properties
*
* @param string $user
* @param string $file
* @param string $filePath
* @param TableNode $properties table with no heading with | property | value |
*
* @return void
*/
public function userHasLockedFileUsingFileId(string $user, string $file, string $filePath, TableNode $properties) {
$fullUrl = $this->featureContext->getBaseUrl() . $filePath;
$response = $this->lockFile($user, $file, $properties, $fullUrl);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
}
/**
* @Given the public has locked the last public link shared file/folder setting the following properties
*
@@ -241,6 +265,7 @@ class WebDavLockingContext implements Context {
$this->featureContext->getLastCreatedPublicShareToken(),
"/",
$properties,
null,
true
);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
@@ -258,6 +283,7 @@ class WebDavLockingContext implements Context {
$this->featureContext->getLastCreatedPublicShareToken(),
"/",
$properties,
null,
true,
false
);
@@ -280,6 +306,7 @@ class WebDavLockingContext implements Context {
$this->featureContext->getLastCreatedPublicShareToken(),
$file,
$properties,
null,
true
);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
@@ -303,6 +330,7 @@ class WebDavLockingContext implements Context {
$this->featureContext->getLastCreatedPublicShareToken(),
$file,
$properties,
null,
true,
false
);

View File

@@ -1,112 +0,0 @@
@issue-1284
Feature: there can be only one exclusive lock on a resource
As a user
I want to lock a resource
So that other users cannot access or change that resource
Background:
Given user "Alice" has been created with default attributes and without skeleton files
Scenario Outline: second lock cannot be set on a folder when its exclusively locked
Given using <dav-path-version> DAV path
And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt"
And user "Alice" has locked file "textfile0.txt" setting the following properties
| lockscope | exclusive |
When user "Alice" locks file "textfile0.txt" using the WebDAV API setting the following properties
| lockscope | <lock-scope> |
Then the HTTP status code should be "423"
And 1 locks should be reported for file "textfile0.txt" of user "Alice" by the WebDAV API
Examples:
| dav-path-version | lock-scope |
| old | shared |
| old | exclusive |
| new | shared |
| new | exclusive |
@skipOnRevaMaster
Examples:
| dav-path-version | lock-scope |
| spaces | shared |
| spaces | exclusive |
Scenario Outline: sharee cannot lock a resource exclusively locked by itself
Given using <dav-path-version> DAV path
And user "Brian" has been created with default attributes and without skeleton files
And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt"
And user "Brian" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt"
And user "Alice" has shared file "textfile0.txt" with user "Brian"
And user "Brian" has locked file "textfile0 (2).txt" setting the following properties
| lockscope | exclusive |
When user "Brian" locks file "textfile0 (2).txt" using the WebDAV API setting the following properties
| lockscope | <lock-scope> |
Then the HTTP status code should be "423"
And 1 locks should be reported for file "textfile0.txt" of user "Alice" by the WebDAV API
And 1 locks should be reported for file "textfile0 (2).txt" of user "Brian" by the WebDAV API
Examples:
| dav-path-version | lock-scope |
| old | shared |
| old | exclusive |
| new | shared |
| new | exclusive |
@skipOnRevaMaster
Examples:
| dav-path-version | lock-scope |
| spaces | shared |
| spaces | exclusive |
Scenario Outline: sharee cannot lock a resource exclusively locked by the owner
Given using <dav-path-version> DAV path
And user "Brian" has been created with default attributes and without skeleton files
And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt"
And user "Brian" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt"
And user "Alice" has shared file "textfile0.txt" with user "Brian"
And user "Alice" has locked file "textfile0.txt" setting the following properties
| lockscope | exclusive |
When user "Brian" locks file "textfile0 (2).txt" using the WebDAV API setting the following properties
| lockscope | <lock-scope> |
Then the HTTP status code should be "423"
And 1 locks should be reported for file "textfile0.txt" of user "Alice" by the WebDAV API
And 1 locks should be reported for file "textfile0 (2).txt" of user "Brian" by the WebDAV API
Examples:
| dav-path-version | lock-scope |
| old | shared |
| old | exclusive |
| new | shared |
| new | exclusive |
@skipOnRevaMaster
Examples:
| dav-path-version | lock-scope |
| spaces | shared |
| spaces | exclusive |
Scenario Outline: sharer cannot lock a resource exclusively locked by a sharee
Given using <dav-path-version> DAV path
And user "Brian" has been created with default attributes and without skeleton files
And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt"
And user "Brian" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt"
And user "Alice" has shared file "textfile0.txt" with user "Brian"
And user "Brian" has locked file "textfile0 (2).txt" setting the following properties
| lockscope | exclusive |
When user "Alice" locks file "textfile0.txt" using the WebDAV API setting the following properties
| lockscope | <lock-scope> |
Then the HTTP status code should be "423"
And 1 locks should be reported for file "textfile0.txt" of user "Alice" by the WebDAV API
And 1 locks should be reported for file "textfile0 (2).txt" of user "Brian" by the WebDAV API
Examples:
| dav-path-version | lock-scope |
| old | shared |
| old | exclusive |
| new | shared |
| new | exclusive |
@skipOnRevaMaster
Examples:
| dav-path-version | lock-scope |
| spaces | shared |
| spaces | exclusive |