-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove email config `mail_smtpauthtype` - this is now auto detected fix: Mailer::send will always thrown an exception in case of errors during delivery
- Loading branch information
1 parent
73c370c
commit 9ea1926
Showing
18 changed files
with
545 additions
and
800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,124 +22,78 @@ | |
|
||
namespace OCA\DAV\Tests\unit\CalDAV\Schedule; | ||
|
||
use Exception; | ||
use OC\Mail\Mailer; | ||
use OCA\DAV\CalDAV\Schedule\IMipPlugin; | ||
use OCP\ILogger; | ||
use OCP\IRequest; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use Sabre\VObject\Component\VCalendar; | ||
use Sabre\VObject\ITip\Message; | ||
use Symfony\Component\Mime\Email; | ||
use Test\TestCase; | ||
use OC\Log; | ||
|
||
class IMipPluginTest extends TestCase { | ||
public function testDelivery() { | ||
$mailMessage = new \OC\Mail\Message(new \Swift_Message()); | ||
/** @var Mailer | \PHPUnit\Framework\MockObject\MockObject $mailer */ | ||
$mailer = $this->createMock(Mailer::class); | ||
$mailer->method('createMessage')->willReturn($mailMessage); | ||
$mailer->expects($this->once())->method('send'); | ||
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject $logger */ | ||
$logger = $this->createMock(Log::class); | ||
/** @var IRequest| \PHPUnit\Framework\MockObject\MockObject $request */ | ||
private \OC\Mail\Message $mailMessage; | ||
/** | ||
* @var Mailer|MockObject | ||
*/ | ||
private $mailer; | ||
private IMipPlugin $plugin; | ||
/** @var ILogger|MockObject */ | ||
private $logger; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->mailMessage = new \OC\Mail\Message(new Email()); | ||
$this->mailer = $this->createMock(Mailer::class); | ||
$this->mailer->method('createMessage')->willReturn($this->mailMessage); | ||
|
||
$this->logger = $this->createMock(Log::class); | ||
/** @var IRequest| MockObject $request */ | ||
$request = $this->createMock(IRequest::class); | ||
|
||
$plugin = new IMipPlugin($mailer, $logger, $request); | ||
$message = new Message(); | ||
$message->method = 'REQUEST'; | ||
$message->message = new VCalendar(); | ||
$message->message->add('VEVENT', [ | ||
'UID' => $message->uid, | ||
'SEQUENCE' => $message->sequence, | ||
'SUMMARY' => 'Fellowship meeting', | ||
]); | ||
$message->sender = 'mailto:[email protected]'; | ||
$message->recipient = 'mailto:[email protected]'; | ||
$this->plugin = new IMipPlugin($this->mailer, $this->logger, $request); | ||
} | ||
|
||
public function testDelivery(): void { | ||
$this->mailer->expects($this->once())->method('send'); | ||
|
||
$message = $this->buildIMIPMessage('REQUEST'); | ||
|
||
$plugin->schedule($message); | ||
$this->plugin->schedule($message); | ||
$this->assertEquals('1.1', $message->getScheduleStatus()); | ||
$this->assertEquals('Fellowship meeting', $mailMessage->getSubject()); | ||
$this->assertEquals(['[email protected]' => null], $mailMessage->getTo()); | ||
$this->assertEquals(['[email protected]' => null], $mailMessage->getReplyTo()); | ||
$this->assertEquals('text/calendar; charset=UTF-8; method=REQUEST', $mailMessage->getSwiftMessage()->getContentType()); | ||
$this->assertEquals('Fellowship meeting', $this->mailMessage->getSubject()); | ||
$this->assertEquals(['[email protected]' => null], $this->mailMessage->getTo()); | ||
$this->assertEquals(['[email protected]' => null], $this->mailMessage->getReplyTo()); | ||
$this->assertStringContainsString('text/calendar; charset=UTF-8; method=REQUEST', $this->mailMessage->getMessage()->getBody()->bodyToString()); | ||
} | ||
|
||
public function testFailedDeliveryWithException() { | ||
$mailMessage = new \OC\Mail\Message(new \Swift_Message()); | ||
/** @var Mailer | \PHPUnit\Framework\MockObject\MockObject $mailer */ | ||
$mailer = $this->createMock(Mailer::class); | ||
$mailer->method('createMessage')->willReturn($mailMessage); | ||
$mailer->method('send')->willThrowException(new \Exception()); | ||
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject $logger */ | ||
$logger = $this->createMock(Log::class); | ||
/** @var IRequest| \PHPUnit\Framework\MockObject\MockObject $request */ | ||
$request = $this->createMock(IRequest::class); | ||
public function testFailedDeliveryWithException(): void { | ||
$ex = new Exception(); | ||
$this->mailer->method('send')->willThrowException($ex); | ||
$this->logger->expects(self::once())->method('logException')->with($ex, ['app' => 'dav']); | ||
|
||
$plugin = new IMipPlugin($mailer, $logger, $request); | ||
$message = new Message(); | ||
$message->method = 'REQUEST'; | ||
$message->message = new VCalendar(); | ||
$message->message->add('VEVENT', [ | ||
'UID' => $message->uid, | ||
'SEQUENCE' => $message->sequence, | ||
'SUMMARY' => 'Fellowship meeting', | ||
]); | ||
$message->sender = 'mailto:[email protected]'; | ||
$message->recipient = 'mailto:[email protected]'; | ||
$message = $this->buildIMIPMessage('REQUEST'); | ||
|
||
$plugin->schedule($message); | ||
$this->assertEquals('5.0', $message->getScheduleStatus()); | ||
$this->assertEquals('Fellowship meeting', $mailMessage->getSubject()); | ||
$this->assertEquals(['[email protected]' => null], $mailMessage->getTo()); | ||
$this->assertEquals(['[email protected]' => null], $mailMessage->getReplyTo()); | ||
$this->assertEquals('text/calendar; charset=UTF-8; method=REQUEST', $mailMessage->getSwiftMessage()->getContentType()); | ||
$this->plugin->schedule($message); | ||
$this->assertIMipState($message, '5.0', 'REQUEST', 'Fellowship meeting'); | ||
} | ||
|
||
public function testFailedDelivery() { | ||
$mailMessage = new \OC\Mail\Message(new \Swift_Message()); | ||
/** @var Mailer | \PHPUnit\Framework\MockObject\MockObject $mailer */ | ||
$mailer = $this->createMock(Mailer::class); | ||
$mailer->method('createMessage')->willReturn($mailMessage); | ||
$mailer->method('send')->willReturn(['[email protected]']); | ||
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject $logger */ | ||
$logger = $this->createMock(Log::class); | ||
$logger->expects(self::once())->method('error')->with('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => '[email protected]']); | ||
/** @var IRequest| \PHPUnit\Framework\MockObject\MockObject $request */ | ||
$request = $this->createMock(IRequest::class); | ||
public function testDeliveryOfCancel(): void { | ||
$this->mailer->expects($this->once())->method('send'); | ||
|
||
$plugin = new IMipPlugin($mailer, $logger, $request); | ||
$message = new Message(); | ||
$message->method = 'REQUEST'; | ||
$message->message = new VCalendar(); | ||
$message->message->add('VEVENT', [ | ||
'UID' => $message->uid, | ||
'SEQUENCE' => $message->sequence, | ||
'SUMMARY' => 'Fellowship meeting', | ||
]); | ||
$message->sender = 'mailto:[email protected]'; | ||
$message->recipient = 'mailto:[email protected]'; | ||
$message = $this->buildIMIPMessage('CANCEL'); | ||
|
||
$plugin->schedule($message); | ||
$this->assertEquals('5.0', $message->getScheduleStatus()); | ||
$this->assertEquals('Fellowship meeting', $mailMessage->getSubject()); | ||
$this->assertEquals(['[email protected]' => null], $mailMessage->getTo()); | ||
$this->assertEquals(['[email protected]' => null], $mailMessage->getReplyTo()); | ||
$this->assertEquals('text/calendar; charset=UTF-8; method=REQUEST', $mailMessage->getSwiftMessage()->getContentType()); | ||
$this->plugin->schedule($message); | ||
$this->assertIMipState($message, '1.1', 'CANCEL', 'Cancelled: Fellowship meeting'); | ||
} | ||
|
||
public function testDeliveryOfCancel() { | ||
$mailMessage = new \OC\Mail\Message(new \Swift_Message()); | ||
/** @var Mailer | \PHPUnit\Framework\MockObject\MockObject $mailer */ | ||
$mailer = $this->createMock(Mailer::class); | ||
$mailer->method('createMessage')->willReturn($mailMessage); | ||
$mailer->expects($this->once())->method('send'); | ||
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject $logger */ | ||
$logger = $this->createMock(Log::class); | ||
/** @var IRequest| \PHPUnit\Framework\MockObject\MockObject $request */ | ||
$request = $this->createMock(IRequest::class); | ||
|
||
$plugin = new IMipPlugin($mailer, $logger, $request); | ||
private function buildIMIPMessage(string $method): Message { | ||
$message = new Message(); | ||
$message->method = 'CANCEL'; | ||
$message->method = $method; | ||
$message->message = new VCalendar(); | ||
$message->message->add('VEVENT', [ | ||
'UID' => $message->uid, | ||
|
@@ -148,13 +102,14 @@ public function testDeliveryOfCancel() { | |
]); | ||
$message->sender = 'mailto:[email protected]'; | ||
$message->recipient = 'mailto:[email protected]'; | ||
return $message; | ||
} | ||
|
||
$plugin->schedule($message); | ||
$this->assertEquals('1.1', $message->getScheduleStatus()); | ||
$this->assertEquals('Cancelled: Fellowship meeting', $mailMessage->getSubject()); | ||
$this->assertEquals(['[email protected]' => null], $mailMessage->getTo()); | ||
$this->assertEquals(['[email protected]' => null], $mailMessage->getReplyTo()); | ||
$this->assertEquals('text/calendar; charset=UTF-8; method=CANCEL', $mailMessage->getSwiftMessage()->getContentType()); | ||
$this->assertEquals('CANCELLED', $message->message->VEVENT->STATUS->getValue()); | ||
private function assertIMipState(Message $message, string $scheduleStatus, string $method, string $mailSubject): void { | ||
$this->assertEquals($scheduleStatus, $message->getScheduleStatus()); | ||
$this->assertEquals($mailSubject, $this->mailMessage->getSubject()); | ||
$this->assertEquals(['[email protected]' => null], $this->mailMessage->getTo()); | ||
$this->assertEquals(['[email protected]' => null], $this->mailMessage->getReplyTo()); | ||
$this->assertStringContainsString("text/calendar; charset=UTF-8; method=$method", $this->mailMessage->getMessage()->getBody()->bodyToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.