diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2022-09-08 12:42:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-08 12:42:03 +0200 |
commit | c77cc80fcc2845416ec1a8cc2a26fcb63881bfe7 (patch) | |
tree | 46b615abb0293f52c2331f6afd31809dfb6a20c3 | |
parent | 5555500e9875011e511de6702f93e2462a7ce368 (diff) | |
parent | e3a52ce13e501005736736def2fa8889fe47add1 (diff) | |
download | nextcloud-server-c77cc80fcc2845416ec1a8cc2a26fcb63881bfe7.tar.gz nextcloud-server-c77cc80fcc2845416ec1a8cc2a26fcb63881bfe7.zip |
Merge pull request #33906 from nextcloud/fix/fix-calendar-tests-getTimestamp
Fix Calendar tests mocking a non-existant method.
-rw-r--r-- | lib/private/Calendar/Manager.php | 17 | ||||
-rw-r--r-- | tests/lib/Calendar/ManagerTest.php | 71 |
2 files changed, 53 insertions, 35 deletions
diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php index f0b8e9fd50d..550ba36dd6b 100644 --- a/lib/private/Calendar/Manager.php +++ b/lib/private/Calendar/Manager.php @@ -330,12 +330,27 @@ class Manager implements IManager { // to the email address in the ORGANIZER. // We don't want to accept a CANCEL request from just anyone $organizer = substr($vEvent->{'ORGANIZER'}->getValue(), 7); - if (strcasecmp($sender, $organizer) !== 0 && strcasecmp($replyTo, $organizer) !== 0) { + $isNotOrganizer = ($replyTo !== null) ? (strcasecmp($sender, $organizer) !== 0 && strcasecmp($replyTo, $organizer) !== 0) : (strcasecmp($sender, $organizer) !== 0); + if ($isNotOrganizer) { $this->logger->warning('Sender must be the ORGANIZER of this event'); return false; } + //check if the event is in the future + /** @var DateTime $eventTime */ + $eventTime = $vEvent->{'DTSTART'}; + if ($eventTime->getDateTime()->getTimeStamp() < $this->timeFactory->getTime()) { // this might cause issues with recurrences + $this->logger->warning('Only events in the future are processed'); + return false; + } + + // Check if we have a calendar to work with $calendars = $this->getCalendarsForPrincipal($principalUri); + if (empty($calendars)) { + $this->logger->warning('Could not find any calendars for principal ' . $principalUri); + return false; + } + $found = null; // if the attendee has been found in at least one calendar event with the UID of the iMIP event // we process it. diff --git a/tests/lib/Calendar/ManagerTest.php b/tests/lib/Calendar/ManagerTest.php index 8b99c21ae41..ba30be1b548 100644 --- a/tests/lib/Calendar/ManagerTest.php +++ b/tests/lib/Calendar/ManagerTest.php @@ -251,7 +251,7 @@ class ManagerTest extends TestCase { $this->logger->expects(self::once()) ->method('warning'); $this->time->expects(self::never()) - ->method('getTimestamp'); + ->method('getTime'); $result = $this->manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize()); $this->assertFalse($result); @@ -266,7 +266,7 @@ class ManagerTest extends TestCase { $this->logger->expects(self::once()) ->method('warning'); $this->time->expects(self::never()) - ->method('getTimestamp'); + ->method('getTime'); $result = $this->manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize()); $this->assertFalse($result); @@ -280,7 +280,7 @@ class ManagerTest extends TestCase { $calendarData->VEVENT->DTSTART = new \DateTime('2013-04-07'); // set to in the past $this->time->expects(self::once()) - ->method('getTimestamp') + ->method('getTime') ->willReturn(time()); $this->logger->expects(self::once()) @@ -301,15 +301,16 @@ class ManagerTest extends TestCase { ]) ->setMethods([ 'getCalendarsForPrincipal' - ]); + ]) + ->getMock(); $principalUri = 'principals/user/linus'; $sender = 'pierre@general-store.com'; $recipient = 'linus@stardew-tent-living.com'; $calendarData = $this->getVCalendarReply(); $this->time->expects(self::once()) - ->method('getTimestamp') - ->willReturn(202208219); + ->method('getTime') + ->willReturn(1628374233); $manager->expects(self::once()) ->method('getCalendarsForPrincipal') ->willReturn([]); @@ -331,7 +332,8 @@ class ManagerTest extends TestCase { ]) ->setMethods([ 'getCalendarsForPrincipal' - ]); + ]) + ->getMock(); $calendar = $this->createMock(ICreateFromString::class); $principalUri = 'principals/user/linus'; $sender = 'pierre@general-store.com'; @@ -339,8 +341,8 @@ class ManagerTest extends TestCase { $calendarData = $this->getVCalendarReply(); $this->time->expects(self::once()) - ->method('getTimestamp') - ->willReturn(202208219); + ->method('getTime') + ->willReturn(1628374233); $manager->expects(self::once()) ->method('getCalendarsForPrincipal') ->willReturn([$calendar]); @@ -367,7 +369,8 @@ class ManagerTest extends TestCase { ]) ->setMethods([ 'getCalendarsForPrincipal' - ]); + ]) + ->getMock(); $calendar = $this->createMock(ICreateFromString::class); $principalUri = 'principals/user/linus'; $sender = 'pierre@general-store.com'; @@ -375,8 +378,8 @@ class ManagerTest extends TestCase { $calendarData = $this->getVCalendarReply(); $this->time->expects(self::once()) - ->method('getTimestamp') - ->willReturn(202208219); + ->method('getTime') + ->willReturn(1628374233); $manager->expects(self::once()) ->method('getCalendarsForPrincipal') ->willReturn([$calendar]); @@ -397,12 +400,12 @@ class ManagerTest extends TestCase { $recipient = 'pierre@general-store.com'; $replyTo = null; $calendarData = $this->getVCalendarCancel(); - $calendarData->VEVENT->METHOD = 'REQUEST'; + $calendarData->METHOD = 'REQUEST'; $this->logger->expects(self::once()) ->method('warning'); $this->time->expects(self::never()) - ->method('getTimestamp'); + ->method('getTime'); $result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); $this->assertFalse($result); @@ -414,12 +417,11 @@ class ManagerTest extends TestCase { $recipient = 'leah@general-store.com'; $replyTo = null; $calendarData = $this->getVCalendarCancel(); - $calendarData->VEVENT->METHOD = 'CANCEL'; $this->logger->expects(self::once()) ->method('warning'); $this->time->expects(self::never()) - ->method('getTimestamp'); + ->method('getTime'); $result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); $this->assertFalse($result); @@ -434,7 +436,7 @@ class ManagerTest extends TestCase { $calendarData->VEVENT->DTSTART = new \DateTime('2013-04-07'); // set to in the past $this->time->expects(self::once()) - ->method('getTimestamp') + ->method('getTime') ->willReturn(time()); $this->logger->expects(self::once()) ->method('warning'); @@ -454,7 +456,8 @@ class ManagerTest extends TestCase { ]) ->setMethods([ 'getCalendarsForPrincipal' - ]); + ]) + ->getMock(); $principalUri = 'principals/user/pierre'; $sender = 'linus@stardew-tent-living.com'; $recipient = 'pierre@general-store.com'; @@ -462,8 +465,8 @@ class ManagerTest extends TestCase { $calendarData = $this->getVCalendarCancel(); $this->time->expects(self::once()) - ->method('getTimestamp') - ->willReturn(202208219); + ->method('getTime') + ->willReturn(1628374233); $manager->expects(self::once()) ->method('getCalendarsForPrincipal') ->with($principalUri) @@ -471,8 +474,8 @@ class ManagerTest extends TestCase { $this->logger->expects(self::once()) ->method('warning'); - $result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); - $this->assertTrue($result); + $result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); + $this->assertFalse($result); } public function testHandleImipCancelOrganiserInReplyTo(): void { @@ -486,18 +489,18 @@ class ManagerTest extends TestCase { ]) ->setMethods([ 'getCalendarsForPrincipal' - ]); + ]) + ->getMock(); $principalUri = 'principals/user/pierre'; $sender = 'clint@stardew-blacksmiths.com'; $recipient = 'pierre@general-store.com'; $replyTo = 'linus@stardew-tent-living.com'; $calendar = $this->createMock(ICreateFromString::class); $calendarData = $this->getVCalendarCancel(); - $calendarData->VEVENT->METHOD = 'CANCEL'; $this->time->expects(self::once()) - ->method('getTimestamp') - ->willReturn(202208219); + ->method('getTime') + ->willReturn(1628374233); $manager->expects(self::once()) ->method('getCalendarsForPrincipal') ->with($principalUri) @@ -508,8 +511,8 @@ class ManagerTest extends TestCase { $calendar->expects(self::once()) ->method('handleIMipMessage') ->with('testname.ics', $calendarData->serialize()); - $result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); - $this->assertFalse($result); + $result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); + $this->assertTrue($result); } public function testHandleImipCancel(): void { @@ -523,18 +526,18 @@ class ManagerTest extends TestCase { ]) ->setMethods([ 'getCalendarsForPrincipal' - ]); + ]) + ->getMock(); $principalUri = 'principals/user/pierre'; $sender = 'linus@stardew-tent-living.com'; $recipient = 'pierre@general-store.com'; $replyTo = null; $calendar = $this->createMock(ICreateFromString::class); $calendarData = $this->getVCalendarCancel(); - $calendarData->VEVENT->METHOD = 'CANCEL'; $this->time->expects(self::once()) - ->method('getTimestamp') - ->willReturn(202208219); + ->method('getTime') + ->willReturn(1628374233); $manager->expects(self::once()) ->method('getCalendarsForPrincipal') ->with($principalUri) @@ -545,8 +548,8 @@ class ManagerTest extends TestCase { $calendar->expects(self::once()) ->method('handleIMipMessage') ->with('testname.ics', $calendarData->serialize()); - $result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); - $this->assertFalse($result); + $result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); + $this->assertTrue($result); } private function getVCalendarReply(): Document { |