diff options
author | SebastianKrupinski <krupinskis05@gmail.com> | 2024-04-17 10:40:31 -0400 |
---|---|---|
committer | Sebastian Krupinski <165827823+SebastianKrupinski@users.noreply.github.com> | 2024-06-25 16:43:51 -0400 |
commit | d7eb509b267944f18ade6e2d57467539718a5027 (patch) | |
tree | 74c2022d88eb06e0fe270d21ab7ca4d1ed0a35ff /apps/dav | |
parent | f0182226d4986e00825f919eed9f20f0f0723e50 (diff) | |
download | nextcloud-server-d7eb509b267944f18ade6e2d57467539718a5027.tar.gz nextcloud-server-d7eb509b267944f18ade6e2d57467539718a5027.zip |
fix(caldav): when message is a reply compare the message sender not the recipient
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/CalDAV/Schedule/IMipService.php | 7 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php | 2 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php | 71 |
3 files changed, 77 insertions, 3 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipService.php b/apps/dav/lib/CalDAV/Schedule/IMipService.php index e71f97764f8..ec5e4f4d1ac 100644 --- a/apps/dav/lib/CalDAV/Schedule/IMipService.php +++ b/apps/dav/lib/CalDAV/Schedule/IMipService.php @@ -552,8 +552,11 @@ class IMipService { $vevent = $iTipMessage->message->VEVENT; $attendees = $vevent->select('ATTENDEE'); foreach ($attendees as $attendee) { - /** @var Property $attendee */ - if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) { + if ($iTipMessage->method === 'REPLY' && strcasecmp($attendee->getValue(), $iTipMessage->sender) === 0) { + /** @var Property $attendee */ + return $attendee; + } elseif (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) { + /** @var Property $attendee */ return $attendee; } } diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php index 433f3a87c59..eb6bd204bdd 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php @@ -88,7 +88,7 @@ class IMipPluginTest extends TestCase { $this->timeFactory->method('getTime')->willReturn(1496912528); // 2017-01-01 $this->config = $this->createMock(IConfig::class); - + $this->user = $this->createMock(IUser::class); /* $this->user->method('getUID'); diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php index d4f1dd66897..e4a9f1b75d0 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php @@ -18,6 +18,7 @@ use OCP\Security\ISecureRandom; use PHPUnit\Framework\MockObject\MockObject; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VEvent; +use Sabre\VObject\ITip\Message; use Sabre\VObject\Property\ICalendar\DateTime; use Test\TestCase; @@ -248,4 +249,74 @@ class IMipServiceTest extends TestCase { $occurrence = $this->service->getLastOccurrence($vCalendar); $this->assertEquals(1451606400, $occurrence); } + + public function testGetCurrentAttendeeRequest(): void { + // Construct ITip Message + $message = new Message(); + $message->method = 'REQUEST'; + $message->sequence = 1; + $message->sender = 'mailto:organizer@example.com'; + $message->senderName = 'The Organizer'; + $message->recipient = 'mailto:attendee@example.com'; + $message->recipientName = 'The Attendee'; + $message->significantChange = true; + $message->message = new VCalendar(); + $message->message->add('VEVENT', ['UID' => '82496785-1915-4604-a5ce-4e2091639c9a', 'SEQUENCE' => 1]); + $message->message->VEVENT->add('SUMMARY', 'Fellowship meeting'); + $message->message->VEVENT->add('DTSTART', (new \DateTime('NOW'))->modify('+1 hour')); + $message->message->VEVENT->add('DTEND', (new \DateTime('NOW'))->modify('+2 hour')); + $message->message->VEVENT->add('ORGANIZER', 'mailto:organizer@example.com', ['CN' => 'The Organizer']); + $message->message->VEVENT->add('ATTENDEE', 'mailto:attendee@example.com', ['CN' => 'The Attendee']); + // Test getCurrentAttendee + $result = $this->service->getCurrentAttendee($message); + // Evaluate Result + $this->assertEquals($message->message->VEVENT->ATTENDEE, $result); + } + + public function testGetCurrentAttendeeReply(): void { + // Construct ITip Message + $message = new Message(); + $message->method = 'REPLY'; + $message->sequence = 2; + $message->sender = 'mailto:attendee@example.com'; + $message->senderName = 'The Attendee'; + $message->recipient = 'mailto:organizer@example.com'; + $message->recipientName = 'The Organizer'; + $message->significantChange = true; + $message->message = new VCalendar(); + $message->message->add('METHOD', 'REPLY'); + $message->message->add('VEVENT', ['UID' => '82496785-1915-4604-a5ce-4e2091639c9a', 'SEQUENCE' => 2]); + $message->message->VEVENT->add('SUMMARY', 'Fellowship meeting'); + $message->message->VEVENT->add('DTSTART', (new \DateTime('NOW'))->modify('+1 hour')); + $message->message->VEVENT->add('DTEND', (new \DateTime('NOW'))->modify('+2 hour')); + $message->message->VEVENT->add('ORGANIZER', 'mailto:organizer@example.com', ['CN' => 'The Organizer']); + $message->message->VEVENT->add('ATTENDEE', 'mailto:attendee@example.com', ['CN' => 'The Attendee']); + // Test getCurrentAttendee + $result = $this->service->getCurrentAttendee($message); + // Evaluate Result + $this->assertEquals($message->message->VEVENT->ATTENDEE, $result); + } + + public function testGetCurrentAttendeeMismatch(): void { + // Construct ITip Message + $message = new Message(); + $message->method = 'REQUEST'; + $message->sequence = 1; + $message->sender = 'mailto:organizer@example.com'; + $message->senderName = 'The Organizer'; + $message->recipient = 'mailto:mismatch@example.com'; + $message->recipientName = 'The Mismatch'; + $message->significantChange = true; + $message->message = new VCalendar(); + $message->message->add('VEVENT', ['UID' => '82496785-1915-4604-a5ce-4e2091639c9a', 'SEQUENCE' => 1]); + $message->message->VEVENT->add('SUMMARY', 'Fellowship meeting'); + $message->message->VEVENT->add('DTSTART', (new \DateTime('NOW'))->modify('+1 hour')); + $message->message->VEVENT->add('DTEND', (new \DateTime('NOW'))->modify('+2 hour')); + $message->message->VEVENT->add('ORGANIZER', 'mailto:organizer@example.com', ['CN' => 'The Organizer']); + $message->message->VEVENT->add('ATTENDEE', 'mailto:attendee@example.com', ['CN' => 'The Attendee']); + // Test getCurrentAttendee + $result = $this->service->getCurrentAttendee($message); + // Evaluate Result + $this->assertEquals(null, $result); + } } |