Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2021-08-04 18:07:21 +0300
committerAnna Larch <anna@nextcloud.com>2021-09-22 17:12:11 +0300
commitce1b302b260994072e80019d0225ff9aa60f0643 (patch)
tree9cfed550a60ab42fb02e1758446b542afca7578c /tests
parent77d7bceeaaf6b2fc0d8f53d5e48ae856a789351f (diff)
Add parent domain to imap/smtp check
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Service/Autoconfig/ImapServerDetectorTest.php12
-rw-r--r--tests/Unit/Service/Autoconfig/MxRecordTest.php24
-rw-r--r--tests/Unit/Service/Autoconfig/SmtpServerDetectorTest.php18
3 files changed, 45 insertions, 9 deletions
diff --git a/tests/Unit/Service/Autoconfig/ImapServerDetectorTest.php b/tests/Unit/Service/Autoconfig/ImapServerDetectorTest.php
index 364812228..90b58434c 100644
--- a/tests/Unit/Service/Autoconfig/ImapServerDetectorTest.php
+++ b/tests/Unit/Service/Autoconfig/ImapServerDetectorTest.php
@@ -55,10 +55,14 @@ class ImapServerDetectorTest extends TestCase {
$this->mxRecord->expects($this->once())
->method('query')
->with($this->equalTo('domain.tld'))
- ->willReturn(['mx.domain.tld']);
+ ->willReturn(['domain.tld']);
+ $this->mxRecord->expects($this->once())
+ ->method('getSanitizedRecords')
+ ->with(['domain.tld'])
+ ->willReturn(['domain.tld']);
$this->imapConnectivityTester->expects($this->once())
->method('test')
- ->with($this->equalTo($email), $this->equalTo('mx.domain.tld'), $this->equalTo(['user', 'user@domain.tld']))
+ ->with($this->equalTo($email), $this->equalTo('domain.tld'), $this->equalTo(['user', 'user@domain.tld']))
->willReturn($this->createMock(MailAccount::class));
$account = $this->detector->detect($email, $password, $name);
@@ -75,6 +79,8 @@ class ImapServerDetectorTest extends TestCase {
->method('query')
->with($this->equalTo('domain.tld'))
->willReturn(false);
+ $this->mxRecord->expects($this->never())
+ ->method('getSanitizedRecords');
$this->imapConnectivityTester->expects($this->once())
->method('test')
->with($this->equalTo($email), $this->equalTo('domain.tld'), $this->equalTo(['user', 'user@domain.tld']))
@@ -94,6 +100,8 @@ class ImapServerDetectorTest extends TestCase {
->method('query')
->with($this->equalTo('domain.tld'))
->willReturn(false);
+ $this->mxRecord->expects($this->never())
+ ->method('getSanitizedRecords');
$this->imapConnectivityTester->expects($this->once())
->method('test')
->with($this->equalTo($email), $this->equalTo('domain.tld'), $this->equalTo(['user', 'user@domain.tld']))
diff --git a/tests/Unit/Service/Autoconfig/MxRecordTest.php b/tests/Unit/Service/Autoconfig/MxRecordTest.php
index 25fac14b5..bde19d81b 100644
--- a/tests/Unit/Service/Autoconfig/MxRecordTest.php
+++ b/tests/Unit/Service/Autoconfig/MxRecordTest.php
@@ -40,16 +40,36 @@ class MxRecordTest extends TestCase {
$this->record = new MxRecord($logger);
}
- public function testQuery() {
+ public function testQuery(): void {
$records = $this->record->query('nextcloud.com');
$this->assertIsArray($records);
$this->assertNotEmpty($records);
}
- public function testQueryNoRecord() {
+ public function testQueryNoRecord(): void {
$records = $this->record->query('example.com');
$this->assertFalse($records);
}
+
+ public function testGetSanitizedRecords(): void {
+ $records = ['mx.google.com',
+ 'testing.google.com',
+ 'try.again.de',
+ 'eins.zwei.drei.de'
+ ];
+
+ $mxRecords = $this->record->getSanitizedRecords($records);
+ $this->assertContains('google.com', $mxRecords);
+ $this->assertContains('again.de', $mxRecords);
+ $this->assertContains('mx.google.com', $mxRecords);
+ $this->assertContains('testing.google.com', $mxRecords);
+ $this->assertContains('try.again.de', $mxRecords);
+ $this->assertContains('drei.de', $mxRecords);
+ $this->assertContains('eins.zwei.drei.de', $mxRecords);
+
+ $this->assertNotContains('', $mxRecords);
+ $this->assertNotContains('gaga.uh.lala', $mxRecords);
+ }
}
diff --git a/tests/Unit/Service/Autoconfig/SmtpServerDetectorTest.php b/tests/Unit/Service/Autoconfig/SmtpServerDetectorTest.php
index 8177333f4..172ed866f 100644
--- a/tests/Unit/Service/Autoconfig/SmtpServerDetectorTest.php
+++ b/tests/Unit/Service/Autoconfig/SmtpServerDetectorTest.php
@@ -70,11 +70,15 @@ class SmtpServerDetectorTest extends TestCase {
$this->mxRecord->expects($this->once())
->method('query')
->with($this->equalTo('domain.tld'))
- ->willReturn(['mx.domain.tld']);
- $this->smtpConnectivityTester->expects($this->once())
- ->method('test')
- ->with($this->equalTo($account), $this->equalTo('mx.domain.tld'), $this->equalTo(['user', 'user@domain.tld']))
- ->willReturn(true);
+ ->willReturn(['domain.tld']);
+ $this->mxRecord->expects($this->once())
+ ->method('getSanitizedRecords')
+ ->with(['domain.tld'])
+ ->willReturn(['domain.tld']);
+ $this->smtpConnectivityTester
+ ->method('test')
+ ->with($this->equalTo($account), $this->equalTo('domain.tld'), $this->equalTo(['user', 'user@domain.tld']))
+ ->willReturn(true);
$result = $this->detector->detect($account, $email, $password);
@@ -92,6 +96,8 @@ class SmtpServerDetectorTest extends TestCase {
->method('query')
->with($this->equalTo('domain.tld'))
->willReturn(false);
+ $this->mxRecord->expects($this->never())
+ ->method('getSanitizedRecords');
$this->smtpConnectivityTester->expects($this->once())
->method('test')
->with($this->equalTo($account), $this->equalTo('domain.tld'), $this->equalTo(['user', 'user@domain.tld']))
@@ -113,6 +119,8 @@ class SmtpServerDetectorTest extends TestCase {
->method('query')
->with($this->equalTo('domain.tld'))
->willReturn(false);
+ $this->mxRecord->expects($this->never())
+ ->method('getSanitizedRecords');
$this->smtpConnectivityTester->expects($this->once())
->method('test')
->with($this->equalTo($account), $this->equalTo('domain.tld'), $this->equalTo(['user', 'user@domain.tld']))