Skip to content

Commit

Permalink
bug reproduce WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranparajuli589 committed Feb 12, 2020
1 parent 61382da commit 6f48807
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 0 deletions.
Empty file modified .htaccess 100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions find.txt
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<a:propfind xmlns:a="DAV:" xmlns:oc="http://owncloud.org/ns">
<a:prop>
<oc:testvar1/>
</a:prop>
</a:propfind>
8 changes: 8 additions & 0 deletions patch1.txt
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<a:propertyupdate xmlns:a="DAV:" xmlns:oc="http://owncloud.org/ns">
<a:set>
<a:prop> <oc:testvar1>AAAAAAAAAAAAAAAAAAAAAA</oc:testvar1>
<oc:testvar2>BBBBBBBBBBBBBBBBBBBB</oc:testvar2>
</a:prop>
</a:set>
</a:propertyupdate>
9 changes: 9 additions & 0 deletions patch2.txt
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<a:propertyupdate xmlns:a="DAV:" xmlns:oc="http://owncloud.org/ns">
<a:set>
<a:prop>
<oc:testvar1>CCCCCCCCCCCCCCCCCC</oc:testvar1>
<oc:testvar2>DDDDDDDDDDDDDDDDDD</oc:testvar2>
</a:prop>
</a:set>
</a:propertyupdate>
86 changes: 86 additions & 0 deletions tests/TestHelpers/WebDavHelper.php
Expand Up @@ -142,6 +142,56 @@ public static function propfind(
);
}

public static function propfind_multiple(
$baseUrl,
$user,
$password,
$path,
$properties,
$folderDepth = 0,
$type = "files",
$davPathVersionToUse = 2
) {
$propertyBody = "";
$extraNamespaces = "";
foreach ($properties as $count => $propertyArray) {
$namespaceString = \array_key_first($propertyArray);
$property = \array_values($propertyArray)[0];
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";
} else {
//calculate the namespace prefix and namespace from the array key
$matches = [];
\preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches);
$nameSpace = $matches[2];
$namespacePrefix = $matches[1];
}
//if a namespace prefix is given in the property value use that
if (\strpos($property, ":") !== false) {
$propertyParts = \explode(":", $property);
$namespacePrefix = $propertyParts[0];
$property = $propertyParts[1];
}
$propertyBody .= "\n\t\t\t<$namespacePrefix:$property/>";
}
$headers = ['Depth' => $folderDepth];
$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>";
var_dump($body);
return self::makeDavRequest(
$baseUrl, $user, $password, "PROPFIND", $path, $headers, $body,
$davPathVersionToUse, $type
);
}

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

public static function proppatch_multiple(
$baseUrl,
$user,
$password,
$path,
$properties,
$namespaceString = "oc='http://owncloud.org/ns'",
$davPathVersionToUse = 2,
$type="files"
) {
$propertyBody = "";
foreach ($properties as $sn => $propertyArray) {
$property = array_key_first($propertyArray);
$value = array_values($propertyArray)[0];
$matches = [];
\preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches);
$namespace = $matches[2];
$namespacePrefix = $matches[1];
$propertyBody .= "\n\t<$namespacePrefix:$property" .
" xmlns:$namespacePrefix=\"$namespace\">" .
"$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,39 @@ 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' |

@issue-36920
Scenario: add, recieve various custom meta properties to my files
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 following properties of file "/TestFolder/test1.txt" using WebDav API
| property | value |
| testprop1 | AAAAA |
| testprop2 | BBBBB |
And user "user0" has set following properties of file "/TestFolder/test2.txt" using WebDav API
| property | value |
| testprop1 | CCCCC |
| testprop2 | DDDDD |
# When user "user0" gets a custom property "testprop1" with namespace "oc='http://owncloud.org/ns'" of file "/TestFolder/test2.txt"
# Then the response should contain a custom "testprop1" property with namespace "oc='http://owncloud.org/ns'" and value "CCCCC"
# When user "user0" gets a custom property "testprop1" with namespace "x1='http://owncloud.org/ns'" of file "/TestFolder/test1.txt"
When user "user0" gets following properties with namespace "oc='http://owncloud.org/ns'" of file "/TestFolder/test1.txt" using WebDav API
| testprop1 |
| testprop2 |
Then the HTTP status code should be success
And following properties with namespace "oc='http://owncloud.org/ns'" should be listed with respective values
| property | value |
| testprop1 | AAAAA |
| testprop2 | BBBBB |

# Then the response should contain a custom "testprop1" property with namespace "x1='http://owncloud.org/ns'" and value "AAAAA"
# And user "user0" has set property "testprop1" with namespace "x1='http://owncloud.org/ns'" of file "/TestFolder/test1.txt" to "AAAAAAAAAA"
# And user "user0" has set property "testprop2" with namespace "x1='http://owncloud.org/ns'" of file "/TestFolder/test1.txt" to "BBBBBBBBBB"
# And user "user0" has set property "testprop1" with namespace "x1='http://owncloud.org/ns'" of file "/TestFolder/test2.txt" to "CCCCCCCCCC"
# And user "user0" has set property "testprop2" with namespace "x1='http://owncloud.org/ns'" of file "/TestFolder/test2.txt" to "DDDDDDDDDD"
## When user "user0" gets a custom property "testprop1" with namespace "x1='http://owncloud.org/ns'" of file "/TestFolder/test1.txt"
## Then the response should contain a custom "testprop1" property with namespace "x1='http://owncloud.org/ns'" and value "AAAAAAAAAA"
# When the user gets the following properties of folder "/TestFolder/test1.txt" using the WebDAV propfind API
# | oc:testprop1 |
# | oc:testprop1 |
85 changes: 85 additions & 0 deletions tests/acceptance/features/bootstrap/WebDavPropertiesContext.php
Expand Up @@ -103,6 +103,35 @@ public function theUserGetsPropertiesOfFolder($path, $propertiesTable) {
);
}

/**
* @Given /^user "([^"]*)" has set following properties of (?:file|folder|entry) "([^"]*)" using WebDav API$/
*
* @param string $username
* @param string $path
* @param TableNode|null $propertiesTable
*
* @returns void
* @throws Exception
*/
public function userHasSetFollowingPropertiesUsingProppatch($username, $path, $propertiesTable) {
$this->featureContext->verifyTableNodeColumns($propertiesTable, ['property', 'value']);
$namespace = 'x1="http://owncloud.org/ns"';
$properties = [];
foreach ($propertiesTable->getColumnsHash() as $col) {
\array_push($properties, [$col["property"] => $col["value"]]);
}
$this->featureContext->setResponse(
WebDavHelper::proppatch_multiple(
$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 +159,33 @@ public function userGetsPropertiesOfFile(
);
}

/**
* @When user :username gets following properties with namespace :namespace of file :path using WebDav API
*
* @param string $username
* @param string $namespace
* @param string $path
* @param TableNode $propertiesTable
*/
public function userGetsFollowingPropsWithNamespaceOfFileUsingWebDavAPI(
$username, $namespace, $path, $propertiesTable
) {
$properties = [];
foreach($propertiesTable->getRows() as $row) {
\array_push($properties, [$namespace => $row[0]]);
}
$this->featureContext->setResponse(
WebDavHelper::propfind_multiple(
$this->featureContext->getBaseUrl(),
$username,
$this->featureContext->getPasswordForUser($username),
$path,
$properties,
1
)
);
}

/**
* @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 @@ -236,10 +292,12 @@ public function userHasSetPropertyWithNamespaceOfEntryTo(
public function theResponseShouldContainACustomPropertyWithValue(
$propertyName, $namespaceString, $propertyValue
) {
var_dump($this->featureContext->getResponse());
$this->featureContext->setResponseXmlObject(
HttpRequestHelper::getResponseXml($this->featureContext->getResponse())
);
$responseXmlObject = $this->featureContext->getResponseXmlObject();
var_dump($responseXmlObject);
//calculate the namespace prefix and namespace
$matches = [];
\preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches);
Expand Down Expand Up @@ -574,6 +632,33 @@ public function thePropertiesResponseShouldContainAnEtag() {
}
}

/**
* @Then /^following properties with namespace "([^"]*)" should be listed with respective values$/
*
* @param string $namespace
* @param TableNode $propertiesTable
* @return void
* @throws \Exception
*/
public function thePropertiesResponseShouldContain($namespace, $propertiesTable) {
$response = $this->featureContext->getResponse();
$this->featureContext->setResponseXmlObject(
HttpRequestHelper::getResponseXml($this->featureContext->getResponse())
);
$responseXmlObject = $this->featureContext->getResponseXmlObject();
var_dump($responseXmlObject);
$responseXmlObject->registerXPathNamespace('oc', 'http://owncloud.org/ns');
$responseXmlObject->registerXPathNamespace('d', 'DAV:');
$responseXmlObject->registerXPathNamespace(
'ocs', 'http://open-collaboration-services.org/ns'
);
var_dump($responseXmlObject);
$xmlPart = $responseXmlObject->xpath(
"//d:prop/testprop1"
);
var_dump($xmlPart);
}

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

0 comments on commit 6f48807

Please sign in to comment.