0011130: handle bad originator timzone in VCALENDAR converter
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 7 Jul 2015 12:48:42 +0000 (14:48 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 9 Jul 2015 13:11:47 +0000 (15:11 +0200)
* adds a test with broken originator_tz
* throw exceptions if bad originator timezone is found

https://forge.tine20.org/view.php?id=11130

Change-Id: I2337fbd96387a7595da3e7df5eedb9a45411c344
Reviewed-on: http://gerrit.tine20.com/customers/2016
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Controller/EventTests.php
tests/tine20/Calendar/Convert/Event/VCalendar/GenericTest.php
tine20/Calendar/Controller/Event.php
tine20/Calendar/Convert/Event/VCalendar/Abstract.php

index 3cfb684..d848696 100644 (file)
@@ -1492,4 +1492,19 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $ownAttender = Calendar_Model_Attender::getOwnAttender($repairedEvent->attendee);
         $this->assertTrue($ownAttender !== null);
     }
+
+    /**
+     * @see 0011130: handle bad originator timzone in VCALENDAR converter
+     */
+    public function testBrokenTimezoneInEvent()
+    {
+        $event = $this->_getEvent(true);
+        $event->originator_tz = 'AWST';
+        try {
+            $event = $this->_controller->create($event);
+            $this->fail('should throw Tinebase_Exception_Record_Validation because of bad TZ: ' . print_r($event->toArray(), true));
+        } catch (Tinebase_Exception_Record_Validation $terv) {
+            $this->assertEquals('Bad Timezone: AWST', $terv->getMessage());
+        }
+    }
 }
index 5f2ccdc..78dd6c3 100644 (file)
@@ -758,4 +758,22 @@ class Calendar_Convert_Event_VCalendar_GenericTest extends PHPUnit_Framework_Tes
         
         $this->assertEquals('Telko axel', $savedEvent->summary);
     }
+
+    /**
+     * @see 0011130: handle bad originator timzone in VCALENDAR converter
+     */
+    public function testBrokenTimezoneInTineEvent()
+    {
+        $event = $this->testConvertRepeatingAllDayDailyEventToTine20Model();
+        $event->originator_tz = 'AWST'; // Australian Western Standard Time
+
+        $this->_converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
+
+        try {
+            $vevent = $this->_converter->fromTine20Model($event)->serialize();
+            $this->fail('should throw Tinebase_Exception_Record_Validation because of bad TZ');
+        } catch (Tinebase_Exception_Record_Validation $terv) {
+            $this->assertEquals('Bad Timezone: AWST', $terv->getMessage());
+        }
+    }
 }
index c4cf83d..0e31722 100644 (file)
@@ -1475,10 +1475,11 @@ class Calendar_Controller_Event extends Tinebase_Controller_Record_Abstract impl
     protected function _inspectEvent($_record)
     {
         $_record->uid = $_record->uid ? $_record->uid : Tinebase_Record_Abstract::generateUID();
-        $_record->originator_tz = $_record->originator_tz ? $_record->originator_tz : Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
         $_record->organizer = $_record->organizer ? $_record->organizer : Tinebase_Core::getUser()->contact_id;
         $_record->transp = $_record->transp ? $_record->transp : Calendar_Model_Event::TRANSP_OPAQUE;
-        
+
+        $this->_inspectOriginatorTZ($_record);
+
         if ($_record->hasExternalOrganizer()) {
             // assert calendarUser as attendee. This is important to keep the event in the loop via its displaycontianer(s)
             try {
@@ -1532,6 +1533,23 @@ class Calendar_Controller_Event extends Tinebase_Controller_Record_Abstract impl
             $_record->rrule = NULL;
         }
     }
+
+    /**
+     * checks/sets originator timezone
+     *
+     * @param $record
+     * @throws Tinebase_Exception_Record_Validation
+     */
+    protected function _inspectOriginatorTZ($record)
+    {
+        $record->originator_tz = $record->originator_tz ? $record->originator_tz : Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
+
+        try {
+            new DateTimeZone($record->originator_tz);
+        } catch (Exception $e) {
+            throw new Tinebase_Exception_Record_Validation('Bad Timezone: ' . $record->originator_tz);
+        }
+    }
     
     /**
      * inspects delete action
index 67684a7..32098c2 100644 (file)
@@ -81,8 +81,13 @@ class Calendar_Convert_Event_VCalendar_Abstract extends Tinebase_Convert_VCalend
         if (empty($originatorTz)) {
             throw new Tinebase_Exception_Record_Validation('originator_tz needed for conversion to Sabre\VObject\Component');
         }
-        
-        $vcalendar->add(new Sabre_VObject_Component_VTimezone($originatorTz));
+
+        try {
+            $vcalendar->add(new Sabre_VObject_Component_VTimezone($originatorTz));
+        } catch (Exception $e) {
+            Tinebase_Exception::log($e);
+            throw new Tinebase_Exception_Record_Validation('Bad Timezone: ' . $originatorTz);
+        }
         
         foreach ($_records as $_record) {
             $this->_convertCalendarModelEvent($vcalendar, $_record);