diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2021-02-26 18:45:36 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-26 18:45:36 +0300 |
commit | 06842c1ad4fc1b73218d7a49b72343ce6ac92b48 (patch) | |
tree | 5f218940949e1b00a56809f59c18c6121dcc3e49 /tests/Integration | |
parent | 164d7be1eefff8d1ea2e12c62b28311b7bfd083b (diff) | |
parent | 82ab9d00075bf00d611e819ef9c3a6cc72c12c26 (diff) |
Merge pull request #4472 from nextcloud/enh/sievev1.9.0-alpha2
Sieve
Diffstat (limited to 'tests/Integration')
-rw-r--r-- | tests/Integration/Db/MailAccountTest.php | 2 | ||||
-rw-r--r-- | tests/Integration/Sieve/SieveClientFactoryTest.php | 117 | ||||
-rw-r--r-- | tests/Integration/Sieve/SieveLoggerTest.php | 46 |
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'); + } +} |