Skip to content

Commit

Permalink
[test-only] Add more lock test (#7624)
Browse files Browse the repository at this point in the history
* add more lock test

* Update WebDavLockingContext.php

* fix
  • Loading branch information
ScharfViktor authored Nov 1, 2023
1 parent 16b6f58 commit dfc55c3
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 209 deletions.
18 changes: 0 additions & 18 deletions tests/acceptance/expected-failures-API-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 50 additions & 8 deletions tests/acceptance/features/apiSpaces/lockFiles.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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"
Expand All @@ -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 |
160 changes: 94 additions & 66 deletions tests/acceptance/features/bootstrap/WebDavLockingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -60,6 +61,7 @@ private function lockFile(
string $user,
string $file,
TableNode $properties,
string $fullUrl = null,
bool $public = false,
bool $expectToSucceed = true
):ResponseInterface {
Expand Down Expand Up @@ -88,20 +90,33 @@ private function lockFile(
$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])) {
Expand All @@ -115,61 +130,20 @@ private function lockFile(
}

/**
* @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
Expand All @@ -178,8 +152,8 @@ private function lockFileInSpace(
*
* @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);
}

Expand All @@ -193,25 +167,59 @@ public function lockFileUsingWebDavAPI(string $user, string $file, TableNode $pr
*
* @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->lockFile($user, $file, $properties, $fullUrl);
$this->featureContext->setResponse($response);
}

/**
* @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->lockFileInSpace($user, $fullUrl, $properties);
$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 userLocksFileUsingFileIdUsingWebDavAPI(string $user, string $file, string $filePath, TableNode $properties) {
$fullUrl = $this->featureContext->getBaseUrl() . $filePath;
$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 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 userTriesToLockFileUsingFileIdUsingWebDavAPI(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, false, false);
$this->featureContext->setResponse($response);
}

Expand All @@ -229,6 +237,22 @@ public function userHasLockedFile(string $user, string $file, TableNode $propert
$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
*
Expand All @@ -241,6 +265,7 @@ public function publicHasLockedLastSharedFile(TableNode $properties) {
$this->featureContext->getLastCreatedPublicShareToken(),
"/",
$properties,
null,
true
);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
Expand All @@ -258,6 +283,7 @@ public function publicLocksLastSharedFile(TableNode $properties) {
$this->featureContext->getLastCreatedPublicShareToken(),
"/",
$properties,
null,
true,
false
);
Expand All @@ -280,6 +306,7 @@ public function publicHasLockedFileLastSharedFolder(
$this->featureContext->getLastCreatedPublicShareToken(),
$file,
$properties,
null,
true
);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
Expand All @@ -303,6 +330,7 @@ public function publicLocksFileLastSharedFolder(
$this->featureContext->getLastCreatedPublicShareToken(),
$file,
$properties,
null,
true,
false
);
Expand Down
Loading

0 comments on commit dfc55c3

Please sign in to comment.