From 9c10ef5eb2a7df0f40b7b1ac386bfe0a0bc59a2a Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Sat, 2 Mar 2024 23:23:37 +1300 Subject: [PATCH] Support start or end missing from free-busy-query REPORT Previously if either start or end were missing then the current time was used. This would almost never be the expected behaviour. --- ChangeLog | 4 +++ inc/caldav-REPORT-freebusy.php | 29 +++++++++++++++++-- ...605-REPORT-freebusy-no-start-no-end.result | 8 +++++ .../2605-REPORT-freebusy-no-start-no-end.test | 20 +++++++++++++ .../2606-REPORT-freebusy-no-start.result | 21 ++++++++++++++ .../2606-REPORT-freebusy-no-start.test | 21 ++++++++++++++ .../2607-REPORT-freebusy-no-end.result | 21 ++++++++++++++ .../2607-REPORT-freebusy-no-end.test | 21 ++++++++++++++ 8 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 testing/tests/regression-suite/2605-REPORT-freebusy-no-start-no-end.result create mode 100644 testing/tests/regression-suite/2605-REPORT-freebusy-no-start-no-end.test create mode 100644 testing/tests/regression-suite/2606-REPORT-freebusy-no-start.result create mode 100644 testing/tests/regression-suite/2606-REPORT-freebusy-no-start.test create mode 100644 testing/tests/regression-suite/2607-REPORT-freebusy-no-end.result create mode 100644 testing/tests/regression-suite/2607-REPORT-freebusy-no-end.test diff --git a/ChangeLog b/ChangeLog index 19039261..c328d22a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2024-03-02 Andrew Ruthve + * Fix free-busy-query REPORT if start/end is missing, previously the + current timestamp was used for missing values. + 2023-03-02 Florian Schlichting * release davical 1.1.12 * add Debian autopkgtests diff --git a/inc/caldav-REPORT-freebusy.php b/inc/caldav-REPORT-freebusy.php index c77a504b..983dc28b 100644 --- a/inc/caldav-REPORT-freebusy.php +++ b/inc/caldav-REPORT-freebusy.php @@ -10,9 +10,34 @@ $fbq_end = $fbq_content[0]->GetAttribute('end'); if ( ! ( isset($fbq_start) || isset($fbq_end) ) ) { $request->DoResponse( 400, 'All valid freebusy requests MUST contain a time-range filter' ); } -$range_start = new RepeatRuleDateTime($fbq_start); -$range_end = new RepeatRuleDateTime($fbq_end); +if ( isset($fbq_start) ) { + $range_start = new RepeatRuleDateTime($fbq_start); +} else { + # RFC 4791 Section 9.9 says that if start isn't set, then -infinity + # should be used. We can't specify that in PHP, and + # expand_event_instances has '-6 weeks' as the default. + # That's a bit short, go for one year prior to end, if defined, + # otherwise 1 year prior to now now. + if ( isset($fbq_end) ) { + $range_start = new RepeatRuleDateTime($fbq_end); + } else { + $range_start = new RepeatRuleDateTime; + } + + $range_start->modify('-365 days'); +} + +if ( isset($fbq_end) ) { + $range_end = new RepeatRuleDateTime($fbq_end); +} else { + # RFC 4791 Section 9.9 says that if end isn't set, then +infinity + # should be used. We can't specify that in PHP, and + # expand_event_instances has '+ 6 weeks' as the default. That's a + # bit short, go for two years from the start. + $range_end = clone($range_start); + $range_end->modify('+730 days'); +} /** We use the same code for the REPORT, the POST and the freebusy GET... */ $freebusy = get_freebusy( '^' . $request->path . $request->DepthRegexTail(true), $range_start, $range_end ); diff --git a/testing/tests/regression-suite/2605-REPORT-freebusy-no-start-no-end.result b/testing/tests/regression-suite/2605-REPORT-freebusy-no-start-no-end.result new file mode 100644 index 00000000..1d06f2b5 --- /dev/null +++ b/testing/tests/regression-suite/2605-REPORT-freebusy-no-start-no-end.result @@ -0,0 +1,8 @@ +HTTP/1.1 400 Bad Request +Date: Dow, 01 Jan 2000 00:00:00 GMT +DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule +DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy +Content-Length: 60 +Content-Type: text/plain; charset="utf-8" + +All valid freebusy requests MUST contain a time-range filter \ No newline at end of file diff --git a/testing/tests/regression-suite/2605-REPORT-freebusy-no-start-no-end.test b/testing/tests/regression-suite/2605-REPORT-freebusy-no-start-no-end.test new file mode 100644 index 00000000..f5644f9c --- /dev/null +++ b/testing/tests/regression-suite/2605-REPORT-freebusy-no-start-no-end.test @@ -0,0 +1,20 @@ +# +# Request a REPORT with no start end end set, should return an error. +# +TYPE=REPORT +URL=http://regression.host/caldav.php/user1/291-test-fb-rr-changes/ +HEADER=Accept: text/calendar +HEADER=Content-Type: text/xml +HEADER=Depth: 1 +HEAD + +AUTH=user4:user4 + +BEGINDATA + + + + +ENDDATA + +REPLACE=/^DTSTAMP:\d{8}T\d{6}Z\r?$/DTSTAMP:yyyymmddThhmmssZ/ diff --git a/testing/tests/regression-suite/2606-REPORT-freebusy-no-start.result b/testing/tests/regression-suite/2606-REPORT-freebusy-no-start.result new file mode 100644 index 00000000..2f8a05a3 --- /dev/null +++ b/testing/tests/regression-suite/2606-REPORT-freebusy-no-start.result @@ -0,0 +1,21 @@ +HTTP/1.1 200 OK +Date: Dow, 01 Jan 2000 00:00:00 GMT +DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule +DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy +Content-Length: 398 +Content-Type: text/calendar;charset=UTF-8 + +BEGIN:VCALENDAR +PRODID:-//davical.org//NONSGML AWL Calendar//EN +VERSION:2.0 +CALSCALE:GREGORIAN +BEGIN:VFREEBUSY +DTSTAMP:yyyymmddThhmmssZ +DTSTART:20230416T140000Z +DTEND:20250415T140000Z +FREEBUSY:20230416T210000Z/20230416T212500Z +FREEBUSY:20230418T230000Z/20230418T232500Z +FREEBUSY:20230419T210000Z/20230419T212500Z +FREEBUSY:20230420T210000Z/20230420T212500Z +END:VFREEBUSY +END:VCALENDAR diff --git a/testing/tests/regression-suite/2606-REPORT-freebusy-no-start.test b/testing/tests/regression-suite/2606-REPORT-freebusy-no-start.test new file mode 100644 index 00000000..47f5898a --- /dev/null +++ b/testing/tests/regression-suite/2606-REPORT-freebusy-no-start.test @@ -0,0 +1,21 @@ +# +P +# Request a REPORT with only start set, end should be sometime in the future. +# +TYPE=REPORT +URL=http://regression.host/caldav.php/user1/291-test-fb-rr-changes/ +HEADER=Accept: text/calendar +HEADER=Content-Type: text/xml +HEADER=Depth: 1 +HEAD + +AUTH=user4:user4 + +BEGINDATA + + + + +ENDDATA + +REPLACE=/^DTSTAMP:\d{8}T\d{6}Z\r?$/DTSTAMP:yyyymmddThhmmssZ/ diff --git a/testing/tests/regression-suite/2607-REPORT-freebusy-no-end.result b/testing/tests/regression-suite/2607-REPORT-freebusy-no-end.result new file mode 100644 index 00000000..77f6ea11 --- /dev/null +++ b/testing/tests/regression-suite/2607-REPORT-freebusy-no-end.result @@ -0,0 +1,21 @@ +HTTP/1.1 200 OK +Date: Dow, 01 Jan 2000 00:00:00 GMT +DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule +DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy +Content-Length: 398 +Content-Type: text/calendar;charset=UTF-8 + +BEGIN:VCALENDAR +PRODID:-//davical.org//NONSGML AWL Calendar//EN +VERSION:2.0 +CALSCALE:GREGORIAN +BEGIN:VFREEBUSY +DTSTAMP:yyyymmddThhmmssZ +DTSTART:20220421T220000Z +DTEND:20230421T220000Z +FREEBUSY:20230416T210000Z/20230416T212500Z +FREEBUSY:20230418T230000Z/20230418T232500Z +FREEBUSY:20230419T210000Z/20230419T212500Z +FREEBUSY:20230420T210000Z/20230420T212500Z +END:VFREEBUSY +END:VCALENDAR diff --git a/testing/tests/regression-suite/2607-REPORT-freebusy-no-end.test b/testing/tests/regression-suite/2607-REPORT-freebusy-no-end.test new file mode 100644 index 00000000..dd062564 --- /dev/null +++ b/testing/tests/regression-suite/2607-REPORT-freebusy-no-end.test @@ -0,0 +1,21 @@ +# +P +# Request a REPORT with only end set, start should be sometime in the past. +# +TYPE=REPORT +URL=http://regression.host/caldav.php/user1/291-test-fb-rr-changes/ +HEADER=Accept: text/calendar +HEADER=Content-Type: text/xml +HEADER=Depth: 1 +HEAD + +AUTH=user4:user4 + +BEGINDATA + + + + +ENDDATA + +REPLACE=/^DTSTAMP:\d{8}T\d{6}Z\r?$/DTSTAMP:yyyymmddThhmmssZ/