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
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2021-01-27 18:54:37 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-02-26 18:36:46 +0300
commit82ab9d00075bf00d611e819ef9c3a6cc72c12c26 (patch)
treed59f99e49ebfe0be9c389ae8aee7311c3d9040d8 /tests/Integration
parent685580fff2859112bc1dd37b3823f0ada0950811 (diff)
Add Sieve support
* Expose managesieve port * Add sieve client factory * Add support for sieve to provisioning * Refactor test connectivity logic and add sieve. * Add support for sieve to provisioning * Add sieve to account form * Add debug logger for ManageSieve * Add api to get and update active script * Add error for managesieve exception * Add text editor to update existing script Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests/Integration')
-rw-r--r--tests/Integration/Db/MailAccountTest.php2
-rw-r--r--tests/Integration/Sieve/SieveClientFactoryTest.php117
-rw-r--r--tests/Integration/Sieve/SieveLoggerTest.php46
3 files changed, 165 insertions, 0 deletions
diff --git a/tests/Integration/Db/MailAccountTest.php b/tests/Integration/Db/MailAccountTest.php
index 8bf2af949..fd2ad11e3 100644
--- a/tests/Integration/Db/MailAccountTest.php
+++ b/tests/Integration/Db/MailAccountTest.php
@@ -69,6 +69,7 @@ class MailAccountTest extends TestCase {
'draftsMailboxId' => null,
'sentMailboxId' => null,
'trashMailboxId' => null,
+ 'sieveEnabled' => false,
], $a->toJson());
}
@@ -95,6 +96,7 @@ class MailAccountTest extends TestCase {
'draftsMailboxId' => null,
'sentMailboxId' => null,
'trashMailboxId' => null,
+ 'sieveEnabled' => false,
];
$a = new MailAccount($expected);
// TODO: fix inconsistency
diff --git a/tests/Integration/Sieve/SieveClientFactoryTest.php b/tests/Integration/Sieve/SieveClientFactoryTest.php
new file mode 100644
index 000000000..47964c32c
--- /dev/null
+++ b/tests/Integration/Sieve/SieveClientFactoryTest.php
@@ -0,0 +1,117 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Daniel Kesselberg <mail@danielkesselberg.de>
+ *
+ * Mail
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Mail\Tests\Integration\Sieve;
+
+use ChristophWurst\Nextcloud\Testing\TestCase;
+use Horde\ManageSieve;
+use OC;
+use OCA\Mail\Account;
+use OCA\Mail\Db\MailAccount;
+use OCA\Mail\Sieve\SieveClientFactory;
+use OCP\IConfig;
+use OCP\Security\ICrypto;
+use PHPUnit\Framework\MockObject\MockObject;
+
+class SieveClientFactoryTest extends TestCase {
+
+ /** @var ICrypto|MockObject */
+ private $crypto;
+
+ /** @var IConfig|MockObject */
+ private $config;
+
+ /** @var SieveClientFactory */
+ private $factory;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->crypto = $this->createMock(ICrypto::class);
+ $this->config = $this->createMock(IConfig::class);
+
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(static function ($key, $default) {
+ if ($key === 'app.mail.sieve.timeout') {
+ return 5;
+ }
+ if ($key === 'debug') {
+ return false;
+ }
+ return null;
+ });
+
+ $this->config->method('getSystemValueBool')
+ ->with('app.mail.verify-tls-peer', true)
+ ->willReturn(false);
+
+ $this->factory = new SieveClientFactory($this->crypto, $this->config);
+ }
+
+ /**
+ * @return Account
+ */
+ private function getTestAccount() {
+ $mailAccount = new MailAccount();
+ $mailAccount->setId(123);
+ $mailAccount->setEmail('user@domain.tld');
+ $mailAccount->setInboundHost('127.0.0.1');
+ $mailAccount->setInboundPort(993);
+ $mailAccount->setInboundSslMode('ssl');
+ $mailAccount->setInboundUser('user@domain.tld');
+ $mailAccount->setInboundPassword(OC::$server->get(ICrypto::class)->encrypt('mypassword'));
+ $mailAccount->setSieveHost('127.0.0.1');
+ $mailAccount->setSievePort(4190);
+ $mailAccount->setSieveSslMode('');
+ $mailAccount->setSieveUser('');
+ $mailAccount->setSievePassword('');
+ return new Account($mailAccount);
+ }
+
+ public function testClientConnectivity() {
+ $account = $this->getTestAccount();
+ $this->crypto->expects($this->once())
+ ->method('decrypt')
+ ->with($account->getMailAccount()->getInboundPassword())
+ ->willReturn('mypassword');
+
+ $client = $this->factory->getClient($account);
+ $this->assertInstanceOf(ManageSieve::class, $client);
+ }
+
+ public function testClientInstallScript() {
+ $account = $this->getTestAccount();
+ $this->crypto->expects($this->once())
+ ->method('decrypt')
+ ->with($account->getMailAccount()->getInboundPassword())
+ ->willReturn('mypassword');
+
+ $client = $this->factory->getClient($account);
+
+ $client->installScript('test', '#test');
+ $this->assertCount(1, $client->listScripts());
+
+ $client->removeScript('test');
+ $this->assertCount(0, $client->listScripts());
+ }
+}
diff --git a/tests/Integration/Sieve/SieveLoggerTest.php b/tests/Integration/Sieve/SieveLoggerTest.php
new file mode 100644
index 000000000..fbb526a76
--- /dev/null
+++ b/tests/Integration/Sieve/SieveLoggerTest.php
@@ -0,0 +1,46 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Daniel Kesselberg <mail@danielkesselberg.de>
+ *
+ * Mail
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Mail\Tests\Integration\Sieve;
+
+use ChristophWurst\Nextcloud\Testing\TestCase;
+use OCA\Mail\Sieve\SieveLogger;
+
+class SieveLoggerTest extends TestCase {
+ public function testOpenInvalidFile(): void {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectDeprecationMessage('Unable to use "/root/horde_sieve.log" as log file for sieve.');
+ new SieveLogger('/root/horde_sieve.log');
+ }
+
+ public function testWriteLog(): void {
+ $logFile = sys_get_temp_dir() . '/horde_sieve.log';
+ @unlink($logFile);
+
+ $logger = new SieveLogger($logFile);
+ $logger->debug('Test');
+ unset($logger);
+
+ $this->assertStringEqualsFile($logFile, 'Test');
+ }
+}