diff --git a/CHANGELOG.md b/CHANGELOG.md index 29c0388..87655b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ This release works with caldav 3.7.0: the tester carries the definitions of the - **`save-load.icalendar.olson-tzid`** - whether an event with `TZID=Asia/Tokyo` and no VTIMEZONE is placed in Tokyo time, judged by time-range searches in UTC; the behaviour says whether the server adds a VTIMEZONE of its own. Where `full`, a client may leave the VTIMEZONE out. The event is compared with the same event carrying its VTIMEZONE and with one at 12:00 UTC, so a search that misplaces zoned times or only matches start times does not stop the probe from reaching a verdict. caldav does not define this feature yet, so the tester adds its definition itself until a caldav release has it. See https://github.com/python-caldav/caldav/issues/849. - **`search.time-range.event.overlap`** and **`search.time-range.todo.overlap`** - whether a time-range search finds an event or task that overlaps the range without starting inside it (RFC 4791 section 9.9): one range inside the object, one straddling its end. Robur only finds events whose DTSTART is in the range, Cyrus and GMX only tasks whose DTSTART is. - **`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. ### Fixed diff --git a/src/caldav_server_tester/checks.py b/src/caldav_server_tester/checks.py index 604471f..c68b899 100644 --- a/src/caldav_server_tester/checks.py +++ b/src/caldav_server_tester/checks.py @@ -5453,6 +5453,44 @@ def _grade(self, raw): return self._graded("full", *defaults) +class CheckAttendeeOnce(_RoundTrip, Check): + """ + Checks whether each ATTENDEE of an event comes back once. Bedework 5 + stores every ATTENDEE twice, as an exact copy; caldav drops such a copy + when it reads the data, so that is a quirk. Copies that differ are + broken. A dropped attendee is attendee-params' business: unknown here. + """ + + depends_on = {PrepareCalendar} + LABEL = "attendee-once" + FEATURE = "save-load.icalendar.attendee-once" + features_to_be_checked = {FEATURE} + UID = "csc_attendee_once" + WHAT = "an event with attendees" + EXTRA = CheckAttendeeParams.EXTRA + + def _grade(self, raw): + stored = [line for line in component_lines(raw, "VEVENT") if line.upper().startswith("ATTENDEE")] + by_address = {} + for line in stored: + address, _ = CheckAttendeeParams._parse(line) + by_address.setdefault(address, []).append(line) + sent = list(CheckAttendeeParams.ATTENDEES) + if not set(sent) <= set(by_address): + return self._graded("unknown", "cannot test, the attendees are not all stored") + ## An attendee the server adds (the owner, say) is not graded + copies = {address: by_address[address] for address in sent if len(by_address[address]) > 1} + if not copies: + return "full" + if any(len(set(lines)) > 1 for lines in copies.values()): + return self._graded("broken", "an ATTENDEE comes back more than once, the copies differing") + counts = {len(lines) for lines in copies.values()} + times = "twice" if counts == {2} else " or ".join(f"{n} times" for n in sorted(counts)) + if len(copies) < len(sent): + return self._graded("quirk", f"stored {times}: {', '.join(sorted(copies))}") + return self._graded("quirk", f"stored {times}") + + class CheckParticipant(_RoundTrip, Check): """ Checks whether a PARTICIPANT component (RFC 9073 section 7.1) inside a diff --git a/src/caldav_server_tester/future_features.py b/src/caldav_server_tester/future_features.py index d8f5754..c4a852f 100644 --- a/src/caldav_server_tester/future_features.py +++ b/src/caldav_server_tester/future_features.py @@ -15,6 +15,11 @@ from caldav.compatibility_hints import FeatureSet FUTURE_FEATURES: dict[str, dict] = { + ## 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.", + "default": {"support": "full"}, + }, ## caldav PR 861 (https://github.com/python-caldav/caldav/pull/861) "url.encode-at.encoded.href": { "description": "Whether '%40' resolves in an href inside a REPORT body (a calendar-multiget), as it does in the request path. RFC4918 section 8.3 makes such an href a URI reference, so the server should decode it as it decodes the path. 'unsupported' is the Robur case: a GET of '.../foo%40example.com.ics' serves the object, a multiget naming the same href answers 404, and a multiget naming '.../foo@example.com.ics' finds it.", diff --git a/tests/test_attendee_once.py b/tests/test_attendee_once.py new file mode 100644 index 0000000..f4ce525 --- /dev/null +++ b/tests/test_attendee_once.py @@ -0,0 +1,119 @@ +"""Whether each ATTENDEE of an event comes back once. + +Bedework 5 stores every ATTENDEE twice: one line sent, two identical lines +back. caldav drops the exact copy when it reads the data, so that is a quirk; +copies that differ would be broken. +""" + +from unittest.mock import Mock + +from caldav.compatibility_hints import FeatureSet + +from caldav_server_tester.checks import CheckAttendeeOnce +from tests.test_attendee_params import RewritingServer + +BASE = "http://example.com/cal/" +FEATURE = "save-load.icalendar.attendee-once" + + +class DuplicatingServer(RewritingServer): + """Bedework 5's way: every ATTENDEE line is stored twice.""" + + def __init__(self, copy=lambda line: line, **kwargs): + super().__init__(**kwargs) + self.copy = copy + + def put(self, url, body, headers=None): + lines = [] + for line in body.split("\r\n"): + lines.append(line) + if line.startswith("ATTENDEE"): + lines.append(self.copy(line)) + return super().put(url, "\r\n".join(lines), headers) + + +def _run(server): + checker = Mock() + checker._features_checked = FeatureSet() + checker.debug_mode = None + checker._client_obj = server + checker.fixture_base_year = 2027 + checker.calendar.url.join.side_effect = lambda name: BASE + name + CheckAttendeeOnce(checker)._run_check() + return checker._features_checked.is_supported(FEATURE, return_type=dict) + + +def test_once_is_full(): + server = RewritingServer() + assert _run(server) == {"support": "full"} + assert not server.objects + + +def test_bedework_5_is_a_quirk(): + verdict = _run(DuplicatingServer()) + assert verdict["support"] == "quirk" + assert verdict["behaviour"] == "stored twice" + + +def test_copies_that_differ_are_broken(): + verdict = _run(DuplicatingServer(copy=lambda line: line.replace(":mailto", ";RSVP=TRUE:mailto"))) + assert verdict["support"] == "broken" + + +def test_a_dropped_attendee_cannot_tell(): + verdict = _run(RewritingServer(rewrite=lambda line: None)) + assert verdict["support"] == "unknown" + + +def test_a_refused_event_is_ungraceful(): + assert _run(RewritingServer(put_status=403))["support"] == "ungraceful" + + +def test_one_attendee_doubled_names_it(): + server = DuplicatingServer() + server.put = _copy_only(server, "csc-bob") + verdict = _run(server) + assert verdict["support"] == "quirk" + assert "csc-bob" in verdict["behaviour"] and "csc-ase" not in verdict["behaviour"] + assert not server.objects + + +def test_three_copies_say_so(): + server = DuplicatingServer(copy=lambda line: line + "\r\n" + line) + verdict = _run(server) + assert verdict == {"support": "quirk", "behaviour": "stored 3 times"} + assert not server.objects + + +def test_an_attendee_the_server_adds_is_no_obstacle(): + """Some servers add the owner; the sent attendees are what is graded.""" + server = DuplicatingServer() + original = server.put + + def put(url, body, headers=None): + body = body.replace("END:VEVENT", "ATTENDEE:mailto:owner@example.com\r\nEND:VEVENT") + return original(url, body, headers) + + server.put = put + assert _run(server)["support"] == "quirk" + + +def test_broken_copies_are_cleaned_up(): + server = DuplicatingServer(copy=lambda line: line.replace(":mailto", ";RSVP=TRUE:mailto")) + _run(server) + assert not server.objects + + +def _copy_only(server, who): + """A put that stores a copy of one attendee's line only.""" + original = RewritingServer.put.__get__(server) + + def put(url, body, headers=None): + lines = [] + for line in body.split("\r\n"): + lines.append(line) + if line.startswith("ATTENDEE") and who in line: + lines.append(line) + return original(url, "\r\n".join(lines), headers) + + return put