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

Fix propfind type of subnodes with depth >= 1 #1344

Merged
merged 4 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/DAV/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ private function generatePathNodes(PropFind $propFind, array $yieldFirst = null)
}

$propertyNames = $propFind->getRequestedProperties();
$propFindType = !empty($propertyNames) ? PropFind::NORMAL : PropFind::ALLPROPS;
$propFindType = !$propFind->isAllProps() ? PropFind::NORMAL : PropFind::ALLPROPS;

foreach ($this->tree->getChildren($path) as $childNode) {
if ('' !== $path) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Sabre/DAV/AbstractServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ protected function getRootNode()
return new FS\Directory(SABRE_TEMPDIR);
}

protected function getSanitizedBody()
{
return preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
}

protected function getSanitizedBodyAsXml()
{
return simplexml_load_string($this->getSanitizedBody());
}

private function deleteTree($path, $deleteRoot = true)
{
foreach (scandir($path) as $node) {
Expand Down
6 changes: 2 additions & 4 deletions tests/Sabre/DAV/Locks/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public function testLock()

$this->assertEquals(200, $this->response->status, 'Got an incorrect status back. Response body: '.$this->response->getBodyAsString());

$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$xml = simplexml_load_string($body);
$xml = $this->getSanitizedBodyAsXml();
$xml->registerXPathNamespace('d', 'urn:DAV');

$elements = [
Expand Down Expand Up @@ -128,8 +127,7 @@ public function testLockWithContext()

$this->assertEquals(200, $this->response->status, 'Got an incorrect status back. Response body: '.$this->response->getBodyAsString());

$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$xml = simplexml_load_string($body);
$xml = $this->getSanitizedBodyAsXml();
$xml->registerXPathNamespace('d', 'urn:DAV');

$lockRoot = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:lockroot/d:href');
Expand Down
7 changes: 3 additions & 4 deletions tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public function testLockDiscovery()

$this->sendRequest($xml);

$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$xml = simplexml_load_string($body);
$xml = $this->getSanitizedBodyAsXml();
$xml->registerXPathNamespace('d', 'urn:DAV');

$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:lockdiscovery');
Expand All @@ -138,7 +137,7 @@ public function testUnknownProperty()
</d:propfind>';

$this->sendRequest($xml);
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$body = $this->getSanitizedBody();
$xml = simplexml_load_string($body);
$xml->registerXPathNamespace('d', 'urn:DAV');
$pathTests = [
Expand Down Expand Up @@ -168,7 +167,7 @@ public function testFilesThatAreSiblingsOfDirectoriesShouldBeReportedAsFiles()
</d:propfind>';

$this->sendRequest($xml);
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$body = $this->getSanitizedBody();
$xml = simplexml_load_string($body);
$xml->registerXPathNamespace('d', 'urn:DAV');
$pathTests = [
Expand Down
44 changes: 35 additions & 9 deletions tests/Sabre/DAV/ServerPropsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public function testPropFindEmptyBody()
$this->response->getHeaders()
);

$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$xml = simplexml_load_string($body);
$xml = $this->getSanitizedBodyAsXml();
$xml->registerXPathNamespace('d', 'urn:DAV');

list($data) = $xml->xpath('/d:multistatus/d:response/d:href');
Expand All @@ -66,6 +65,36 @@ public function testPropFindEmptyBody()
$this->assertEquals(1, count($data));
}

public function testPropFindEmptyBodyDepth1Custom()
{
// Add custom property to nodes.
$this->server->on('propFind', function (PropFind $propFind, INode $node) {
$propFind->set('{DAV:}ishidden', '1');
});

$this->sendRequest('', '/', ['Depth' => 1]);
$this->assertEquals(207, $this->response->status);

$this->assertEquals([
'X-Sabre-Version' => [Version::VERSION],
'Content-Type' => ['application/xml; charset=utf-8'],
'DAV' => ['1, 3, extended-mkcol, 2'],
'Vary' => ['Brief,Prefer'],
],
$this->response->getHeaders()
);

$xml = $this->getSanitizedBodyAsXml();
$xml->registerXPathNamespace('d', 'urn:DAV');

$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:ishidden');
$this->assertEquals(5, count($data), 'Response should contain 5 elements');

foreach ($data as $prop) {
$this->assertEquals('1', $prop[0]);
}
}

public function testPropFindEmptyBodyFile()
{
$this->sendRequest('', '/test2.txt', []);
Expand All @@ -80,8 +109,7 @@ public function testPropFindEmptyBodyFile()
$this->response->getHeaders()
);

$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$xml = simplexml_load_string($body);
$xml = $this->getSanitizedBodyAsXml();
$xml->registerXPathNamespace('d', 'urn:DAV');

list($data) = $xml->xpath('/d:multistatus/d:response/d:href');
Expand All @@ -102,8 +130,7 @@ public function testSupportedLocks()

$this->sendRequest($xml);

$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$xml = simplexml_load_string($body);
$xml = $this->getSanitizedBodyAsXml();
$xml->registerXPathNamespace('d', 'urn:DAV');

$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry');
Expand Down Expand Up @@ -136,8 +163,7 @@ public function testLockDiscovery()

$this->sendRequest($xml);

$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$xml = simplexml_load_string($body);
$xml = $this->getSanitizedBodyAsXml();
$xml->registerXPathNamespace('d', 'urn:DAV');

$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:lockdiscovery');
Expand All @@ -154,7 +180,7 @@ public function testUnknownProperty()
</d:propfind>';

$this->sendRequest($xml);
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$body = $this->getSanitizedBody();
$xml = simplexml_load_string($body);
$xml->registerXPathNamespace('d', 'urn:DAV');
$pathTests = [
Expand Down