Skip to content

Commit

Permalink
Merge pull request #36941 from owncloud/bug-reproduce-36920
Browse files Browse the repository at this point in the history
[Tests-Only] Bug reproduce 36920
  • Loading branch information
phil-davis committed Feb 14, 2020
2 parents caa0f6d + 07f2637 commit 099f313
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 0 deletions.
130 changes: 130 additions & 0 deletions tests/TestHelpers/WebDavHelper.php
Expand Up @@ -142,6 +142,54 @@ public static function propfind(
);
}

/**
* sends HTTP request PROPFIND method with multiple properties
*
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $path
* @param array $properties
* @param string $namespaceString
* @param int $folderDepth
* @param string $type
* @param int $davPathVersionToUse
*
* @return ResponseInterface
*/
public static function propfindWithMultipleProps(
$baseUrl,
$user,
$password,
$path,
$properties,
$namespaceString = "oc='http://owncloud.org/ns'",
$folderDepth = 0,
$type = "files",
$davPathVersionToUse = 2
) {
$propertyBody = "";
foreach ($properties as $property) {
[$namespacePrefix, $namespace, $property] = self::getPropertyWithNamespaceInfo(
$namespaceString,
$property
);
$propertyBody .= "\n\t\t<$namespacePrefix:$property/>";
}
$body = "<?xml version=\"1.0\"?>
<d:propfind
xmlns:d=\"DAV:\"
xmlns:oc=\"http://owncloud.org/ns\"
xmlns:ocs=\"http://open-collaboration-services.org/ns\">
<d:prop>$propertyBody
</d:prop>
</d:propfind>";
return self::makeDavRequest(
$baseUrl, $user, $password, "PROPFIND", $path, null, $body,
$davPathVersionToUse, $type
);
}

/**
*
* @param string $baseUrl
Expand Down Expand Up @@ -183,7 +231,89 @@ public static function proppatch(
<d:prop>$propertyBody</d:prop>
</d:set>
</d:propertyupdate>";
return self::makeDavRequest(
$baseUrl, $user, $password, "PROPPATCH", $path, [], $body,
$davPathVersionToUse, $type
);
}

/**
* gets namespace-prefix, namespace url and propName from provided namespaceString or property
* or otherwise use default
*
* @param string $namespaceString
* @param string $property
*
* @return array
*/
public static function getPropertyWithNamespaceInfo($namespaceString = "", $property = "") {
$namespace = "";
$namespacePrefix = "";
if (\is_int($namespaceString)) {
//default namespace prefix if the property has no array key
//also used if no prefix is given in the property value
$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];
}
//if a namespace prefix is given in the property value use that
if ($property && \strpos($property, ":")) {
$propertyParts = \explode(":", $property);
$namespacePrefix = $propertyParts[0];
$property = $propertyParts[1];
}
return [$namespacePrefix, $namespace, $property];
}

/**
* sends HTTP request PROPPATCH method with multiple properties
*
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $path
* @param array $propertiesArray
* @param string $namespaceString
* @param int $davPathVersionToUse
* @param string $type
*
* @return ResponseInterface
*/
public static function proppatchWithMultipleProps(
$baseUrl,
$user,
$password,
$path,
$propertiesArray,
$namespaceString = "oc='http://owncloud.org/ns'",
$davPathVersionToUse = 2,
$type="files"
) {
$propertyBody = "";
foreach ($propertiesArray as $propertyArray) {
$property = $propertyArray["property"];
$value = $propertyArray["value"];
[$namespacePrefix, $namespace, $property] = self::getPropertyWithNamespaceInfo(
$namespaceString,
$property
);
$propertyBody .= "\n\t<$namespacePrefix:$property>" .
"$value" .
"</$namespacePrefix:$property>";
}
$body = "<?xml version=\"1.0\"?>
<d:propertyupdate xmlns:d=\"DAV:\"
xmlns:oc=\"http://owncloud.org/ns\">
<d:set>
<d:prop>$propertyBody
</d:prop>
</d:set>
</d:propertyupdate>";
return self::makeDavRequest(
$baseUrl, $user, $password, "PROPPATCH", $path, [], $body,
$davPathVersionToUse, $type
Expand Down
Expand Up @@ -190,3 +190,49 @@ Feature: get file properties
| url | message |
| /remote.php/dav/files/does-not-exist | Principal with name does-not-exist not found |
| /remote.php/dav/does-not-exist | File not found: does-not-exist in 'root' |

Scenario: add, receive multiple custom meta properties to a file
Given user "user0" has created folder "/TestFolder"
And user "user0" has uploaded file with content "test data one" to "/TestFolder/test1.txt"
And user "user0" has set the following properties of file "/TestFolder/test1.txt" using the WebDav API
| property | value |
| testprop1 | AAAAA |
| testprop2 | BBBBB |
When user "user0" gets the following properties of file "/TestFolder/test1.txt" using the WebDav PropFind API
| property |
| testprop1 |
| testprop2 |
Then the HTTP status code should be success
And as user "user0" the last response should have the following properties
| resource | property | value |
| /TestFolder/test1.txt | testprop1 | AAAAA |
| /TestFolder/test1.txt | testprop2 | BBBBB |
| /TestFolder/test1.txt | status | HTTP/1.1 200 OK |

@issue-36920
Scenario: add multiple properties to files inside a folder and do a propfind of the parent folder
Given user "user0" has created folder "/TestFolder"
And user "user0" has uploaded file with content "test data one" to "/TestFolder/test1.txt"
And user "user0" has uploaded file with content "test data two" to "/TestFolder/test2.txt"
And user "user0" has set the following properties of file "/TestFolder/test1.txt" using the WebDav API
| property | value |
| testprop1 | AAAAA |
| testprop2 | BBBBB |
And user "user0" has set the following properties of file "/TestFolder/test2.txt" using the WebDav API
| property | value |
| testprop1 | CCCCC |
| testprop2 | DDDDD |
When user "user0" gets the following properties of folder "/TestFolder" using the WebDav PropFind API
| property |
| testprop1 |
| testprop2 |
Then the HTTP status code should be success
And as user "user0" the last response should have the following properties
| resource | property | value |
| /TestFolder/test1.txt | testprop1 | CCCCC |
#| /TestFolder/test1.txt | testprop1 | AAAAA |
| /TestFolder/test1.txt | testprop2 | BBBBB |
| /TestFolder/test2.txt | testprop1 | CCCCC |
| /TestFolder/test2.txt | testprop2 | DDDDD |
| /TestFolder/ | status | HTTP/1.1 404 Not Found |
#| /TestFolder/ | status | HTTP/1.1 200 OK |
104 changes: 104 additions & 0 deletions tests/acceptance/features/bootstrap/WebDavPropertiesContext.php
Expand Up @@ -103,6 +103,33 @@ public function theUserGetsPropertiesOfFolder($path, $propertiesTable) {
);
}

/**
* @Given /^user "([^"]*)" has set the following properties of (?:file|folder|entry) "([^"]*)" using the WebDav API$/
*
* @param string $username
* @param string $path
* @param TableNode|null $propertiesTable with following columns with column header as:
* property: name of prop to be set
* value: value of prop to be set
*
* @return void
* @throws Exception
*/
public function userHasSetFollowingPropertiesUsingProppatch($username, $path, $propertiesTable) {
$this->featureContext->verifyTableNodeColumns($propertiesTable, ['property', 'value']);
$properties = $propertiesTable->getColumnsHash();
$this->featureContext->setResponse(
WebDavHelper::proppatchWithMultipleProps(
$this->featureContext->getBaseUrl(),
$username,
$this->featureContext->getPasswordForUser($username),
$path,
$properties
)
);
$this->featureContext->theHTTPStatusCodeShouldBeSuccess();
}

/**
* @When user :user gets a custom property :propertyName with namespace :namespace of file :path
*
Expand Down Expand Up @@ -130,6 +157,38 @@ public function userGetsPropertiesOfFile(
);
}

/**
* @When user :username gets the following properties of file/folder :path using the WebDav PropFind API
*
* @param string $username
* @param string $path
* @param TableNode $propertiesTable with single column with column header 'property'
*
* @return void
* @throws Exception
*/
public function userGetsFollowingPropsWithNamespaceOfFileUsingWebDavAPI(
$username, $path, $propertiesTable
) {
$this->featureContext->verifyTableNodeColumns($propertiesTable, ["property",]);
$properties = [];
foreach ($propertiesTable->getColumnsHash() as $col) {
\array_push($properties, $col["property"]);
}
$this->featureContext->setResponse(
WebDavHelper::propfindWithMultipleProps(
$this->featureContext->getBaseUrl(),
$username,
$this->featureContext->getPasswordForUser($username),
$path,
$properties
)
);
$this->featureContext->setResponseXmlObject(
HttpRequestHelper::getResponseXml($this->featureContext->getResponse())
);
}

/**
* @When /^the public gets the following properties of (?:file|folder|entry) "([^"]*)" in the last created public link using the WebDAV API$/
*
Expand Down Expand Up @@ -574,6 +633,51 @@ public function thePropertiesResponseShouldContainAnEtag() {
}
}

/**
* @Then as user :username the last response should have the following properties
*
* @param string $username
* @param TableNode $expectedPropTable with following columns:
* resource: full path of resource(file/folder/entry) from root of your oc storage
* property: expected name of property to be asserted, eg: status, href, customPropName
* value: expected value of expected property
*
* @return void
* @throws Exception
*/
public function theResponseShouldHavePropertyWithValue($username, $expectedPropTable) {
$this->featureContext->verifyTableNodeColumns($expectedPropTable, ['resource', 'property', 'value']);
$responseXmlObject = $this->featureContext->getResponseXmlObject();

$hrefSplittedUptoUsername = \explode("/", $responseXmlObject->xpath("//d:href")[0]);
$xmlHrefSplittedArray = \array_slice(
$hrefSplittedUptoUsername,
0,
\array_search($username, $hrefSplittedUptoUsername) + 1
);
$xmlHref = \implode("/", $xmlHrefSplittedArray);
foreach ($expectedPropTable->getColumnsHash() as $col) {
if ($col["property"] === "status") {
$xmlPart = $responseXmlObject->xpath(
"//d:href[.='" .
$xmlHref . $col["resource"] .
"']/following-sibling::d:propstat//d:" .
$col["property"]
);
} else {
$xmlPart = $responseXmlObject->xpath(
"//d:href[.= '" .
$xmlHref . $col["resource"] .
"']/..//oc:" . $col["property"]
);
}
Assert::assertEquals(
$col["value"],
$xmlPart[0]
);
}
}

/**
* @Then the etag of element :path of user :user should not have changed
*
Expand Down

0 comments on commit 099f313

Please sign in to comment.