This commit is contained in:
Robin Appelman 2019-11-06 14:15:26 +01:00
commit 7174c02348
2 changed files with 77 additions and 58 deletions

View file

@ -84,7 +84,8 @@ class SearchHandler {
$response->setBody($e->getMessage()); $response->setBody($e->getMessage());
return false; return false;
} }
$data = $this->server->generateMultiStatus(iterator_to_array($this->getPropertiesIteratorResults($results, $query->select)), false); $data = $this->server->generateMultiStatus(iterator_to_array($this->getPropertiesIteratorResults($results,
$query->select)), false);
$response->setBody($data); $response->setBody($data);
return false; return false;
} }
@ -140,11 +141,13 @@ class SearchHandler {
throw new BadRequest('requested search property is not searchable'); throw new BadRequest('requested search property is not searchable');
} }
return $prop; return $prop;
} else if ($argument instanceof \SearchDAV\XML\Operator) { } else {
if ($argument instanceof \SearchDAV\XML\Operator) {
return $this->transformOperator($argument, $allProps); return $this->transformOperator($argument, $allProps);
} else { } else {
return $argument; return $argument;
} }
}
}, $operator->arguments); }, $operator->arguments);
return new Operator($operator->type, $arguments); return new Operator($operator->type, $arguments);

View file

@ -60,7 +60,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
->willReturn('foo'); ->willReturn('foo');
$request = new Request('SEARCH', 'foo', [ $request = new Request('SEARCH', 'foo', [
'Content-Type' => 'text/plain' 'Content-Type' => 'text/plain',
], fopen(__DIR__ . '/nofrom.xml', 'r')); ], fopen(__DIR__ . '/nofrom.xml', 'r'));
$response = new Response(); $response = new Response();
@ -75,7 +75,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
->willReturn('foo'); ->willReturn('foo');
$request = new Request('SEARCH', 'bar', [ $request = new Request('SEARCH', 'bar', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
], fopen(__DIR__ . '/nofrom.xml', 'r')); ], fopen(__DIR__ . '/nofrom.xml', 'r'));
$response = new Response(); $response = new Response();
@ -90,7 +90,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
->willReturn('foo'); ->willReturn('foo');
$request = new Request('SEARCH', 'foo', [ $request = new Request('SEARCH', 'foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
], fopen(__DIR__ . '/invalidtype.xml', 'r')); ], fopen(__DIR__ . '/invalidtype.xml', 'r'));
$response = new Response(); $response = new Response();
@ -107,7 +107,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
->willReturn('foo'); ->willReturn('foo');
$request = new Request('SEARCH', 'foo', [ $request = new Request('SEARCH', 'foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
], fopen(__DIR__ . '/nofrom.xml', 'r')); ], fopen(__DIR__ . '/nofrom.xml', 'r'));
$response = new Response(); $response = new Response();
@ -171,7 +171,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/discover.xml', 'r')); $request->setBody(fopen(__DIR__ . '/discover.xml', 'r'));
@ -184,10 +184,12 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$this->searchBackend->expects($this->once()) $this->searchBackend->expects($this->once())
->method('getPropertyDefinitionsForScope') ->method('getPropertyDefinitionsForScope')
->willReturn([ ->willReturn([
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
new SearchPropertyDefinition('{DAV:}displayname', true, true, true), new SearchPropertyDefinition('{DAV:}displayname', true, true, true),
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true,
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
]); ]);
$plugin->searchHandler($request, $response); $plugin->searchHandler($request, $response);
@ -208,7 +210,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/discover.xml', 'r')); $request->setBody(fopen(__DIR__ . '/discover.xml', 'r'));
@ -239,7 +241,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/invaliddiscover.xml', 'r')); $request->setBody(fopen(__DIR__ . '/invaliddiscover.xml', 'r'));
@ -266,7 +268,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/basicquery.xml', 'r')); $request->setBody(fopen(__DIR__ . '/basicquery.xml', 'r'));
@ -276,17 +278,18 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
->method('isValidScope') ->method('isValidScope')
->willReturn(true); ->willReturn(true);
$lengthProp = new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER); $lengthProp = new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER);
$orderBy = [ $orderBy = [
new \SearchDAV\Query\Order($lengthProp, \SearchDAV\Query\Order::ASC) new \SearchDAV\Query\Order($lengthProp, \SearchDAV\Query\Order::ASC),
]; ];
$select = [$lengthProp]; $select = [$lengthProp];
$from = [ $from = [
new Scope('/container1/', 'infinity', '/container1/') new Scope('/container1/', 'infinity', '/container1/'),
]; ];
$where = new \SearchDAV\Query\Operator(\SearchDAV\Query\Operator::OPERATION_GREATER_THAN, [ $where = new \SearchDAV\Query\Operator(\SearchDAV\Query\Operator::OPERATION_GREATER_THAN, [
$lengthProp, $lengthProp,
new Literal(10000) new Literal(10000),
]); ]);
$limit = new Limit(); $limit = new Limit();
$query = new Query($select, $from, $where, $orderBy, $limit); $query = new Query($select, $from, $where, $orderBy, $limit);
@ -298,13 +301,13 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
new SearchResult( new SearchResult(
new Directory('/foo'), new Directory('/foo'),
'/foo' '/foo'
) ),
]); ]);
$this->searchBackend->expects($this->any()) $this->searchBackend->expects($this->any())
->method('getPropertyDefinitionsForScope') ->method('getPropertyDefinitionsForScope')
->willReturn([ ->willReturn([
$lengthProp $lengthProp,
]); ]);
$plugin->searchHandler($request, $response); $plugin->searchHandler($request, $response);
@ -325,7 +328,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/nofrom.xml', 'r')); $request->setBody(fopen(__DIR__ . '/nofrom.xml', 'r'));
@ -348,13 +351,14 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
->method('getArbiterPath') ->method('getArbiterPath')
->willReturn('foo'); ->willReturn('foo');
$lengthProp = new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER); $lengthProp = new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER);
$plugin = new SearchPlugin($this->searchBackend); $plugin = new SearchPlugin($this->searchBackend);
$server = new Server(); $server = new Server();
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/nowhere.xml', 'r')); $request->setBody(fopen(__DIR__ . '/nowhere.xml', 'r'));
@ -390,7 +394,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/noselect.xml', 'r')); $request->setBody(fopen(__DIR__ . '/noselect.xml', 'r'));
@ -418,7 +422,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/invalid.xml', 'r')); $request->setBody(fopen(__DIR__ . '/invalid.xml', 'r'));
@ -467,7 +471,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/invalidwhere.xml', 'r')); $request->setBody(fopen(__DIR__ . '/invalidwhere.xml', 'r'));
@ -483,7 +487,8 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$this->searchBackend->expects($this->once()) $this->searchBackend->expects($this->once())
->method('getPropertyDefinitionsForScope') ->method('getPropertyDefinitionsForScope')
->willReturn([ ->willReturn([
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true,
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
]); ]);
$plugin->searchHandler($request, $response); $plugin->searchHandler($request, $response);
@ -501,7 +506,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/invalidwherenoprop.xml', 'r')); $request->setBody(fopen(__DIR__ . '/invalidwherenoprop.xml', 'r'));
@ -517,8 +522,10 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$this->searchBackend->expects($this->any()) $this->searchBackend->expects($this->any())
->method('getPropertyDefinitionsForScope') ->method('getPropertyDefinitionsForScope')
->willReturn([ ->willReturn([
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true,
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
]); ]);
$plugin->searchHandler($request, $response); $plugin->searchHandler($request, $response);
@ -536,7 +543,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$plugin->initialize($server); $plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [ $request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml' 'Content-Type' => 'text/xml',
]); ]);
$request->setBaseUrl('/index.php'); $request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/infiniteloopemptyliteral.xml', 'r')); $request->setBody(fopen(__DIR__ . '/infiniteloopemptyliteral.xml', 'r'));
@ -549,6 +556,15 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$this->searchBackend->expects($this->never()) $this->searchBackend->expects($this->never())
->method('search'); ->method('search');
$this->searchBackend->expects($this->any())
->method('getPropertyDefinitionsForScope')
->willReturn([
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true,
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
]);
$plugin->searchHandler($request, $response); $plugin->searchHandler($request, $response);
$this->assertEquals(400, $response->getStatus()); $this->assertEquals(400, $response->getStatus());