Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ This release works with caldav 3.7.0: the tester carries the definitions of the
- **`search.time-range.event.tzid`** - whether a time-range search places an event with `TZID=Asia/Tokyo` and its VTIMEZONE at its time in UTC. Infomaniak finds it only by a range that also reaches 12:00 UTC, its local time read as UTC. caldav does not define these three features yet, so the tester adds their definitions itself until a caldav release has them.
- **`save-load.icalendar.attendee-once`** - whether each ATTENDEE of an event comes back once. Bedework 5 stores every ATTENDEE twice, as an exact copy (`quirk`, "stored twice"), which caldav will drop when it reads the data (a caldav change still to be released). caldav does not define this feature yet, so the tester adds its definition itself until a caldav release has it.
- **`url.encode-at.encoded.href`** - whether a calendar-multiget finds an object named by an href with `%40`, as a GET of that URL does. Robur does not decode the `%40` in the href and answers 404; the literal `@` finds the object. caldav does not define this feature yet, so the tester adds its definition itself until a caldav release has it.
- **`search.recurrences.exception.in-calendar-data`** - whether a search returns a recurring event with its exceptions, as a GET has it. Bedework 3.10 and 5 return the master only. caldav does not define this feature yet, so the tester adds its definition itself until a caldav release has it.

### Fixed

- **`save-load.event.recurrences.exception`** is graded on a GET of the stored event, not on what a search returned. Bedework 3.10 and 5 were reported as not storing the exception, while it was only the search that left it out.
- A probe for a feature the installed caldav does not know no longer aborts the whole run. The check logs a warning and loses that feature only, and a check reading it gets "unknown"; a check with no other feature is not run.
- **`save.duplicate-uid.cross-calendar`** - whether saving the copy moved the original is read from a listing of the original calendar, not from a search by UID, which a stale search index answers wrongly.
- **`save.if-none-match`** also puts an object with another UID under a taken name, as a new object saved there would have one: Bedework (3 and 5) refuses the same UID with 412, but another one with 500, which the library does not read as "exists". It is now `ungraceful` there.
Expand Down
83 changes: 70 additions & 13 deletions src/caldav_server_tester/checks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import inspect
import logging
import math
import os
Expand All @@ -12,7 +13,7 @@
from xml.sax.saxutils import escape as xml_escape
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError

from caldav.calendarobjectresource import Event, Journal, Todo, _quote_uid
from caldav.calendarobjectresource import CalendarObjectResource, Event, Journal, Todo, _quote_uid
from caldav.collection import Principal
from caldav.compatibility_hints import FeatureSet
from caldav.davobject import DAVObject
Expand Down Expand Up @@ -1633,6 +1634,7 @@ class PrepareCalendar(Check):
"save-load.event.recurrences",
"save-load.event.recurrences.count",
"save-load.event.recurrences.exception",
"search.recurrences.exception.in-calendar-data",
"save-load.todo.recurrences",
"save-load.todo.recurrences.count",
"save-load.event",
Expand Down Expand Up @@ -1873,8 +1875,14 @@ def _store_recurrence_with_exception(self, calendar, add_if_not_existing, base):
Only what the server answered is graded: a PUT that fails without an
answer (a dropped connection, a gateway) and a failed listing say
nothing about the feature and are "unknown", with the reason.
What is stored is read by a GET, as the listing is a search: Bedework
3.10 and 5 leave the exception out of the calendar-data of a search
while a GET has it. The listing against the GET grades
search.recurrences.exception.in-calendar-data.
"""
feature = "save-load.event.recurrences.exception"
in_search = "search.recurrences.exception.in-calendar-data"
exception_uid = "csc_monthly_recurring_with_exception"
try:
add_if_not_existing(
Expand Down Expand Up @@ -1904,6 +1912,7 @@ def _store_recurrence_with_exception(self, calendar, add_if_not_existing, base):
self.set_feature(
feature, graded_refusal(e, "a master VEVENT with an exception VEVENT is refused ({answer})")
)
self.set_feature(in_search, {"support": "unknown", "behaviour": "cannot test, the event was not stored"})
return

try:
Expand All @@ -1912,6 +1921,7 @@ def _store_recurrence_with_exception(self, calendar, add_if_not_existing, base):
self.set_feature(
feature, {"support": "unknown", "behaviour": f"cannot test, listing the calendar failed ({e})"}
)
self.set_feature(in_search, {"support": "unknown", "behaviour": "cannot test, the listing failed"})
return

def _uid(obj):
Expand All @@ -1922,31 +1932,66 @@ def _uid(obj):
except Exception:
return None

def _vevents(obj):
return len([c for c in obj.icalendar_instance.subcomponents if c.name == "VEVENT"])

ours = [obj for obj in listing if _uid(obj) == exception_uid]
if not ours:
self.set_feature(
feature, {"support": "unknown", "behaviour": "cannot test, the stored event is not in the listing"}
)
elif len(ours) > 1:
self.set_feature(in_search, {"support": "unknown", "behaviour": "cannot test, nothing listed"})
return
if len(ours) > 1:
self.set_feature(
feature,
{
"support": "unsupported",
"behaviour": f"the exception is stored as a separate object ({len(ours)} objects with the UID)",
},
)
self.set_feature(
in_search, {"support": "unknown", "behaviour": "cannot test, the exception is stored apart"}
)
return

listed = _vevents(ours[0])
try:
_load_by_get(ours[0])
except Exception as e:
self.set_feature(
feature, {"support": "unknown", "behaviour": f"cannot test, a GET of the stored event failed ({e})"}
)
self.set_feature(in_search, {"support": "unknown", "behaviour": "cannot test, the GET failed"})
return
stored = _vevents(ours[0])
if stored == 2:
self.set_feature(feature)
else:
vevents = [c for c in ours[0].icalendar_instance.subcomponents if c.name == "VEVENT"]
if len(vevents) == 2:
self.set_feature(feature)
else:
self.set_feature(
feature,
{
"support": "unsupported",
"behaviour": f"stored as one object with {len(vevents)} VEVENTs instead of 2",
},
)
self.set_feature(
feature,
{
"support": "unsupported",
"behaviour": f"stored as one object with {stored} VEVENTs instead of 2",
},
)
self.set_feature(in_search, {"support": "unknown", "behaviour": "cannot test, the exception is not stored"})
return
if listed == stored:
self.set_feature(in_search)
elif listed == 1:
self.set_feature(
in_search,
{"support": "unsupported", "behaviour": "the calendar-data of a search holds the master only"},
)
else:
self.set_feature(
in_search,
{
"support": "unsupported",
"behaviour": f"the calendar-data of a search holds {listed} VEVENTs where a GET has {stored}",
},
)

def _create_test_events(self, calendar, cal_id, name, add_if_not_existing):
"""Create all the test event/task/journal objects in the calendar.
Expand Down Expand Up @@ -4278,6 +4323,18 @@ def _run_check(self):
self.set_feature("synchronous-write", {"support": "full", "save-load-delay": save_load})


def _load_by_get(obj):
"""Load ``obj`` by a GET and nothing else.
caldav's load() falls back to a calendar-multiget, and after a 404 to a
search by UID. A caldav without load(fallbacks=...) still does the
latter: there only the multiget is turned off.
"""
if "fallbacks" in inspect.signature(CalendarObjectResource.load).parameters:
return obj.load(fallbacks=False)
return obj.load(multiget_fallback=False)


@contextlib.contextmanager
def proppatch_wait(client, node):
"""Run a block with the library waiting after a PROPPATCH as ``node`` says.
Expand Down
10 changes: 10 additions & 0 deletions src/caldav_server_tester/future_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
from caldav.compatibility_hints import FeatureSet

FUTURE_FEATURES: dict[str, dict] = {
## caldav PR 867 (https://github.com/python-caldav/caldav/pull/867)
"search.recurrences.exception": {
"description": "A search handles the exceptions of a recurrence set (the components with a RECURRENCE-ID) as it handles any other component. The children say in what way it does not",
"default": {"support": "full"},
},
"search.recurrences.exception.in-calendar-data": {
"description": "A search returns a recurring object with all its components: the exceptions (the components with a RECURRENCE-ID) along with the master, as a GET has them. RFC 4791 section 9.6 makes a calendar-data element with no children ask for the whole object. 'unsupported' when the calendar-data of a search holds the master only (Bedework 3.10 and 5): a client expanding the recurrence set itself then gets each moved or changed occurrence as a plain one. search() then loads the recurring objects it found again with a multiget",
"default": {"support": "full"},
"links": ["https://datatracker.ietf.org/doc/html/rfc4791#section-9.6"],
},
## caldav PR 864 (https://github.com/python-caldav/caldav/pull/864)
"save-load.icalendar.attendee-once": {
"description": "Each ATTENDEE of an event comes back once. 'quirk' with behaviour 'stored twice' when every ATTENDEE line comes back twice, as an exact copy (Bedework 5, with or without ORGANIZER, RRULE or PARTSTAT); vcal.fix() drops an exact copy of an ATTENDEE line in the same component whenever iCalendar text is set on an object, whatever this hint says, so a client sees each attendee once. 'broken' when an attendee comes back twice with lines that differ, which the library keeps.",
Expand Down
107 changes: 102 additions & 5 deletions tests/test_recurrence_exception_grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,55 @@
word of behaviour, and the event missing from it "unsupported". Robur was
reported "ungraceful" run after run that way, while storing a master VEVENT
with its exception correctly.
What is stored is read by a GET, not off the listing: Bedework 3.10 and 5
leave the exception out of the calendar-data of a search, and were graded
as not storing it. The difference between the two is
search.recurrences.exception.in-calendar-data.
"""

import inspect
from unittest.mock import Mock

import icalendar
import niquests
import pytest
from caldav.calendarobjectresource import CalendarObjectResource
from caldav.compatibility_hints import FeatureSet
from caldav.lib.error import AuthorizationError, PutError, ReportError

from caldav_server_tester.checks import PrepareCalendar

FEATURE = "save-load.event.recurrences.exception"
IN_SEARCH = "search.recurrences.exception.in-calendar-data"
UID = "csc_monthly_recurring_with_exception"
URL = "http://example.com/cal/csc_monthly_recurring_with_exception.ics"


def _obj(uid=UID, vevents=2):
def _cal(uid, vevents):
cal = icalendar.Calendar()
for _ in range(vevents):
ev = icalendar.Event()
ev.add("uid", uid)
cal.add_component(ev)
return cal


def _obj(uid=UID, vevents=2, stored=None, get_error=None):
"""An object as the listing has it, with ``vevents`` VEVENTs; a GET
(``load()``) gives it ``stored`` VEVENTs, the same number by default."""
obj = Mock()
obj.icalendar_instance = cal
obj.icalendar_component = cal.subcomponents[0]
obj.icalendar_instance = _cal(uid, vevents)
obj.icalendar_component = obj.icalendar_instance.subcomponents[0]

def load(*args, **kwargs):
obj.load_kwargs = kwargs
if get_error is not None:
raise get_error
obj.icalendar_instance = _cal(uid, vevents if stored is None else stored)
return obj

obj.load.side_effect = load
return obj


Expand All @@ -39,7 +62,7 @@ def _unparsable():
return obj


def _run(add=None, listing=None, listing_error=None):
def _run(add=None, listing=None, listing_error=None, feature=FEATURE):
checker = Mock()
checker._features_checked = FeatureSet()
checker.debug_mode = None
Expand All @@ -52,7 +75,19 @@ def _run(add=None, listing=None, listing_error=None):
if add is not None:
add_if_not_existing.side_effect = add
PrepareCalendar(checker)._store_recurrence_with_exception(calendar, add_if_not_existing, 2027)
return checker._features_checked.is_supported(FEATURE, dict)
return checker._features_checked.is_supported(feature, dict)


def _run_both(**kwargs):
"""Both verdicts: save-load first, then the search one."""
checker = Mock()
checker._features_checked = FeatureSet()
checker.debug_mode = None
calendar = Mock()
calendar.events.return_value = kwargs.pop("listing")
PrepareCalendar(checker)._store_recurrence_with_exception(calendar, Mock(), 2027)
fs = checker._features_checked
return fs.is_supported(FEATURE, dict), fs.is_supported(IN_SEARCH, dict)


def test_master_and_exception_kept_together_is_full():
Expand Down Expand Up @@ -120,3 +155,65 @@ def test_own_object_missing_from_the_listing_is_unknown():
observed = _run(listing=[_obj(uid="csc_something_else")])
assert observed["support"] == "unknown"
assert "listing" in observed["behaviour"]


def test_a_search_dropping_the_exception_is_not_a_storage_failure():
"""Bedework: the listing holds the master only, a GET has both."""
stored, in_search = _run_both(listing=[_obj(vevents=1, stored=2)])
assert stored["support"] == "full"
assert in_search["support"] == "unsupported"
assert "master only" in in_search["behaviour"]


def test_a_search_with_the_whole_object_is_full():
stored, in_search = _run_both(listing=[_obj()])
assert stored["support"] == "full"
assert in_search["support"] == "full"


def test_an_exception_not_stored_is_graded_on_the_get():
stored, in_search = _run_both(listing=[_obj(vevents=1, stored=1)])
assert stored["support"] == "unsupported"
assert in_search["support"] == "unknown"


def test_split_objects_leave_the_search_verdict_unknown():
stored, in_search = _run_both(listing=[_obj(vevents=1), _obj(vevents=1)])
assert stored["support"] == "unsupported"
assert in_search["support"] == "unknown"


def test_a_failed_get_is_unknown():
stored, in_search = _run_both(
listing=[_obj(vevents=1, get_error=niquests.exceptions.ConnectionError("Connection reset by peer"))]
)
assert stored["support"] == "unknown"
assert "GET" in stored["behaviour"]
assert in_search["support"] == "unknown"


@pytest.mark.parametrize(
"kwargs",
[
{"add": PutError("400 Bad Request")},
{"listing_error": ReportError("500 Internal Server Error")},
{"listing": [_obj(uid="csc_something_else")]},
],
ids=["put-refused", "listing-failed", "not-listed"],
)
def test_every_early_exit_grades_the_search_feature_too(kwargs):
"""PrepareCalendar asserts that every feature it declares got a verdict."""
observed = _run(feature=IN_SEARCH, **kwargs)
assert observed["support"] == "unknown"
assert observed["behaviour"]


def test_the_stored_event_is_read_by_the_get_alone():
"""load() falls back to a multiget, and after a 404 to a search by UID:
the probe would then compare a search with a search."""
obj = _obj(vevents=1, stored=2)
_run_both(listing=[obj])
if "fallbacks" in inspect.signature(CalendarObjectResource.load).parameters:
assert obj.load_kwargs == {"fallbacks": False}
else:
assert obj.load_kwargs == {"multiget_fallback": False}
Loading