Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Infrastructure/DavTest.php
- This file was added.
<?php | |||||
namespace Tests\Infrastructure; | |||||
use Tests\TestCase; | |||||
class DavTest extends TestCase | |||||
{ | |||||
private \GuzzleHttp\Client $client; | |||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function setUp(): void | |||||
{ | |||||
parent::setUp(); | |||||
//FIXME test users are probably not created in imap, | |||||
//which is why this fails. So we're using john@kolab.org for now. | |||||
// $user = $this->getTestUser('jane@kolabnow.com'); | |||||
// $user->password = "simple123"; | |||||
// $user->save(); | |||||
$this->client = new \GuzzleHttp\Client([ | |||||
'http_errors' => false, // No exceptions | |||||
'base_uri' => "http://roundcube/", | |||||
'verify' => false, | |||||
// 'auth' => [$user->email, $user->password], | |||||
'auth' => ['john@kolab.org', 'simple123'], | |||||
'connect_timeout' => 10, | |||||
'timeout' => 10, | |||||
'headers' => [ | |||||
"Content-Type" => "application/xml; charset=utf-8", | |||||
"Depth" => "1", | |||||
] | |||||
]); | |||||
} | |||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function tearDown(): void | |||||
{ | |||||
// $this->deleteTestUser('jane@kolabnow.com'); | |||||
parent::tearDown(); | |||||
} | |||||
public function testDiscoverPrincipal() | |||||
{ | |||||
$body = "<d:propfind xmlns:d='DAV:'><d:prop><d:current-user-principal/></d:prop></d:propfind>"; | |||||
$response = $this->client->request('PROPFIND', '/iRony/', ['body' => $body]); | |||||
$this->assertEquals(207, $response->getStatusCode()); | |||||
machniak: Just use `$this->deleteTestUser($this->user->email)`. | |||||
Not Done Inline ActionstearDownAfterClass is a static function. mollekopf: tearDownAfterClass is a static function. | |||||
$data = $response->getBody(); | |||||
$this->assertTrue(str_contains($data, '<d:href>/iRony/principals/john@kolab.org/</d:href>')); | |||||
$this->assertTrue(str_contains($data, '<d:href>/iRony/calendars/</d:href>')); | |||||
$this->assertTrue(str_contains($data, '<d:href>/iRony/addressbooks/</d:href>')); | |||||
} | |||||
/** | |||||
* | |||||
* This codepath is triggerd by MacOS CalDAV when it tries to login. | |||||
* Verify we don't crash and end up with a 500 status code. | |||||
*/ | |||||
public function testFailingLogin() | |||||
{ | |||||
$body = "<d:propfind xmlns:d='DAV:'><d:prop><d:current-user-principal/></d:prop></d:propfind>"; | |||||
$headers = [ | |||||
"Content-Type" => "application/xml; charset=utf-8", | |||||
"Depth" => "1", | |||||
'body' => $body, | |||||
'auth' => ['invaliduser@kolab.org', 'invalid'] | |||||
]; | |||||
$response = $this->client->request('PROPFIND', '/iRony/', $headers); | |||||
$this->assertEquals(401, $response->getStatusCode()); | |||||
} | |||||
/** | |||||
* This codepath is triggerd by MacOS CardDAV when it tries to login. | |||||
* NOTE: This depends on the username_domain roundcube config option. | |||||
*/ | |||||
public function testShortlogin() | |||||
{ | |||||
$body = "<d:propfind xmlns:d='DAV:'><d:prop><d:current-user-principal/></d:prop></d:propfind>"; | |||||
$response = $this->client->request('PROPFIND', '/iRony/', [ | |||||
'body' => $body, | |||||
'auth' => ['john', 'simple123'] | |||||
]); | |||||
$this->assertEquals(207, $response->getStatusCode()); | |||||
} | |||||
public function testDiscoverCalendarHomeset() | |||||
{ | |||||
$body = <<<EOF | |||||
<d:propfind xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav"> | |||||
<d:prop> | |||||
<c:calendar-home-set /> | |||||
</d:prop> | |||||
</d:propfind> | |||||
EOF; | |||||
$response = $this->client->request('PROPFIND', '/iRony/', ['body' => $body]); | |||||
$this->assertEquals(207, $response->getStatusCode()); | |||||
$data = $response->getBody(); | |||||
$this->assertTrue(str_contains($data, '<d:href>/iRony/calendars/john@kolab.org/</d:href>')); | |||||
} | |||||
public function testDiscoverCalendars() | |||||
{ | |||||
$body = <<<EOF | |||||
<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/" xmlns:c="urn:ietf:params:xml:ns:caldav"> | |||||
<d:prop> | |||||
<d:resourcetype /> | |||||
<d:displayname /> | |||||
<cs:getctag /> | |||||
<c:supported-calendar-component-set /> | |||||
</d:prop> | |||||
</d:propfind> | |||||
EOF; | |||||
$response = $this->client->request('PROPFIND', '/iRony/calendars/john@kolab.org', [ | |||||
'headers' => [ | |||||
"Depth" => "infinity", | |||||
], | |||||
'body' => $body | |||||
]); | |||||
$this->assertEquals(207, $response->getStatusCode()); | |||||
$data = $response->getBody(); | |||||
$this->assertTrue(str_contains($data, '<d:href>/iRony/calendars/john@kolab.org/</d:href>')); | |||||
$doc = new \DOMDocument('1.0', 'UTF-8'); | |||||
$doc->loadXML($data); | |||||
$response = $doc->getElementsByTagName('response')->item(1); | |||||
$doc->getElementsByTagName('href')->item(0); | |||||
$this->assertEquals("d:href", $response->childNodes->item(0)->nodeName); | |||||
$href = $response->childNodes->item(0)->nodeValue; | |||||
return $href; | |||||
} | |||||
/** | |||||
* @depends testDiscoverCalendars | |||||
*/ | |||||
public function testPropfindCalendar($href) | |||||
{ | |||||
$body = <<<EOF | |||||
<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:current-user-privilege-set/> | |||||
<d:supported-report-set/> | |||||
<cs:getctag /> | |||||
<c:supported-calendar-component-set /> | |||||
</d:prop> | |||||
</d:propfind> | |||||
EOF; | |||||
$response = $this->client->request('PROPFIND', $href, [ | |||||
'headers' => [ | |||||
"Depth" => "0", | |||||
], | |||||
'body' => $body, | |||||
]); | |||||
$this->assertEquals(207, $response->getStatusCode()); | |||||
$data = $response->getBody(); | |||||
$this->assertTrue(str_contains($data, "<d:href>$href</d:href>")); | |||||
} | |||||
/** | |||||
* Thunderbird does this and relies on the WWW-Authenticate header response to | |||||
* start sending authenticated requests. | |||||
* | |||||
* @depends testDiscoverCalendars | |||||
*/ | |||||
public function testPropfindCalendarWithoutAuth($href) | |||||
{ | |||||
$body = <<<EOF | |||||
<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:current-user-privilege-set/> | |||||
<d:supported-report-set/> | |||||
<cs:getctag /> | |||||
<c:supported-calendar-component-set /> | |||||
</d:prop> | |||||
</d:propfind> | |||||
EOF; | |||||
$response = $this->client->request('PROPFIND', $href, [ | |||||
'headers' => [ | |||||
"Depth" => "0", | |||||
], | |||||
'body' => $body, | |||||
'auth' => [] | |||||
]); | |||||
$this->assertEquals(401, $response->getStatusCode()); | |||||
$this->assertTrue(str_contains($response->getHeader('WWW-Authenticate')[0], 'Basic realm=')); | |||||
$data = $response->getBody(); | |||||
$this->assertTrue(str_contains($data, "<s:exception>Sabre\DAV\Exception\NotAuthenticated</s:exception>")); | |||||
} | |||||
/** | |||||
* Required for MacOS autoconfig | |||||
*/ | |||||
public function testOptions() | |||||
{ | |||||
$body = <<<EOF | |||||
<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/" xmlns:c="urn:ietf:params:xml:ns:caldav"> | |||||
<d:prop> | |||||
<d:resourcetype /> | |||||
<d:displayname /> | |||||
<cs:getctag /> | |||||
<c:supported-calendar-component-set /> | |||||
</d:prop> | |||||
</d:propfind> | |||||
EOF; | |||||
$response = $this->client->request('OPTIONS', '/iRony/principals/john@kolab.org/', ['body' => $body]); | |||||
$this->assertEquals(200, $response->getStatusCode()); | |||||
$this->assertTrue(str_contains($response->getHeader('Allow')[0], 'PROPFIND')); | |||||
} | |||||
} |
Just use $this->deleteTestUser($this->user->email).