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:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-02-03 16:51:51 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-02-03 22:24:27 +0300
commit6d2d36a1982f851aead5acb7a861601e7881ccae (patch)
treecff597c6126f2e6d0fcff1be88d29f98ca5399cb /tests
parent70962a95ac6bf61079976c13380d809ef754ef6a (diff)
Detect missing mailbox cache and block access to messages
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Controller/MessagesControllerTest.php6
-rw-r--r--tests/Unit/Service/MailSearchTest.php45
2 files changed, 45 insertions, 6 deletions
diff --git a/tests/Unit/Controller/MessagesControllerTest.php b/tests/Unit/Controller/MessagesControllerTest.php
index 0b215c557..1178a03c4 100644
--- a/tests/Unit/Controller/MessagesControllerTest.php
+++ b/tests/Unit/Controller/MessagesControllerTest.php
@@ -38,7 +38,6 @@ use OCA\Mail\Model\Message;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\ItineraryService;
use OCA\Mail\Service\MailManager;
-use OCA\Mail\Service\SyncService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\ContentSecurityPolicy;
@@ -72,9 +71,6 @@ class MessagesControllerTest extends TestCase {
/** @var ItineraryService|MockObject */
private $itineraryService;
- /** @var SyncService|MockObject */
- private $syncService;
-
/** @var string */
private $userId;
@@ -120,7 +116,6 @@ class MessagesControllerTest extends TestCase {
$this->mailManager = $this->createMock(IMailManager::class);
$this->mailSearch = $this->createMock(IMailSearch::class);
$this->itineraryService = $this->createMock(ItineraryService::class);
- $this->syncService = $this->createMock(SyncService::class);
$this->userId = 'john';
$this->userFolder = $this->createMock(Folder::class);
$this->request = $this->createMock(Request::class);
@@ -145,7 +140,6 @@ class MessagesControllerTest extends TestCase {
$this->mailManager,
$this->mailSearch,
$this->itineraryService,
- $this->syncService,
$this->userId,
$this->userFolder,
$this->logger,
diff --git a/tests/Unit/Service/MailSearchTest.php b/tests/Unit/Service/MailSearchTest.php
index 2b5006ef4..410ef372d 100644
--- a/tests/Unit/Service/MailSearchTest.php
+++ b/tests/Unit/Service/MailSearchTest.php
@@ -27,8 +27,11 @@ use ChristophWurst\Nextcloud\Testing\TestCase;
use Horde_Imap_Client_Fetch_Results;
use Horde_Imap_Client_Socket;
use OCA\Mail\Account;
+use OCA\Mail\Db\Mailbox;
use OCA\Mail\Db\MailboxMapper;
use OCA\Mail\Db\MessageMapper;
+use OCA\Mail\Exception\MailboxLockedException;
+use OCA\Mail\Exception\MailboxNotCachedException;
use OCA\Mail\IMAP\IMAPClientFactory;
use OCA\Mail\IMAP\Search\Provider;
use OCA\Mail\Service\Search\FilterStringParser;
@@ -74,8 +77,50 @@ class MailSearchTest extends TestCase {
);
}
+ public function testFindMessagesNotCached() {
+ $account = $this->createMock(Account::class);
+ $mailbox = new Mailbox();
+ $mailbox->setSyncNewToken('abc');
+ $mailbox->setSyncChangedToken('def');
+ $this->mailboxMapper->expects($this->once())
+ ->method('find')
+ ->willReturn($mailbox);
+ $this->expectException(MailboxNotCachedException::class);
+
+ $messages = $this->search->findMessages(
+ $account,
+ 'INBOX',
+ null,
+ null
+ );
+ }
+
+ public function testFindMessagesLocked() {
+ $account = $this->createMock(Account::class);
+ $mailbox = new Mailbox();
+ $mailbox->setSyncNewLock(123);
+ $this->mailboxMapper->expects($this->once())
+ ->method('find')
+ ->willReturn($mailbox);
+ $this->expectException(MailboxLockedException::class);
+
+ $messages = $this->search->findMessages(
+ $account,
+ 'INBOX',
+ null,
+ null
+ );
+ }
+
public function testNoFindMessages() {
$account = $this->createMock(Account::class);
+ $mailbox = new Mailbox();
+ $mailbox->setSyncNewToken('abc');
+ $mailbox->setSyncChangedToken('def');
+ $mailbox->setSyncVanishedToken('ghi');
+ $this->mailboxMapper->expects($this->once())
+ ->method('find')
+ ->willReturn($mailbox);
$messages = $this->search->findMessages(
$account,