Add api test for propfind contract testing

This commit is contained in:
Swikriti Tripathi
2022-11-28 14:27:41 +05:45
parent f9b779c2cc
commit 1ceaca7364
3 changed files with 100 additions and 11 deletions

View File

@@ -0,0 +1,24 @@
@api @skipOnOcV10
Feature: Propfind test
check that the PROPFIND response contains all the relevant values
Background:
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
And using spaces DAV path
And the administrator has given "Alice" the role "Space Admin" using the settings api
And user "Alice" has created a space "new-space" with the default quota using the GraphApi
Scenario: check the PROPFIND request of a space
Given user "Alice" has uploaded a file inside space "new-space" with content "some content" to "testfile.txt"
When user "Alice" sends PROPFIND request to space "new-space" using the WebDAV API
Then the HTTP status code should be "207"
And for user "Alice" the "PROPFIND" response should contain a space "new-space" with these key and value pairs:
| key | value |
| oc:fileid | UUIDof:new-space |
| oc:name | new-space |
| oc:permissions | SRDNVCKZ |
| oc:privatelink | |
| oc:size | 12 |

View File

@@ -23,7 +23,7 @@ Feature: Report test
And user "Brian" has accepted share "/folderMain" offered by user "Alice"
When user "Brian" searches for "SubFolder1" using the WebDAV API
Then the HTTP status code should be "207"
And for user "Brian" the REPORT response should contain a mountpoint "folderMain" with these key and value pairs:
And for user "Brian" the "REPORT" response should contain a mountpoint "folderMain" with these key and value pairs:
| key | value |
| oc:fileid | UUIDof:SubFolder1 |
| oc:file-parent | UUIDof:folderMain |
@@ -39,7 +39,7 @@ Feature: Report test
And user "Brian" has accepted share "/folderMain" offered by user "Alice"
When user "Brian" searches for "insideTheFolder.txt" using the WebDAV API
Then the HTTP status code should be "207"
And for user "Brian" the REPORT response should contain a mountpoint "folderMain" with these key and value pairs:
And for user "Brian" the "REPORT" response should contain a mountpoint "folderMain" with these key and value pairs:
| key | value |
| oc:fileid | UUIDof:SubFolder1/subFOLDER2/insideTheFolder.txt |
| oc:file-parent | UUIDof:SubFolder1/subFOLDER2 |

View File

@@ -355,6 +355,32 @@ class SpacesContext implements Context {
return $responseArray[0][0];
}
/**
* @param string $user
* @param string $spaceName
*
* @return string
* @throws GuzzleException
* @throws JsonException
*/
public function getPrivateLink(string $user, string $spaceName): string {
$this->setSpaceIDByName($user, $spaceName);
$response = WebDavHelper::propfind(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
"",
['oc:privatelink'],
"",
"0",
"files",
WebDavHelper::DAV_VERSION_SPACES
);
$responseArray = json_decode(json_encode($this->featureContext->getResponseXml($response)->xpath("//d:response/d:propstat/d:prop/oc:privatelink")), true, 512, JSON_THROW_ON_ERROR);
Assert::assertNotEmpty($responseArray, "the PROPFIND response for $spaceName is empty");
return $responseArray[0][0];
}
/**
* The method returns eTag
*
@@ -1079,7 +1105,7 @@ class SpacesContext implements Context {
* Verify that the tableNode contains expected number of columns
*
* @param TableNode $table
* @param int $count
* @param int $count
*
* @return void
*
@@ -2911,37 +2937,76 @@ class SpacesContext implements Context {
}
/**
* @Then /^for user "([^"]*)" the REPORT response should contain a (?:space|mountpoint) "([^"]*)" with these key and value pairs:$/
* @When /^user "([^"]*)" sends PROPFIND request to space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $spaceName
*
* @throws GuzzleException
*
* @return void
*/
public function userSendsPropfindRequestToSpace(string $user, string $spaceName): void {
$this->setSpaceIDByName($user, $spaceName);
$properties = ['oc:permissions','oc:fileid','oc:share-types','oc:privatelink','d:resourcetype','oc:size','oc:name','d:getcontenttype'];
$this->featureContext->setResponse(
WebDavHelper::propfind(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
"",
$properties,
"",
"0",
"files",
WebDavHelper::DAV_VERSION_SPACES
)
);
}
/**
* @Then /^for user "([^"]*)" the "([^"]*)" response should contain a (?:space|mountpoint) "([^"]*)" with these key and value pairs:$/
*
* @param string $user
* @param string $method # method should be either PROPFIND or REPORT
* @param string $space
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function reportResponseShouldContain(string $user, string $space, TableNode $table): void {
public function theResponseShouldContain(string $user, string $method, string $space, TableNode $table): void {
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
$xmlRes = $this->featureContext->getResponseXml();
$resourceType = $xmlRes->xpath("//d:response/d:propstat/d:prop/d:getcontenttype")[0]->__toString();
foreach ($table->getHash() as $row) {
$findItem = $row['key'];
$responseValue = $xmlRes->xpath("//d:response/d:propstat/d:prop/$findItem")[0]->__toString();
Assert::assertNotEmpty($responseValue, "response doesn't contain $findItem or empty");
$value = str_replace('UUIDof:', '', $row['value']);
switch ($findItem) {
case "oc:fileid":
if ($resourceType === 'httpd/unix-directory') {
Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong fileId in the response');
$resourceType = $xmlRes->xpath("//d:response/d:propstat/d:prop/d:getcontenttype")[0]->__toString();
if ($method === 'PROPFIND') {
if (!$resourceType) {
Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong fileId in the response');
} else {
Assert::assertEquals($this->getFileId($user, $space, $value), $responseValue, 'wrong fileId in the response');
}
} else {
Assert::assertEquals($this->getFileId($user, $space, $value), $responseValue, 'wrong fileId in the response');
if ($resourceType === 'httpd/unix-directory') {
Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong fileId in the response');
} else {
Assert::assertEquals($this->getFileId($user, $space, $value), $responseValue, 'wrong fileId in the response');
}
}
break;
case "oc:file-parent":
Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong file-parentId in the response');
break;
case "oc:privatelink":
Assert::assertEquals($this->getPrivateLink($user, $space), $responseValue, 'cannot find private link for space or resource in the response');
break;
default:
Assert::assertEquals($value, $responseValue, "wrong $findItem in the response");
break;