3 * Tine 2.0 - http://www.tine20.org
6 * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
7 * @copyright Copyright (c) 2012-2014 Metaways Infosystems GmbH (http://www.metaways.de)
8 * @author Lars Kneschke <l.kneschke@metaways.de>
12 * Test class for Tinebase_Server_WebDAV
16 class Tinebase_Server_WebDAVTests extends ServerTestCase
18 #protected $_logPriority = Zend_Log::DEBUG;
21 * test general functionality of Tinebase_Server_WebDAV
24 public function testServer()
26 $request = \Zend\Http\PhpEnvironment\Request::fromString(<<<EOS
27 PROPFIND /calendars/64d7fdf9202f7b1faf7467f5066d461c2e75cf2b/4/ HTTP/1.1
30 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7
34 $_SERVER['REQUEST_METHOD'] = $request->getMethod();
35 $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
36 $_SERVER['HTTP_DEPTH'] = '0';
38 $credentials = $this->getTestCredentials();
40 $request->getServer()->set('PHP_AUTH_USER', $credentials['username']);
41 $request->getServer()->set('PHP_AUTH_PW', $credentials['password']);
42 $request->getServer()->set('REMOTE_ADDR', 'localhost');
44 $body = fopen('php://temp', 'r+');
45 fwrite($body, '<?xml version="1.0" encoding="UTF-8"?><D:propfind xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"><D:prop><CS:getctag/></D:prop></D:propfind>');
50 $server = new Tinebase_Server_WebDAV();
52 $server->handle($request, $body);
54 $result = ob_get_contents();
58 $this->assertEquals('PD94bWwgdmVyc2lvbj0iMS4wIiBlbm', substr(base64_encode($result),0,30));
62 * test general functionality of Tinebase_Server_WebDAV
65 public function testServerWithAuthorizationHeader()
67 $credentials = $this->getTestCredentials();
69 $hash = base64_encode($credentials['username'] . ':' . $credentials['password']);
71 $request = \Zend\Http\PhpEnvironment\Request::fromString(
72 "PROPFIND /calendars/64d7fdf9202f7b1faf7467f5066d461c2e75cf2b/4/ HTTP/1.1\r\n"
73 . "Host: localhost\r\n"
75 . "User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7\r\n"
76 . "Authorization: Basic $hash\r\n"
79 $_SERVER['REQUEST_METHOD'] = $request->getMethod();
80 $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
81 $_SERVER['HTTP_DEPTH'] = '0';
83 $request->getServer()->set('REMOTE_ADDR', 'localhost');
85 $body = fopen('php://temp', 'r+');
86 fwrite($body, '<?xml version="1.0" encoding="UTF-8"?><D:propfind xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"><D:prop><CS:getctag/></D:prop></D:propfind>');
91 $server = new Tinebase_Server_WebDAV();
93 $server->handle($request, $body);
95 $result = ob_get_contents();
99 print_r($request->getHeader('HTTP_AUTHORIZATION'));
100 print_r($request->getHeaders());
102 $this->assertEquals('PD94bWwgdmVyc2lvbj0iMS4wIiBlbm', substr(base64_encode($result),0,30), $result);
106 * test general functionality of Tinebase_Server_WebDAV
109 public function testServerWithAuthorizationEnv()
111 $credentials = $this->getTestCredentials();
113 $hash = base64_encode($credentials['username'] . ':' . $credentials['password']);
115 $request = \Zend\Http\PhpEnvironment\Request::fromString(<<<EOS
116 PROPFIND /calendars/64d7fdf9202f7b1faf7467f5066d461c2e75cf2b/4/ HTTP/1.1
119 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7
123 $_SERVER['REQUEST_METHOD'] = $request->getMethod();
124 $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
125 $_SERVER['HTTP_DEPTH'] = '0';
127 $request->getServer()->set('HTTP_AUTHORIZATION', 'Basic ' . $hash);
128 $request->getServer()->set('REMOTE_ADDR', 'localhost');
130 $body = fopen('php://temp', 'r+');
131 fwrite($body, '<?xml version="1.0" encoding="UTF-8"?><D:propfind xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"><D:prop><CS:getctag/></D:prop></D:propfind>');
136 $server = new Tinebase_Server_WebDAV();
138 $server->handle($request, $body);
140 $result = ob_get_contents();
144 $this->assertEquals('PD94bWwgdmVyc2lvbj0iMS4wIiBlbm', substr(base64_encode($result),0,30));
148 * test general functionality of Tinebase_Server_WebDAV
151 public function testServerWithAuthorizationRemoteUser()
153 $credentials = $this->getTestCredentials();
155 $hash = base64_encode($credentials['username'] . ':' . $credentials['password']);
157 $request = \Zend\Http\PhpEnvironment\Request::fromString(<<<EOS
158 PROPFIND /calendars/64d7fdf9202f7b1faf7467f5066d461c2e75cf2b/4/ HTTP/1.1
161 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7
165 $_SERVER['REQUEST_METHOD'] = $request->getMethod();
166 $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
167 $_SERVER['HTTP_DEPTH'] = '0';
169 $request->getServer()->set('REDIRECT_REMOTE_USER', 'Basic ' . $hash);
170 $request->getServer()->set('REMOTE_ADDR', 'localhost');
172 $body = fopen('php://temp', 'r+');
173 fwrite($body, '<?xml version="1.0" encoding="UTF-8"?><D:propfind xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"><D:prop><CS:getctag/></D:prop></D:propfind>');
178 $server = new Tinebase_Server_WebDAV();
180 $server->handle($request, $body);
182 $result = ob_get_contents();
186 $this->assertEquals('PD94bWwgdmVyc2lvbj0iMS4wIiBlbm', substr(base64_encode($result),0,30));
190 * test propfind for current-user-principal
192 * you have to provide a valid contactid
195 public function testPropfindCurrentUserPrincipal()
197 $request = \Zend\Http\PhpEnvironment\Request::fromString(<<<EOS
198 PROPFIND /principals/users/ HTTP/1.1
201 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7
205 $_SERVER['REQUEST_METHOD'] = $request->getMethod();
206 $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
207 $_SERVER['HTTP_DEPTH'] = '0';
209 $credentials = $this->getTestCredentials();
211 $request->getServer()->set('PHP_AUTH_USER', $credentials['username']);
212 $request->getServer()->set('PHP_AUTH_PW', $credentials['password']);
213 $request->getServer()->set('REMOTE_ADDR', 'localhost');
215 $body = fopen('php://temp', 'r+');
216 fwrite($body, '<?xml version="1.0" encoding="UTF-8"?><D:propfind xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav"><D:prop><D:current-user-principal/><D:principal-URL/><D:resourcetype/></D:prop></D:propfind>');
219 $bbody = fopen('php://temp', 'r+');
220 fwrite($bbody, '<?xml version="1.0" encoding="UTF-8"?><D:propfind xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav"><D:prop><C:calendar-home-set/><C:calendar-user-address-set/><C:schedule-inbox-URL/><C:schedule-outbox-URL/></D:prop></D:propfind>');
225 $server = new Tinebase_Server_WebDAV();
227 $server->handle($request, $body);
229 $result = ob_get_contents();
235 $responseDoc = new DOMDocument();
236 $responseDoc->loadXML($result);
237 #$responseDoc->formatOutput = true; error_log($responseDoc->saveXML());
238 $xpath = new DomXPath($responseDoc);
239 $xpath->registerNamespace('d', 'DAV:');
241 $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:href');
242 $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
243 $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
247 * test propfind for current-user-principal
249 * you have to provide a valid contactid
252 public function testPropfindPrincipal()
254 $credentials = $this->getTestCredentials();
256 $account = $this->getAccountByName($credentials['username']);
258 $this->assertInstanceOf('Tinebase_Model_FullUser', $account);
260 $request = \Zend\Http\PhpEnvironment\Request::fromString(
261 "PROPFIND /principals/users/{$account->contact_id}/ HTTP/1.1\r\n"
262 . "Host: localhost\r\n"
264 . "User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7\r\n"
266 . "<?xml version=\"1.0\" encoding=\"UTF-8\"?><D:propfind xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:caldav\"><D:prop><C:calendar-home-set/><C:calendar-user-address-set/><C:schedule-inbox-URL/><C:schedule-outbox-URL/></D:prop></D:propfind>\r\n"
269 $_SERVER['REQUEST_METHOD'] = $request->getMethod();
270 $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
271 $_SERVER['HTTP_DEPTH'] = '0';
273 $request->getServer()->set('PHP_AUTH_USER', $credentials['username']);
274 $request->getServer()->set('PHP_AUTH_PW', $credentials['password']);
275 $request->getServer()->set('REMOTE_ADDR', 'localhost');
279 $server = new Tinebase_Server_WebDAV();
281 $server->handle($request);
283 $result = ob_get_contents();
289 $responseDoc = new DOMDocument();
290 $responseDoc->loadXML($result);
291 #$responseDoc->formatOutput = true; error_log($responseDoc->saveXML());
292 $xpath = new DomXPath($responseDoc);
293 $xpath->registerNamespace('d', 'DAV:');
294 $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav');
296 $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:calendar-home-set');
297 $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
298 $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
300 $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:calendar-user-address-set');
301 $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
302 $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
304 $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:schedule-inbox-URL');
305 $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
306 $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
310 * test general functionality of Tinebase_Server_WebDAV
313 public function testReportQuery()
315 $credentials = $this->getTestCredentials();
317 $account = $this->getAccountByName($credentials['username']);
319 $this->assertInstanceOf('Tinebase_Model_FullUser', $account);
320 if (Tinebase_Core::getUser() === null) {
321 Tinebase_Core::set(Tinebase_Core::USER, $account);
324 $containerId = $this->getPersonalContainer($account, 'Calendar_Model_Event')
328 $request = \Zend\Http\PhpEnvironment\Request::fromString(<<<EOS
329 REPORT /calendars/{$account->contact_id}/{$containerId}/ HTTP/1.1
332 Content-Type: application/xml; charset="utf-8"
333 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7
335 <?xml version="1.0" encoding="utf-8" ?><C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav"><D:prop><D:getetag/><C:calendar-data/></D:prop><C:filter><C:comp-filter name="VCALENDAR"><C:comp-filter name="VEVENT"><C:time-range start="20060104T000000Z" end="20160105T000000Z"/></C:comp-filter></C:comp-filter></C:filter></C:calendar-query>
339 $_SERVER['REQUEST_METHOD'] = $request->getMethod();
340 $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
341 $_SERVER['HTTP_DEPTH'] = '0';
343 $request->getServer()->set('PHP_AUTH_USER', $credentials['username']);
344 $request->getServer()->set('PHP_AUTH_PW', $credentials['password']);
345 $request->getServer()->set('REMOTE_ADDR', 'localhost');
349 $server = new Tinebase_Server_WebDAV();
351 $server->handle($request);
353 $result = ob_get_contents();
357 $responseDoc = new DOMDocument();
358 $responseDoc->loadXML($result);
359 #$responseDoc->formatOutput = true; error_log($responseDoc->saveXML());
361 $xpath = new DomXPath($responseDoc);
362 $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav');
363 $xpath->registerNamespace('cs', 'http://calendarserver.org/ns/');
365 #$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal');
366 #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
369 $this->assertEquals('PD94bWwgdmVyc2lvbj0iMS4wIiBlbm', substr(base64_encode($result),0,30));
373 * test PROPFIND on calendar
377 public function testPropfindThundebird()
379 $credentials = $this->getTestCredentials();
381 $account = $this->getAccountByName($credentials['username']);
383 $this->assertInstanceOf('Tinebase_Model_FullUser', $account);
385 if (Tinebase_Core::getUser() === null) {
386 Tinebase_Core::set(Tinebase_Core::USER, $account);
389 $containerId = $this->getPersonalContainer($account, 'Calendar_Model_Event')
393 $request = \Zend\Http\PhpEnvironment\Request::fromString(
394 "PROPFIND /calendars/{$account->contact_id}/{$containerId}/ HTTP/1.1" . "\r\n"
395 . "Host: localhost" . "\r\n"
396 . "Depth: 1" . "\r\n"
397 . 'Content-Type: application/xml; charset="utf-8"' . "\r\n"
398 . "User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7" . "\r\n"
400 . '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n"
401 . '<D:propfind xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/" xmlns:C="urn:ietf:params:xml:ns:caldav"><D:prop><D:resourcetype/><D:owner/><D:current-user-principal/><D:supported-report-set/><C:supported-calendar-component-set/><CS:getctag/></D:prop></D:propfind>'
405 $_SERVER['REQUEST_METHOD'] = $request->getMethod();
406 $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
407 $_SERVER['HTTP_DEPTH'] = '0';
409 $request->getServer()->set('PHP_AUTH_USER', $credentials['username']);
410 $request->getServer()->set('PHP_AUTH_PW', $credentials['password']);
411 $request->getServer()->set('REMOTE_ADDR', 'localhost');
415 $server = new Tinebase_Server_WebDAV();
417 $server->handle($request);
419 $result = ob_get_contents();
423 $responseDoc = new DOMDocument();
424 $responseDoc->loadXML($result);
425 #$responseDoc->formatOutput = true; error_log($responseDoc->saveXML());
427 $xpath = new DomXPath($responseDoc);
428 $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav');
429 $xpath->registerNamespace('cs', 'http://calendarserver.org/ns/');
431 $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal');
432 $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());