]> source.dussan.org Git - nextcloud-server.git/commitdiff
RefreshWebcalService: randomly generate calendar-object uri 20148/head
authorGeorg Ehrke <developer@georgehrke.com>
Mon, 16 Mar 2020 14:04:21 +0000 (15:04 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 25 Mar 2020 07:13:01 +0000 (07:13 +0000)
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
apps/dav/lib/CalDAV/WebcalCaching/RefreshWebcalService.php
apps/dav/tests/unit/CalDAV/WebcalCaching/RefreshWebcalServiceTest.php

index beab0271d8fb2913edd241946c2d6e65b5e213d5..a057e29eb2c67a908a699e102de6381835865fc7 100644 (file)
@@ -47,6 +47,7 @@ use Sabre\VObject\InvalidDataException;
 use Sabre\VObject\ParseException;
 use Sabre\VObject\Reader;
 use Sabre\VObject\Splitter\ICalendar;
+use Sabre\VObject\UUIDUtil;
 use function count;
 
 class RefreshWebcalService {
@@ -113,7 +114,6 @@ class RefreshWebcalService {
 
                        while ($vObject = $splitter->getNext()) {
                                /** @var Component $vObject */
-                               $uid = null;
                                $compName = null;
 
                                foreach ($vObject->getComponents() as $component) {
@@ -121,7 +121,6 @@ class RefreshWebcalService {
                                                continue;
                                        }
 
-                                       $uid = $component->{'UID'}->getValue();
                                        $compName = $component->name;
 
                                        if ($stripAlarms) {
@@ -136,7 +135,7 @@ class RefreshWebcalService {
                                        continue;
                                }
 
-                               $uri = $uid . '.ics';
+                               $uri = $this->getRandomCalendarObjectUri();
                                $calendarData = $vObject->serialize();
                                try {
                                        $this->calDavBackend->createCalendarObject($subscription['id'], $uri, $calendarData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
@@ -413,4 +412,13 @@ class RefreshWebcalService {
 
                return $cleanURL;
        }
+
+       /**
+        * Returns a random uri for a calendar-object
+        *
+        * @return string
+        */
+       public function getRandomCalendarObjectUri():string {
+               return UUIDUtil::getUUID() . '.ics';
+       }
 }
index 01e541ec20e897942c980d2b9ce0a1a94c94819d..b1d341c2e4e8bd515f71fb30a15c31188d1802e3 100644 (file)
@@ -69,8 +69,14 @@ class RefreshWebcalServiceTest extends TestCase {
         * @dataProvider runDataProvider
         */
        public function testRun(string $body, string $contentType, string $result) {
-               $refreshWebcalService = new RefreshWebcalService($this->caldavBackend,
-                       $this->clientService, $this->config, $this->logger);
+               $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class)
+                       ->setMethods(['getRandomCalendarObjectUri'])
+                       ->setConstructorArgs([$this->caldavBackend, $this->clientService, $this->config, $this->logger])
+                       ->getMock();
+
+               $refreshWebcalService
+                       ->method('getRandomCalendarObjectUri')
+                       ->willReturn('uri-1.ics');
 
                $this->caldavBackend->expects($this->once())
                        ->method('getSubscriptionsForUser')
@@ -130,7 +136,7 @@ class RefreshWebcalServiceTest extends TestCase {
 
                $this->caldavBackend->expects($this->once())
                        ->method('createCalendarObject')
-                       ->with(42, '12345.ics', $result, 1);
+                       ->with(42, 'uri-1.ics', $result, 1);
 
                $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
        }