diff --git a/src/tests/Infrastructure/ActivesyncTest.php b/src/tests/Infrastructure/ActivesyncTest.php index 6eb67b73..6bac7d3a 100644 --- a/src/tests/Infrastructure/ActivesyncTest.php +++ b/src/tests/Infrastructure/ActivesyncTest.php @@ -1,184 +1,204 @@ loadXML($xml); $encoder->encode($dom); rewind($outputStream); return stream_get_contents($outputStream); } private static function fromWbxml($binary) { $stream = fopen('php://memory', 'r+'); fwrite($stream, $binary); rewind($stream); $decoder = new \Syncroton_Wbxml_Decoder($stream); return $decoder->decode(); } /** * {@inheritDoc} */ public function setUp(): void { parent::setUp(); - if (!self::$user) { - self::$user = $this->getTestUser('activesynctest@kolab.org', ['password' => 'simple123'], true); - } if (!self::$deviceId) { // By always creating a new device we force syncroton to initialize. // Otherwise we work against uninitialized metadata (subscription states), // because the account has been removed, but syncroton doesn't reinitalize the metadata for known devices. self::$deviceId = (string) Str::uuid(); } + + $deviceId = self::$deviceId; + \config(['imap.default_folders' => [ + 'Drafts' => [ + 'metadata' => [ + '/private/vendor/kolab/folder-type' => 'mail.drafts', + '/private/vendor/kolab/activesync' => "{\"FOLDER\":{\"{$deviceId}\":{\"S\":1}}}" + ], + ], + 'Calendar' => [ + 'metadata' => [ + '/private/vendor/kolab/folder-type' => 'event.default', + '/private/vendor/kolab/activesync' => "{\"FOLDER\":{\"{$deviceId}\":{\"S\":1}}}" + ], + ], + 'Contacts' => [ + 'metadata' => [ + '/private/vendor/kolab/folder-type' => 'contact.default', + '/private/vendor/kolab/activesync' => "{\"FOLDER\":{\"{$deviceId}\":{\"S\":1}}}" + ], + ], + ]]); + + if (!self::$user) { + self::$user = $this->getTestUser('activesynctest@kolab.org', ['password' => 'simple123'], true); + } if (!self::$client) { self::$client = new \GuzzleHttp\Client([ 'http_errors' => false, // No exceptions 'base_uri' => \config("services.activesync.uri"), 'verify' => false, 'auth' => [self::$user->email, 'simple123'], 'connect_timeout' => 10, 'timeout' => 10, 'headers' => [ "Content-Type" => "application/xml; charset=utf-8", "Depth" => "1", ] ]); } } public function testOptions() { $response = self::$client->request('OPTIONS', ''); $this->assertEquals(200, $response->getStatusCode()); $this->assertStringContainsString('14', $response->getHeader('MS-Server-ActiveSync')[0]); $this->assertStringContainsString('14.1', $response->getHeader('MS-ASProtocolVersions')[0]); $this->assertStringContainsString('FolderSync', $response->getHeader('MS-ASProtocolCommands')[0]); } public function testList() { $user = self::$user; $deviceId = self::$deviceId; $request = << 0 EOF; $body = self::toWbxml($request); $response = self::$client->request( 'POST', "?Cmd=FolderSync&User={$user->email}&DeviceId={$deviceId}&DeviceType=iphone", [ 'headers' => [ "Content-Type" => "application/vnd.ms-sync.wbxml", 'MS-ASProtocolVersion' => "14.0" ], 'body' => $body ] ); $this->assertEquals(200, $response->getStatusCode()); $dom = self::fromWbxml($response->getBody()); $xml = $dom->saveXML(); $this->assertStringContainsString('INBOX', $xml); // The hash is based on the name, so it's always the same $inboxId = '38b950ebd62cd9a66929c89615d0fc04'; $this->assertStringContainsString($inboxId, $xml); - //TODO for this to work we need to create the default folders in IMAP::createUser - // $this->assertStringContainsString('Drafts', $result); - // $this->assertStringContainsString('Sent', $result); - // $this->assertStringContainsString('Trash', $result); - // $this->assertStringContainsString('Calendar', $result); - // $this->assertStringContainsString('Contacts', $result); + $this->assertStringContainsString('Drafts', $xml); + $this->assertStringContainsString('Calendar', $xml); + $this->assertStringContainsString('Contacts', $xml); // Find the inbox for the next step // $collectionIds = $dom->getElementsByTagName('ServerId'); // $inboxId = $collectionIds[0]->nodeValue; return $inboxId; } /** * @depends testList */ public function testInitialSync($inboxId) { $user = self::$user; $deviceId = self::$deviceId; $request = << 0 {$inboxId} 0 0 512 0 1 1 16 EOF; $body = self::toWbxml($request); $response = self::$client->request( 'POST', "?Cmd=Sync&User={$user->email}&DeviceId={$deviceId}&DeviceType=iphone", [ 'headers' => [ "Content-Type" => "application/vnd.ms-sync.wbxml", 'MS-ASProtocolVersion' => "14.0" ], 'body' => $body ] ); $this->assertEquals(200, $response->getStatusCode()); $dom = self::fromWbxml($response->getBody()); $status = $dom->getElementsByTagName('Status'); $this->assertEquals("1", $status[0]->nodeValue); $collections = $dom->getElementsByTagName('Collection'); $this->assertEquals(1, $collections->length); $collection = $collections->item(0); $this->assertEquals("Class", $collection->childNodes->item(0)->nodeName); $this->assertEquals("Email", $collection->childNodes->item(0)->nodeValue); $this->assertEquals("SyncKey", $collection->childNodes->item(1)->nodeName); $this->assertEquals("1", $collection->childNodes->item(1)->nodeValue); $this->assertEquals("Status", $collection->childNodes->item(3)->nodeName); $this->assertEquals("1", $collection->childNodes->item(3)->nodeValue); } /** * @doesNotPerformAssertions */ public function testCleanup(): void { $this->deleteTestUser(self::$user->email); } }