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

[test-only] new lock tests #7595

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions tests/acceptance/features/apiSpaces/lockFiles.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: lock files
| Brian |


Scenario Outline: locking a file
Scenario Outline: lock a file
Given using <dav-path-version> DAV path
And user "Alice" has uploaded a file inside space "Alice Hansen" with content "some content" to "textfile.txt"
When user "Alice" locks file "textfile.txt" using the WebDAV API setting the following properties
Expand All @@ -30,7 +30,7 @@ Feature: lock files
| spaces |


Scenario Outline: locking a file with a set timeout
Scenario Outline: lock a file with a timeout
Given using <dav-path-version> DAV path
And user "Alice" has uploaded a file inside space "Alice Hansen" with content "some content" to "textfile.txt"
When user "Alice" locks file "textfile.txt" using the WebDAV API setting the following properties
Expand All @@ -52,7 +52,7 @@ Feature: lock files
| spaces |


Scenario Outline: locking a file by file-id
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
Expand Down Expand Up @@ -88,7 +88,7 @@ Feature: lock files
| spaces |


Scenario Outline: locking a file in the project space
Scenario Outline: lock a file in the project space
Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And using spaces DAV path
And user "Alice" has created a space "Project" with the default quota using the GraphApi
Expand All @@ -114,7 +114,7 @@ Feature: lock files
| editor |


Scenario Outline: locking a file in the project space by file-id
Scenario Outline: lock a file in the project space using file-id
Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And using spaces DAV path
And user "Alice" has created a space "Project" with the default quota using the GraphApi
Expand Down Expand Up @@ -158,10 +158,10 @@ Feature: lock files
Then the HTTP status code should be "403"


Scenario Outline: locking a file in the shares
Scenario Outline: lock a file in the shares
Given using <dav-path-version> DAV path
And user "Alice" has uploaded a file inside space "Alice Hansen" with content "some content" to "textfile.txt"
When user "Alice" creates a share inside of space "Alice Hansen" with settings:
And user "Alice" has created a share inside of space "Alice Hansen" with settings:
| path | textfile.txt |
| shareWith | Brian |
| role | editor |
Expand All @@ -181,10 +181,10 @@ Feature: lock files
| spaces |


Scenario Outline: locking a file in the shares using file-id
And user "Alice" has uploaded a file inside space "Alice Hansen" with content "some content" to "textfile.txt"
Scenario Outline: 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"
When user "Alice" creates a share inside of space "Alice Hansen" with settings:
And user "Alice" has created a share inside of space "Alice Hansen" with settings:
| path | textfile.txt |
| shareWith | Brian |
| role | editor |
Expand All @@ -205,9 +205,9 @@ Feature: lock files


Scenario: viewer cannot lock a file in the shares using file-id
And user "Alice" has uploaded a file inside space "Alice Hansen" with content "some content" to "textfile.txt"
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" creates a share inside of space "Alice Hansen" with settings:
And user "Alice" has created a share inside of space "Alice Hansen" with settings:
| path | textfile.txt |
| shareWith | Brian |
| role | viewer |
Expand Down
83 changes: 14 additions & 69 deletions tests/acceptance/features/bootstrap/WebDavLockingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
use TestHelpers\HttpRequestHelper;
use TestHelpers\OcsApiHelper;
use TestHelpers\WebDavHelper;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\OcisHelper;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -118,77 +117,18 @@ private function lockFile(
/**
*
* @param string $user
* @param string $file
* @param string $space
* @param TableNode $properties table with no heading with | property | value |
* @param boolean $expectToSucceed
*
* @return void
*/
private function lockFileInProjectSpace(
string $user,
string $file,
string $space,
TableNode $properties,
bool $expectToSucceed = true
):ResponseInterface {
$spaceId = $this->spacesContext->getSpaceIdByName($user, $space);
$fullUrl = $this->featureContext->getBaseUrl() . '/dav/spaces/' . $spaceId . '/' . $file;
$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][$file] = (string) $xmlPart[0];
} else {
if ($expectToSucceed === true) {
Assert::fail("could not find lock token after trying to lock '$file'");
}
}
return $response;
}

/**
*
* @param string $user
* @param string $filePath
* @param string $fullUrl
* @param TableNode $properties table with no heading with | property | value |
* @param boolean $expectToSucceed
*
* @return void
*/
private function lockFileUsingFileId(
private function lockFileInSpace(
string $user,
string $filePath,
string $fullUrl,
TableNode $properties,
bool $expectToSucceed = true
):ResponseInterface {
$fullUrl = $this->featureContext->getBaseUrl() . $filePath;
$body
= "<?xml version='1.0' encoding='UTF-8'?>" .
"<d:lockinfo xmlns:d='DAV:'> ";
Expand Down Expand Up @@ -219,10 +159,10 @@ private function lockFileUsingFileId(
$responseXml = $this->featureContext->getResponseXml($response, __METHOD__);
$xmlPart = $responseXml->xpath("//d:locktoken/d:href");
if (isset($xmlPart[0])) {
$this->tokenOfLastLock[$user][$filePath] = (string) $xmlPart[0];
$this->tokenOfLastLock[$user] = (string) $xmlPart[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saw-jan I'll solve storing lock token when I combine lockFileInSpace() and lockFile() and move tests from coreApiWebdavLocks to apiSpaces

} else {
if ($expectToSucceed === true) {
Assert::fail("could not find lock token after trying to lock '$filePath'");
Assert::fail("could not find lock token after the last lock");
}
}
return $response;
Expand Down Expand Up @@ -254,7 +194,9 @@ public function lockFileUsingWebDavAPI(string $user, string $file, TableNode $pr
* @return void
*/
public function lockFileInProjectSpaceUsingWebDavAPI(string $user, string $file, string $space, TableNode $properties) {
$response = $this->lockFileInProjectSpace($user, $file, $space, $properties, false, false);
$spaceId = $this->spacesContext->getSpaceIdByName($user, $space);
$fullUrl = $this->featureContext->getBaseUrl() . '/dav/spaces/' . $spaceId . '/' . $file;
$response = $this->lockFileInSpace($user, $fullUrl, $properties, false, false);
ScharfViktor marked this conversation as resolved.
Show resolved Hide resolved
$this->featureContext->setResponse($response);
}

Expand All @@ -268,7 +210,8 @@ public function lockFileInProjectSpaceUsingWebDavAPI(string $user, string $file,
* @return void
*/
public function lockFileUsingFileIdUsingWebDavAPI(string $user, string $filePath, TableNode $properties) {
$response = $this->lockFileUsingFileId($user, $filePath, $properties, false, false);
$fullUrl = $this->featureContext->getBaseUrl() . $filePath;
$response = $this->lockFileInSpace($user, $fullUrl, $properties, false, false);
ScharfViktor marked this conversation as resolved.
Show resolved Hide resolved
$this->featureContext->setResponse($response);
}

Expand Down Expand Up @@ -837,6 +780,8 @@ public function before(BeforeScenarioScope $scope) {
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->publicWebDavContext = $environment->getContext('PublicWebDavContext');
$this->spacesContext = $environment->getContext('SpacesContext');
if (!OcisHelper::isTestingOnReva()) {
$this->spacesContext = $environment->getContext('SpacesContext');
}
}
}