Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1416 from owncloud/test-isbdb-xml-config
Browse files Browse the repository at this point in the history
test IspDb with real xml data
  • Loading branch information
ChristophWurst committed Apr 21, 2016
2 parents 4d4ad3d + efd6f90 commit 59ae2ce
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 20 deletions.
8 changes: 5 additions & 3 deletions appinfo/application.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @author Christoph Wurst <[email protected]>
* @author Thomas Müller <[email protected]>
Expand All @@ -21,11 +22,12 @@

namespace OCA\Mail\AppInfo;

use \OCP\AppFramework\App;
use OCP\AppFramework\App;
use OCP\Util;

class Application extends App {

public function __construct (array $urlParams=array()) {
public function __construct(array $urlParams = []) {
parent::__construct('mail', $urlParams);

$container = $this->getContainer();
Expand All @@ -42,7 +44,7 @@ public function __construct (array $urlParams=array()) {
$container->registerParameter("userFolder", $container->getServer()->getUserFolder($user));
$container->registerParameter("testSmtp", $testSmtp);
$container->registerParameter("referrer", isset($_SERVER['HTTP_REFERER']) ? : null);
$container->registerParameter("hostname", \OCP\Util::getServerHostName());
$container->registerParameter("hostname", Util::getServerHostName());
}

}
24 changes: 18 additions & 6 deletions lib/service/autoconfig/ispdb.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @author Christoph Wurst <[email protected]>
*
Expand All @@ -17,19 +18,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Mail\Service\AutoConfig;

use Exception;
use OCA\Mail\Service\Logger;

class IspDb {

/** @var Logger */
private $logger;
private $urls = array(
'https://autoconfig.{DOMAIN}/mail/config-v1.1.xml',
'https://{DOMAIN}/.well-known/autoconfig/mail/config-v1.1.xml',
'https://autoconfig.thunderbird.net/v1.1/{DOMAIN}',
);

/** @var string[] */
public function getUrls() {
return [
'https://autoconfig.{DOMAIN}/mail/config-v1.1.xml',
'https://{DOMAIN}/.well-known/autoconfig/mail/config-v1.1.xml',
'https://autoconfig.thunderbird.net/v1.1/{DOMAIN}',
];
}

/**
* @param Logger $logger
* @param string[] $ispUrls
*/
public function __construct(Logger $logger) {
$this->logger = $logger;
}
Expand Down Expand Up @@ -84,7 +96,7 @@ public function query($domain, $tryMx = true) {
}

$provider = [];
foreach ($this->urls as $url) {
foreach ($this->getUrls() as $url) {
$url = str_replace("{DOMAIN}", $domain, $url);
$this->logger->debug("IsbDb: querying <$domain> via <$url>");

Expand Down
36 changes: 36 additions & 0 deletions tests/resources/autoconfig-freenet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<clientConfig version="1.1">
<emailProvider id="freenet.de">
<domain>freenet.de</domain>
<displayName>Freenet Mail</displayName>
<displayShortName>Freenet</displayShortName>
<incomingServer type="imap">
<hostname>mx.freenet.de</hostname>
<port>993</port>
<socketType>SSL</socketType>
<authentication>password-encrypted</authentication>
<username>%EMAILADDRESS%</username>
</incomingServer>
<incomingServer type="pop3">
<hostname>mx.freenet.de</hostname>
<port>995</port>
<socketType>SSL</socketType>
<authentication>password-cleartext</authentication>
<username>%EMAILADDRESS%</username>
</incomingServer>
<outgoingServer type="smtp">
<hostname>mx.freenet.de</hostname>
<port>587</port>
<socketType>STARTTLS</socketType>
<authentication>password-encrypted</authentication>
<username>%EMAILADDRESS%</username>
</outgoingServer>
<documentation url="http://email-hilfe.freenet.de/documents/Beitrag/15916/einstellungen-serverdaten-fuer-alle-e-mail-programme">
<descr lang="de">Allgemeine Beschreibung der Einstellungen</descr>
<descr lang="en">Generic settings page</descr>
</documentation>
<documentation url="http://email-hilfe.freenet.de/documents/Beitrag/15808/thunderbird-e-mail-empfang-versand-einrichten-ueber-imap">
<descr lang="de">TB 2.0 IMAP-Einstellungen</descr>
<descr lang="en">TB 2.0 IMAP settings</descr>
</documentation>
</emailProvider>
</clientConfig>
59 changes: 48 additions & 11 deletions tests/service/autoconfig/ispdbtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,24 @@
namespace OCA\Mail\Tests\Service\Autoconfig;

use OCA\Mail\Service\AutoConfig\IspDb;
use PHPUnit_Framework_TestCase;
use Test\TestCase;

class IspDbtest extends PHPUnit_Framework_TestCase {
class IspDbtest extends TestCase {

private $ispDb;
private $logger;

protected function setUp() {
parent::setUp();

$logger = $this->getMockBuilder('\OCA\Mail\Service\Logger')
$this->logger = $this->getMockBuilder('\OCA\Mail\Service\Logger')
->disableOriginalConstructor()
->getMock();
$this->ispDb = new IspDb($logger);
}

public function queryData() {
return [
['gmail.com'],
['outlook.com'],
['yahoo.de'],
['gmail.com'],
['outlook.com'],
];
}

Expand All @@ -50,12 +48,51 @@ public function queryData() {
*
* @param string $domain
*/
public function testQueryGmail($domain) {
$result = $this->ispDb->query($domain);

public function testQueryRealServers($domain) {
$ispDb = new IspDb($this->logger);
$result = $ispDb->query($domain);
$this->assertContainsIspData($result);
}

public function fakeAutoconfigData() {
return [
['freenet.de', true],
//['example.com', false], //should it fail?
];
}

/**
* @dataProvider fakeAutoconfigData
*/
public function testQueryFakeAutoconfig($domain, $shouldSucceed) {
$urls = [
dirname(__FILE__) . '/../../resources/autoconfig-freenet.xml',
];
$ispDb = $this->getIspDbMock($urls);

$result = $ispDb->query($domain);

if ($shouldSucceed) {
$this->assertContainsIspData($result);
} else {
$this->assertEmpty($result);
}
}

private function getIspDbMock($urls) {
$mock = $this->getMockBuilder('\OCA\Mail\Service\AutoConfig\IspDb')
->setMethods(['getUrls'])
->setConstructorArgs([$this->logger])
->getMock();
$mock->expects($this->once())
->method('getUrls')
->will($this->returnValue($urls));
return $mock;
}

/**
* @todo check actual values
*/
private function assertContainsIspData($data) {
$this->assertArrayHasKey('imap', $data);
$this->assertTrue(count($data['imap']) >= 1, 'no isp imap data returned');
Expand Down

0 comments on commit 59ae2ce

Please sign in to comment.