Skip to content

Commit

Permalink
Add lock realated tests for /Shares on ocis
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Aug 18, 2022
1 parent 152ce60 commit 29f879a
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 3 deletions.
91 changes: 91 additions & 0 deletions tests/acceptance/features/apiSpaces/lockSpaces.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
@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"
And using spaces DAV path

Scenario Outline: lock should propagate correctly if a share is reshared when upload to a share that was locked by 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 folder "Shares/PARENT" with user "Carol"
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 "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/textfile.txt" using the WebDAV API
When user "Brian" uploads a file "filesForUpload/textfile.txt" inside space "Shares Jail" 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 if a share is reshared when upload overwriting to a share that was locked by owner
Given user "Alice" has uploaded file with content "ownCloud test text file parent" to "PARENT/parent.txt"
And user "Brian" has uploaded file with content "ownCloud test text file parent" to "PARENT/parent.txt"
And user "Carol" 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 folder "Shares/PARENT" with user "Carol"
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 "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/parent.txt" using the WebDAV API
When user "Brian" uploads a file "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/parent.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 if a share is reshared when public uploads to a reshared share that was locked by 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 folder "Shares/PARENT" with user "Carol"
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 if a share is reshared when upload to a share 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 folder "Shares/PARENT" with user "Carol"
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 "filesForUpload/textfile.txt" inside space "Shares Jail" to "PARENT/textfile.txt" using the WebDAV API
And user "Brian" uploads a file "filesForUpload/textfile.txt" inside space "Shares Jail" 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 should be "423"
And as "Alice" file "/PARENT/test.txt" should not exist
Examples:
| lock-scope |
| shared |
| exclusive |
146 changes: 143 additions & 3 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 @@ -576,7 +582,7 @@ public function sendPropfindRequestToUrl(
string $password,
string $xRequestId = '',
array $headers = [],
$body = null
$body = null
): ResponseInterface {
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PROPFIND', $user, $password, $headers, $body);
}
Expand Down Expand Up @@ -1488,6 +1494,42 @@ public function theUserUploadsAFileToSpace(
);
}

/**
* @When /^user "([^"]*)" uploads a file "([^"]*)" inside space "([^"]*)" to "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $source
* @param string $spaceName
* @param string $destination
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserUploadsSpecificFileToSpace(
string $user,
string $source,
string $spaceName,
string $destination
): void {
$space = $this->getSpaceByName($user, $spaceName);
$file = \fopen($this->featureContext->acceptanceTestsDirLocation() . $source, 'r');
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$space["root"]["webDavUrl"] . "/" . $destination,
"",
'PUT',
$user,
$this->featureContext->getPasswordForUser($user),
[],
$file
)
);
$this->featureContext->pushToLastHttpStatusCodesArray(
(string) $this->featureContext->getResponse()->getStatusCode()
);
}

/**
* @When /^user "([^"]*)" uploads a file inside space "([^"]*)" owned by the user "([^"]*)" with content "([^"]*)" to "([^"]*)" using the WebDAV API$/
*
Expand Down Expand Up @@ -1903,6 +1945,28 @@ public function userMovesFileFromAndToSpaceBetweenSpaces(
$this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
}

/**
* @When /^user "([^"]*)" has moved (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
* @param string $fileDestination
* @param string $toSpaceName
*
* @return void
* @throws GuzzleException
*/
public function userHasMovedFileFromAndToSpaceBetweenSpaces(
string $user,
string $fileSource,
string $fromSpaceName,
string $fileDestination,
string $toSpaceName
):void {
$this->userMovesFileFromAndToSpaceBetweenSpaces($user, $fileSource, $fromSpaceName, $fileDestination, $toSpaceName);
}

/**
* returns a url for destination with spacename
*
Expand Down Expand Up @@ -2057,6 +2121,24 @@ public function sendShareEntityInsideOfSpaceRequest(
);
}

/**
* @Given /^user "([^"]*)" has created a public link share inside of space "([^"]*)" with settings:$/
*
* @param string $user
* @param string $spaceName
* @param TableNode|null $table
*
* @return void
* @throws GuzzleException
*/
public function hasCreatedPublicLinkToEntityInsideOfSpaceRequest(
string $user,
string $spaceName,
?TableNode $table
): void {
$this->createPublicLinkToEntityInsideOfSpaceRequest($user, $spaceName, $table);
}

/**
* @When /^user "([^"]*)" creates a public link share inside of space "([^"]*)" with settings:$/
*
Expand Down Expand Up @@ -2092,7 +2174,6 @@ public function createPublicLinkToEntityInsideOfSpaceRequest(
];

$fullUrl = $this->baseUrl . $this->ocsApiUrl;

$this->featureContext->setResponse(
$this->sendPostRequestToUrl(
$fullUrl,
Expand All @@ -2101,6 +2182,12 @@ public function createPublicLinkToEntityInsideOfSpaceRequest(
$body
)
);
// set last response as PublicShareData. using method from core
$this->featureContext->setLastPublicShareData($this->featureContext->getResponseXml(null, __METHOD__));
// set last shareId if ShareData exists. using method from core
if (isset($this->featureContext->getLastPublicShareData()->data)) {
$this->featureContext->setLastPublicLinkShareId((string) $this->featureContext->getLastPublicShareData()->data[0]->id);
}
}

/**
Expand Down Expand Up @@ -2873,6 +2960,59 @@ public function userHasStoredEtagOfElementOnPathFromSpace($user, $path, $storePa
}
}

/**
* @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) {
$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
)
);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"locking the resource failed !!!"
);
$responseXml = $this->featureContext->getResponseXml(null, __METHOD__);
$this->featureContext->setResponseXmlObject($responseXml);
$xmlPart = $responseXml->xpath("//d:locktoken/d:href");
if (isset($xmlPart[0])) {
$this->tokenOfLastLock[$user][$resource] = (string) $xmlPart[0];
} else {
Assert::fail("could not find lock token after trying to lock '$resource'");
}
}

/**
* @When /^user "([^"]*)" creates a public link share of the space "([^"]*)" with settings:$/
*
Expand Down Expand Up @@ -2988,7 +3128,7 @@ public function forUserSpaceShouldContainLinks(
Assert::assertEmpty($responseArray, __METHOD__ . ' Response should be empty');
}
}

/**
* @When /^user "([^"]*)" gets the following properties of (?:file|folder|entry|resource) "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
Expand Down

0 comments on commit 29f879a

Please sign in to comment.