Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci]Add lock related tests for /Shares on ocis #4404

Merged
merged 3 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ The expected failures in this file are from features in the owncloud/ocis repo.
### [PROPFIND on accepted shares with identical names containing brackets exit with 404](https://github.com/owncloud/ocis/issues/4421)

- [apiSpaces/changingFilesShare.feature:12](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changingFilesShare.feature#L12)

#### [Webdav LOCK operations](https://github.com/owncloud/ocis/issues/1284)
- [apiSpaces/lockSpaces.feature:31](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockSpaces.feature#L31)
- [apiSpaces/lockSpaces.feature:32](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockSpaces.feature#L32)
- [apiSpaces/lockSpaces.feature:50](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockSpaces.feature#L50)
- [apiSpaces/lockSpaces.feature:51](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockSpaces.feature#L51)
- [apiSpaces/lockSpaces.feature:71](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockSpaces.feature#L71)
- [apiSpaces/lockSpaces.feature:72](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockSpaces.feature#L72)
- [apiSpaces/lockSpaces.feature:89](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockSpaces.feature#L89)
- [apiSpaces/lockSpaces.feature:90](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/lockSpaces.feature#L90)
90 changes: 90 additions & 0 deletions tests/acceptance/features/apiSpaces/lockSpaces.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
@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"
SagarGi marked this conversation as resolved.
Show resolved Hide resolved
And using spaces DAV path


Scenario Outline: lock should propagate correctly when uploaded to a reshare that was locked by the 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 the following entity "PARENT" inside of space "Shares Jail" with user "Carol" with role "editor"
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 | <lock-scope> |
When user "Carol" uploads a file inside space "Shares Jail" with content "uploaded by carol" to "PARENT/textfile.txt" using the WebDAV API
And user "Brian" uploads a file inside space "Shares Jail" with content "uploaded by brian" 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 when uploaded overwriting to a reshare that was locked by the owner
Given user "Alice" 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 the following entity "PARENT" inside of space "Shares Jail" with user "Carol" with role "editor"
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 | <lock-scope> |
When user "Carol" uploads a file inside space "Shares Jail" with content "uploaded by carol" to "PARENT/textfile.txt" using the WebDAV API
And user "Brian" uploads a file inside space "Shares Jail" with content "uploaded by brian" to "PARENT/textfile.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 when the public uploads to a reshared share that was locked by the 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 the following entity "PARENT" inside of space "Shares Jail" with user "Carol" with role "editor"
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 | <lock-scope> |
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 when uploaded to a reshare 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 the following entity "PARENT" inside of space "Shares Jail" with user "Carol" with role "editor"
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 | <lock-scope> |
When user "Carol" uploads a file inside space "Shares Jail" with content "uploaded by carol" to "PARENT/textfile.txt" using the WebDAV API
And user "Brian" uploads a file inside space "Shares Jail" with content "uploaded by brian" 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 |
227 changes: 171 additions & 56 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ class SpacesContext implements Context {
*/
private $storedEtags = [];

/**
*
* @var string[][]
*/
private $tokenOfLastLock = [];

private $etagPropfindBody = '<?xml version="1.0"?>'
. '<d:propfind xmlns:d="DAV:" '
. 'xmlns:oc="http://owncloud.org/ns" '
Expand Down Expand Up @@ -457,7 +463,7 @@ public function deleteAllProjectSpaces(): void {
}
$this->sendDeleteSpaceRequest($userName, $value["name"]);
}
}
}
}
}
}
Expand Down Expand Up @@ -696,27 +702,27 @@ public function sendCreateFolderRequest(
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers);
}

/**
* send proppatch request to url
* @param string $fullUrl
* @param string $user
* @param string $password
* @param string $xRequestId
* @param array $headers
* @param mixed|null $body
* @return ResponseInterface
*/
public function sendPropPatchRequest(
string $fullUrl,
string $user,
string $password,
string $xRequestId = '',
array $headers = [],
$body
): ResponseInterface
{
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PROPPATCH', $user, $password, $headers, $body);
}
/**
* send proppatch request to url
*
* @param string $fullUrl
* @param string $user
* @param string $password
* @param string $xRequestId
* @param array $headers
* @param mixed|null $body
* @return ResponseInterface
*/
public function sendPropPatchRequest(
string $fullUrl,
string $user,
string $password,
string $xRequestId = '',
array $headers = [],
$body
): ResponseInterface {
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PROPPATCH', $user, $password, $headers, $body);
}

/**
* @When /^user "([^"]*)" lists all available spaces via the GraphApi$/
Expand Down Expand Up @@ -2135,7 +2141,7 @@ public function sendShareSpaceRequest(
}

/**
* @When /^user "([^"]*)" shares the following entity "([^"]*)" inside of space "([^"]*)" with user "([^"]*)" with role "([^"]*)"$/
* Request to send share of resource inside of space
*
* @param string $user
* @param string $entity
Expand All @@ -2146,13 +2152,7 @@ public function sendShareSpaceRequest(
* @return void
* @throws GuzzleException
*/
public function sendShareEntityInsideOfSpaceRequest(
string $user,
string $entity,
string $spaceName,
string $userRecipient,
string $role
): void {
public function sendRequestForShareOfEntityInsideOfSpace(string $user, string $entity, string $spaceName, string $userRecipient, string $role):void {
$space = $this->getSpaceByName($user, $spaceName);
$body = [
"space_ref" => $space['id'] . "/" . $entity,
Expand All @@ -2174,6 +2174,54 @@ public function sendShareEntityInsideOfSpaceRequest(
$this->setLastShareData();
}

/**
* @When /^user "([^"]*)" shares the following entity "([^"]*)" inside of space "([^"]*)" with user "([^"]*)" with role "([^"]*)"$/
*
* @param string $user
* @param string $entity
* @param string $spaceName
* @param string $userRecipient
* @param string $role
*
* @return void
* @throws GuzzleException
*/
public function sharesTheFollowingEntityInsideOfSpace(
string $user,
string $entity,
string $spaceName,
string $userRecipient,
string $role
): void {
$this->sendRequestForShareOfEntityInsideOfSpace($user, $entity, $spaceName, $userRecipient, $role);
}

/**
* @Given /^user "([^"]*)" has shared the following entity "([^"]*)" inside of space "([^"]*)" with user "([^"]*)" with role "([^"]*)"$/
*
* @param string $user
* @param string $entity
* @param string $spaceName
* @param string $userRecipient
* @param string $role
*
* @return void
* @throws GuzzleException
*/
public function hasSharedTheFollowingEntityInsideOfSpace(
string $user,
string $entity,
string $spaceName,
string $userRecipient,
string $role
): void {
$this->sendRequestForShareOfEntityInsideOfSpace($user, $entity, $spaceName, $userRecipient, $role);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"Expected response status code should be 200"
);
}

/**
* @When /^user "([^"]*)" creates a public link share inside of space "([^"]*)" with settings:$/
*
Expand Down Expand Up @@ -3016,6 +3064,74 @@ public function userHasStoredEtagOfElementOnPathFromSpace($user, $path, $storePa
}
}

/**
* Request to lock the resource inside of space
*
* @param string $user
* @param string $resource
* @param TableNode $properties
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function sendRequestToLockResouceInsideOfSpace(string $user, string $resource, TableNode $properties, string $spaceName):void {
$body
= "<?xml version='1.0' encoding='UTF-8'?>" .
"<d:lockinfo xmlns:d='DAV:'> ";
$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 .= "<d:$property><d:$value/></d:$property>";
}
}
$body .= "</d:lockinfo>";
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $space['root']['webDavUrl'] . '/' . ltrim($resource, '/');
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
"",
'LOCK',
$user,
$this->featureContext->getPasswordForUser($user),
[],
$body
)
SagarGi marked this conversation as resolved.
Show resolved Hide resolved
);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
__METHOD__ . " Failed to lock the resource $resource"
);
$responseXml = $this->featureContext->getResponseXml(null, __METHOD__);
$this->featureContext->setResponseXmlObject($responseXml);
$xmlPart = $responseXml->xpath("//d:locktoken/d:href");
if (\is_array($xmlPart) && isset($xmlPart[0])) {
$this->tokenOfLastLock[$user][$resource] = (string) $xmlPart[0];
} else {
Assert::fail("could not find lock token after trying to lock '$resource'");
}
}

/**
* @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) {
$this->sendRequestToLockResouceInsideOfSpace($user, $resource, $properties, $spaceName);
}

/**
* @When /^user "([^"]*)" creates a public link share of the space "([^"]*)" with settings:$/
*
Expand Down Expand Up @@ -3225,21 +3341,20 @@ public function asUserFileInsideSpaceShouldContainAPropertyWithValue(
);
}

/**
* @When /^user "([^"]*)" favorites element "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $path
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userFavoritesElementInSpaceUsingTheWebdavApi(string $user, string $path, string $spaceName): void
{
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($path, "/");
$body = '<?xml version="1.0"?>
/**
* @When /^user "([^"]*)" favorites element "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $path
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userFavoritesElementInSpaceUsingTheWebdavApi(string $user, string $path, string $spaceName): void {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($path, "/");
$body = '<?xml version="1.0"?>
<d:propertyupdate xmlns:d="DAV:"
xmlns:oc="http://owncloud.org/ns">
<d:set>
Expand All @@ -3248,15 +3363,15 @@ public function userFavoritesElementInSpaceUsingTheWebdavApi(string $user, strin
</d:prop>
</d:set>
</d:propertyupdate>';
$this->featureContext->setResponse(
$this->sendProppatchRequest(
$fullUrl,
$user,
$this->featureContext->getPasswordForUser($user),
$this->featureContext->getStepLineRef(),
[],
$body
)
);
}
$this->featureContext->setResponse(
$this->sendProppatchRequest(
$fullUrl,
$user,
$this->featureContext->getPasswordForUser($user),
$this->featureContext->getStepLineRef(),
[],
$body
)
);
}
}