Skip to content

Commit

Permalink
Merge pull request #44893 from nextcloud/fix/issue-43115
Browse files Browse the repository at this point in the history
fix(caldav): When message is a reply compare the message sender not the recipient
  • Loading branch information
kesselb authored Jun 26, 2024
2 parents ba30695 + d7eb509 commit aa0bbd2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
7 changes: 5 additions & 2 deletions apps/dav/lib/CalDAV/Schedule/IMipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,11 @@ public function getCurrentAttendee(Message $iTipMessage): ?Property {
$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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function setUp(): void {
$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');
Expand Down
71 changes: 71 additions & 0 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;

Expand Down Expand Up @@ -248,4 +249,74 @@ public function testGetLastOccurrenceFallback(): void {
$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);
}
}

0 comments on commit aa0bbd2

Please sign in to comment.