test: fix custom properties tests

This commit is contained in:
Saw-jan
2024-08-05 12:25:55 +05:45
parent 903131f767
commit 62c024bc66
4 changed files with 75 additions and 86 deletions

View File

@@ -63,6 +63,18 @@ class WebDavHelper {
}
}
/**
* @param string $namespaceString
*
* @return object
*/
public static function parseNamespace(string $namespaceString): object {
//calculate the namespace prefix and namespace
$matches = [];
\preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches);
return (object)["namespace" => $matches[2], "prefix" => $matches[1]];
}
/**
* returns the id of a file
*
@@ -132,12 +144,9 @@ class WebDavHelper {
//also used if no prefix is given in the property value
$namespacePrefix = null;
} else {
//calculate the namespace prefix and namespace from the array key
$matches = [];
\preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches);
$nameSpace = $matches[2];
$namespacePrefix = $matches[1];
$extraNamespaces .= " xmlns:$namespacePrefix=\"$nameSpace\" ";
$ns = self::parseNamespace($namespaceString);
$namespacePrefix = $ns->prefix;
$extraNamespaces .= " xmlns:$namespacePrefix=\"$ns->namespace\" ";
}
//if a namespace prefix is given in the property value use that
if (\strpos($property, ":") !== false) {
@@ -263,14 +272,11 @@ class WebDavHelper {
?string $type="files"
):ResponseInterface {
if ($namespaceString !== null) {
$matches = [];
\preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches);
$namespace = $matches[2];
$namespacePrefix = $matches[1];
$propertyBody = "<$namespacePrefix:$propertyName" .
" xmlns:$namespacePrefix=\"$namespace\">" .
$ns = self::parseNamespace($namespaceString);
$propertyBody = "<$ns->prefix:$propertyName" .
" xmlns:$ns->prefix=\"$ns->namespace\">" .
"$propertyValue" .
"</$namespacePrefix:$propertyName>";
"</$ns->prefix:$propertyName>";
} else {
$propertyBody = "<$propertyName>$propertyValue</$propertyName>";
}
@@ -299,12 +305,12 @@ class WebDavHelper {
* gets namespace-prefix, namespace url and propName from provided namespaceString or property
* or otherwise use default
*
* @param string|null $namespaceString
* @param string|null $property
* @param string $namespaceString
* @param string $property
*
* @return array
*/
public static function getPropertyWithNamespaceInfo(?string $namespaceString = "", ?string $property = ""):array {
public static function getPropertyWithNamespaceInfo(string $namespaceString = "", string $property = ""):array {
$namespace = "";
$namespacePrefix = "";
if (\is_int($namespaceString)) {
@@ -313,11 +319,9 @@ class WebDavHelper {
$namespacePrefix = "d";
$namespace = "DAV:";
} elseif ($namespaceString) {
//calculate the namespace prefix and namespace from the array key
$matches = [];
\preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches);
$namespacePrefix = $matches[1];
$namespace = $matches[2];
$ns = self::parseNamespace($namespaceString);
$namespacePrefix = $ns->prefix;
$namespace = $ns->namespace;
}
//if a namespace prefix is given in the property value use that
if ($property && \strpos($property, ":")) {
@@ -352,20 +356,26 @@ class WebDavHelper {
?array $propertiesArray,
?string $xRequestId = '',
?int $davPathVersion = null,
?string $namespaceString = "oc='http://owncloud.org/ns'",
?string $namespaceString = null,
?string $type="files"
):ResponseInterface {
$propertyBody = "";
foreach ($propertiesArray as $propertyArray) {
$property = $propertyArray["propertyName"];
$value = $propertyArray["propertyValue"];
[$namespacePrefix, $namespace, $property] = self::getPropertyWithNamespaceInfo(
$namespaceString,
$property
);
$propertyBody .= "\n\t<$namespacePrefix:$property>" .
"$value" .
"</$namespacePrefix:$property>";
if ($namespaceString !== null) {
$matches = [];
[$namespacePrefix, $namespace, $property] = self::getPropertyWithNamespaceInfo(
$namespaceString,
$property
);
$propertyBody .= "\n\t<$namespacePrefix:$property>" .
"$value" .
"</$namespacePrefix:$property>";
} else {
$propertyBody .= "<$property>$value</$property>";
}
}
$body = "<?xml version=\"1.0\"?>
<d:propertyupdate xmlns:d=\"DAV:\"

View File

@@ -24,15 +24,6 @@ _ocdav: double-check the webdav property parsing when custom namespaces are used
- [coreApiWebdavProperties/setFileProperties.feature:129](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavProperties/setFileProperties.feature#L129)
- [coreApiWebdavProperties/setFileProperties.feature:130](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavProperties/setFileProperties.feature#L130)
#### [Cannot set custom webDav properties](https://github.com/owncloud/product/issues/264)
- [coreApiWebdavProperties/getFileProperties.feature:316](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavProperties/getFileProperties.feature#L316)
- [coreApiWebdavProperties/getFileProperties.feature:317](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavProperties/getFileProperties.feature#L317)
- [coreApiWebdavProperties/getFileProperties.feature:318](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavProperties/getFileProperties.feature#L318)
- [coreApiWebdavProperties/getFileProperties.feature:348](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavProperties/getFileProperties.feature#L348)
- [coreApiWebdavProperties/getFileProperties.feature:349](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavProperties/getFileProperties.feature#L349)
- [coreApiWebdavProperties/getFileProperties.feature:350](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavProperties/getFileProperties.feature#L350)
#### [file versions do not report the version author](https://github.com/owncloud/ocis/issues/2914)
- [coreApiVersions/fileVersionAuthor.feature:15](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiVersions/fileVersionAuthor.feature#L15)

View File

@@ -42,18 +42,6 @@ class WebDavPropertiesContext implements Context {
*/
private array $storedETAG = [];
/**
* @param string $namespaceString
*
* @return object
*/
public function parseNamespace(string $namespaceString): object {
//calculate the namespace prefix and namespace
$matches = [];
\preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches);
return (object)["namespace" => $matches[2], "prefix" => $matches[1]];
}
/**
* @When /^user "([^"]*)" gets the properties of (?:file|folder|entry) "([^"]*)" using the WebDAV API$/
*
@@ -165,10 +153,7 @@ class WebDavPropertiesContext implements Context {
}
/**
* @Given /^user "([^"]*)" has set the following properties of (?:file|folder|entry) "([^"]*)" using the WebDav API$/
*
* if no namespace prefix is provided before property, default `oc:` prefix is set for added props
* only and everything rest on xml is set to prefix `d:`
* @Given /^user "([^"]*)" has set the following properties to (?:file|folder|entry) "([^"]*)" using the WebDav API$/
*
* @param string $username
* @param string $path
@@ -490,7 +475,7 @@ class WebDavPropertiesContext implements Context {
$this->featureContext->getResponse(),
__METHOD__
);
$ns = $this->parseNamespace($namespaceString);
$ns = WebDavHelper::parseNamespace($namespaceString);
$responseXmlObject->registerXPathNamespace(
$ns->prefix,
$ns->namespace
@@ -646,7 +631,7 @@ class WebDavPropertiesContext implements Context {
$xmlPart = $this->featureContext->getResponseXml($response);
if ($namespaceString !== null) {
$ns = $this->parseNamespace($namespaceString);
$ns = WebDavHelper::parseNamespace($namespaceString);
$xmlPart->registerXPathNamespace(
$ns->prefix,
$ns->namespace
@@ -1264,6 +1249,23 @@ class WebDavPropertiesContext implements Context {
);
}
/**
* @param string $href
*
* @return string
*/
public function parseBaseDavPathFromXMLHref(string $href): string {
$hrefArr = \explode('/', $href);
if (\in_array("webdav", $hrefArr)) {
$hrefArr = \array_slice($hrefArr, 0, \array_search("webdav", $hrefArr) + 1);
} elseif (\in_array("files", $hrefArr)) {
$hrefArr = \array_slice($hrefArr, 0, \array_search("files", $hrefArr) + 2);
} elseif (\in_array("spaces", $hrefArr)) {
$hrefArr = \array_slice($hrefArr, 0, \array_search("spaces", $hrefArr) + 2);
}
return \implode('/', $hrefArr);
}
/**
* @Then as user :username the last response should have the following properties
*
@@ -1283,28 +1285,14 @@ class WebDavPropertiesContext implements Context {
$this->featureContext->verifyTableNodeColumns($expectedPropTable, ['resource', 'propertyName', 'propertyValue']);
$responseXmlObject = $this->featureContext->getResponseXml();
$hrefSplitUptoUsername = \explode("/", (string)$responseXmlObject->xpath("//d:href")[0]);
$xmlHrefSplitArray = \array_slice(
$hrefSplitUptoUsername,
0,
\array_search($username, $hrefSplitUptoUsername) + 1
);
$xmlHref = \implode("/", $xmlHrefSplitArray);
$href = (string)$responseXmlObject->xpath("//d:href")[0];
$hrefBase = $this->parseBaseDavPathFromXMLHref($href);
foreach ($expectedPropTable->getColumnsHash() as $col) {
if ($col["propertyName"] === "status") {
$xmlPart = $responseXmlObject->xpath(
"//d:href[.='" .
$xmlHref . $col["resource"] .
"']/following-sibling::d:propstat//d:" .
$col["propertyName"]
);
} else {
$xmlPart = $responseXmlObject->xpath(
"//d:href[.= '" .
$xmlHref . $col["resource"] .
"']/..//oc:" . $col["propertyName"]
);
}
$xpath = "//d:href[.='$hrefBase" . $col["resource"] . "']" .
"/following-sibling::d:propstat//" . $col["propertyName"];
$xmlPart = $responseXmlObject->xpath($xpath);
Assert::assertEquals(
$col["propertyValue"],
$xmlPart[0],

View File

@@ -297,20 +297,20 @@ Feature: get file properties
Given using <dav-path-version> DAV path
And user "Alice" has created folder "/TestFolder"
And user "Alice" has uploaded file with content "test data one" to "/TestFolder/test1.txt"
And user "Alice" has set the following properties of file "/TestFolder/test1.txt" using the WebDav API
And user "Alice" has set the following properties to file "/TestFolder/test1.txt" using the WebDav API
| propertyName | propertyValue |
| testprop1 | AAAAA |
| testprop2 | BBBBB |
When user "Alice" gets the following properties of file "/TestFolder/test1.txt" using the WebDAV API
| propertyName |
| oc:testprop1 |
| oc:testprop2 |
| testprop1 |
| testprop2 |
Then the HTTP status code should be "207"
And as user "Alice" the last response should have the following properties
| resource | propertyName | propertyValue |
| /TestFolder/test1.txt | testprop1 | AAAAA |
| /TestFolder/test1.txt | testprop2 | BBBBB |
| /TestFolder/test1.txt | status | HTTP/1.1 200 OK |
| /TestFolder/test1.txt | d:status | HTTP/1.1 200 OK |
Examples:
| dav-path-version |
| new |
@@ -323,18 +323,18 @@ Feature: get file properties
And user "Alice" has created folder "/TestFolder"
And user "Alice" has uploaded file with content "test data one" to "/TestFolder/test1.txt"
And user "Alice" has uploaded file with content "test data two" to "/TestFolder/test2.txt"
And user "Alice" has set the following properties of file "/TestFolder/test1.txt" using the WebDav API
And user "Alice" has set the following properties to file "/TestFolder/test1.txt" using the WebDav API
| propertyName | propertyValue |
| testprop1 | AAAAA |
| testprop2 | BBBBB |
And user "Alice" has set the following properties of file "/TestFolder/test2.txt" using the WebDav API
And user "Alice" has set the following properties to file "/TestFolder/test2.txt" using the WebDav API
| propertyName | propertyValue |
| testprop1 | CCCCC |
| testprop2 | DDDDD |
When user "Alice" gets the following properties of folder "/TestFolder" using the WebDAV API
| propertyName |
| oc:testprop1 |
| oc:testprop2 |
| testprop1 |
| testprop2 |
Then the HTTP status code should be "207"
And as user "Alice" the last response should have the following properties
| resource | propertyName | propertyValue |
@@ -342,7 +342,7 @@ Feature: get file properties
| /TestFolder/test1.txt | testprop2 | BBBBB |
| /TestFolder/test2.txt | testprop1 | CCCCC |
| /TestFolder/test2.txt | testprop2 | DDDDD |
| /TestFolder/ | status | HTTP/1.1 404 Not Found |
| /TestFolder/ | d:status | HTTP/1.1 404 Not Found |
Examples:
| dav-path-version |
| new |