diff --git a/CHANGELOG.md b/CHANGELOG.md index 118076c..a2a8d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,16 @@ This library is tightly dependent on the CalDAV-library, particularly the `compa ## Unreleased -This release works with caldav 3.7.0. +This release works with caldav 3.7.0: the tester carries the definitions of the features below that caldav has not released yet. ### Added - **`move`**, **`move.overwrite`** and **`move.if-match`** - whether WebDAV MOVE (RFC 4918 section 9.9) moves an object into another calendar, whether a MOVE with `Overwrite: F` onto an existing object fails with 412 as RFC 4918 requires, and whether one with an outdated If-Match does. caldav does not define these features yet, so the tester adds their definitions itself until a caldav release has them. Radicale and Xandikos ignore the If-Match, Zimbra and SOGo also ignore `Overwrite: F`, and Bedework refuses the MOVE. See https://github.com/python-caldav/caldav/issues/841 and https://github.com/python-caldav/caldav-server-tester/issues/50. +- **`save-load.todo.status`**, **`save-load.todo.status.rfc10051`** and **`save-load.todo.priority`** - which STATUS values (RFC 5545's four; PENDING and FAILED from RFC 10051 apart) and which PRIORITY values (0 to 9) a task keeps, with the extra keys `values`, `map` and `refused`. Ox drops PENDING and FAILED and keeps priorities 1, 5 and 9 only; Zimbra stores PENDING and FAILED as NEEDS-ACTION and refuses CANCELLED. PRIORITY:0 dropped is `full`: no PRIORITY means the same. +- **`supported-task-modes`** - whether the server advertises RFC 10051 with `CALDAV:supported-task-mode-set` on the calendar home or a calendar. Neither Ox nor Zimbra does, and the RFC 10051 status verdict says so. +- **`save-load.icalendar.x-parameter`** - whether an X- parameter on SUMMARY is stored, in an event and then in a task. Ox and Zimbra drop it from the event. +- **`multiget.deleted`** - whether a calendar-multiget answers a deleted object as missing. Zimbra still returns its data, while a GET answers 404. +- **`save-load.stable-url`** also stores a task under a name that is not its UID, and records `uid_ics_components: [VTODO]` where only the task is renamed `.ics` (Ox). ### Fixed diff --git a/src/caldav_server_tester/checks.py b/src/caldav_server_tester/checks.py index 5d149e2..33610c6 100644 --- a/src/caldav_server_tester/checks.py +++ b/src/caldav_server_tester/checks.py @@ -2328,20 +2328,22 @@ class this suite probes as ``non-existing-raises-not-found`` broken - return uid return False - def _probe_ical(self, uid, label): - """The one-event calendar the PUT-based probes store, in the fixture window.""" + def _probe_ical(self, uid, label, todo=False): + """The one-event calendar the PUT-based probes store, in the fixture + window; with ``todo``, a task due when the event would end.""" year = self.checker.fixture_base_year + component = "VTODO" if todo else "VEVENT" return ( "BEGIN:VCALENDAR\r\n" "VERSION:2.0\r\n" f"PRODID:-//caldav-server-tester//{label} probe//EN\r\n" - "BEGIN:VEVENT\r\n" + f"BEGIN:{component}\r\n" f"UID:{uid}\r\n" f"DTSTAMP:{year}0119T120000Z\r\n" f"DTSTART:{year}0119T120000Z\r\n" - f"DTEND:{year}0119T130000Z\r\n" + f"{'DUE' if todo else 'DTEND'}:{year}0119T130000Z\r\n" f"SUMMARY:{label} probe\r\n" - "END:VEVENT\r\n" + f"END:{component}\r\n" "END:VCALENDAR\r\n" ) @@ -3118,6 +3120,24 @@ def _check_stable_url(self, calendar): self.set_feature("save-load.stable-url", node) return + ## Ox keeps an event's name and names a task .ics + task_name = self._task_reported_name() + tasks_renamed = task_name == f"{STABLE_URL_PROBE_UID}.ics" + task_note = ( + f"a task stored as {STABLE_URL_PROBE_NAME!r} is reported as .ics, while an event keeps its name" + ) + if task_name is not None and not tasks_renamed: + self.set_feature( + "save-load.stable-url", + { + "support": "unsupported", + "behaviour": ( + f"a task stored as {STABLE_URL_PROBE_NAME!r} is reported under the name {task_name!r}, " + "while an event keeps its name; a client cannot construct the URL of a task it saved" + ), + }, + ) + return if relocated: ## Quote what create-calendar.stable-url observed rather than ## restating one server's flavour of it: OX leaves a second working @@ -3135,15 +3155,24 @@ def _check_stable_url(self, calendar): + (f": {observed}" if observed else "") + "), so a constructed object URL resolves only from the address the " "server reports objects under, and a client may be holding another one" + + (f"; {task_note}" if tasks_renamed else "") ), + **({"uid_ics_components": ["VTODO"]} if tasks_renamed else {}), }, ) return + if tasks_renamed: + self.set_feature( + "save-load.stable-url", + {"support": "unsupported", "behaviour": task_note, "uid_ics_components": ["VTODO"]}, + ) + return + client_url = calendar.url.join(stored_as) self.set_feature("save-load.stable-url", server_event.url.canonical() == client_url.canonical()) - def _probe_stored_name(self, calendar): + def _probe_stored_name(self, calendar, todo=False): """Does the server keep the name an object was PUT under? Storing ``.ics`` cannot tell a server that keeps the name from @@ -3159,7 +3188,7 @@ def _probe_stored_name(self, calendar): port, and the docker image redirects to its internal one. The name is read from the Location, whatever its host and port. """ - ical = self._probe_ical(STABLE_URL_PROBE_UID, "save-load.stable-url") + ical = self._probe_ical(STABLE_URL_PROBE_UID, "save-load.stable-url", todo=todo) urls = [calendar.url.join(STABLE_URL_PROBE_NAME), calendar.url.join(f"{STABLE_URL_PROBE_UID}.ics")] try: response = self.client.put(str(urls[0]), ical, {"Content-Type": "text/calendar; charset=utf-8"}) @@ -3188,6 +3217,14 @@ def _probe_stored_name(self, calendar): return None return STABLE_URL_PROBE_NAME, reported_name + def _task_reported_name(self): + """The name a task PUT under another name is reported under, where the server renamed it, else None""" + tasklist = getattr(self.checker, "tasklist", None) + if tasklist is None: + return None + renamed = self._probe_stored_name(tasklist, todo=True) + return renamed[1] if renamed is not None else None + @staticmethod def _fixtures_by_uid(objects, base): """Map UID to object for what a previous run left in the fixture window. @@ -5574,6 +5611,229 @@ def _grade(self, raw): return self._kept(raw, "COMPLETED") +class _ValueSweep(_RoundTrip): + """Stores a task with each of ``VALUES`` for property ``NAME`` in turn, and + records which are kept, which are stored as another, and which are + refused: ``values``, ``map`` and ``refused`` in the verdict.""" + + COMPONENTS = ("VTODO",) + NAME = "" + VALUES = () + ## A value whose property may be dropped without changing the meaning + SAME_AS_ABSENT = None + + @property + def uid(self): + return f"{self.UID}_{str(self.value).lower()}" + + @property + def WHAT(self): + return str(self.value) + + @property + def EXTRA(self): + return f"{self.NAME}:{self.value}\r\n" + + def _grade(self, raw): + for line in component_lines(raw, self.component): + match = re.match(rf"{self.NAME}(?:;[^:]*)?:(.*)", line, re.IGNORECASE) + if match: + stored = match[1].strip().upper() + if isinstance(self.value, int) and stored.isdigit(): + stored = int(stored) + return ("stored", stored) + return ("stored", None) + + def _run_check(self) -> None: + skipped = self._tasks_unstorable() + if skipped: + if skipped != self.CANNOT_STORE: + self.set_feature(self.FEATURE, self._graded("unknown", f"cannot test, {skipped}")) + return + self.component = "VTODO" + kept, mapped, refused, notes = [], {}, [], [] + for value in self.VALUES: + self.value = value + verdict = self._round_trip() + if isinstance(verdict, tuple): + stored = verdict[1] + if stored == value: + kept.append(value) + elif stored is None and value == self.SAME_AS_ABSENT: + kept.append(value) + notes.append(f"{value} is dropped, which means the same") + elif stored is None: + notes.append(f"{value} is dropped") + else: + mapped[value] = stored + notes.append(f"{value} is stored as {stored}") + elif verdict.get("support") == "ungraceful": + refused.append(value) + notes.append(verdict["behaviour"]) + else: + self.set_feature(self.FEATURE, verdict) + return + if len(kept) == len(self.VALUES): + self.set_feature(self.FEATURE, self._graded("full", *notes)) + return + support = "ungraceful" if refused else "unsupported" + self.set_feature( + self.FEATURE, + {**self._graded(support, *notes, *self._unkept_notes()), "values": kept, "map": mapped, "refused": refused}, + ) + + def _unkept_notes(self): + """More to say where not every value is kept""" + return [] + + +class CheckTodoStatus(_ValueSweep, Check): + """ + Checks which of RFC 5545's four STATUS values a task keeps. Zimbra + refuses CANCELLED. + """ + + depends_on = {PrepareCalendar} + LABEL = "todo-status" + FEATURE = "save-load.todo.status" + features_to_be_checked = {FEATURE} + UID = "csc_status_task" + NAME = "STATUS" + VALUES = ("NEEDS-ACTION", "IN-PROCESS", "COMPLETED", "CANCELLED") + + +class CheckSupportedTaskModes(Check): + """ + Checks whether the server advertises RFC 10051 with the + CALDAV:supported-task-mode-set property (section 13.1), on the calendar + home or the task calendar. Without it, a client must assume the server + does not support RFC 10051. Neither Ox nor Zimbra has it. + """ + + depends_on = {PrepareCalendar} + FEATURE = "supported-task-modes" + features_to_be_checked = {FEATURE} + BODY = ( + '' + '' + "" + ) + SET = "{urn:ietf:params:xml:ns:caldav}supported-task-mode-set" + MODE = "{urn:ietf:params:xml:ns:caldav}supported-task-mode" + + def _run_check(self) -> None: + urls = [] + try: + urls.append(self.checker.principal.calendar_home_set.url) + except Exception: ## no principal, or a home-set PROPFIND that failed: ask the calendar alone + pass + if getattr(self.checker, "tasklist", None) is not None: + urls.append(self.checker.tasklist.url) + answered = False + for url in urls: + try: + response = self.client.request(str(url), "PROPFIND", self.BODY, {"Depth": "0"}) + except (DAVError, OSError): + continue + if response.status != 207 or response.tree is None: + continue + answered = True + modes = self._modes(response.tree) + if modes: + self.set_feature(self.FEATURE, {"support": "full", "values": modes}) + return + if not answered: + self.set_feature( + self.FEATURE, {"support": "unknown", "behaviour": "cannot test, the PROPFIND for it failed"} + ) + return + self.set_feature( + self.FEATURE, + { + "support": "unsupported", + "behaviour": "neither the calendar home nor a calendar has CALDAV:supported-task-mode-set", + }, + ) + + def _modes(self, tree): + """The modes listed in a property answered with 200; an empty set lists none""" + for propstat in tree.findall(f".//{dav.PropStat.tag}"): + status = propstat.find(dav.Status.tag) + if status is None or " 200 " not in f"{status.text} ": + continue + for found in propstat.iter(self.SET): + return [(m.text or "").strip() for m in found.iter(self.MODE)] + return [] + + +class CheckTodoStatusRfc10051(_ValueSweep, Check): + """ + Checks whether a task keeps the statuses RFC 10051 adds, PENDING and + FAILED. Ox drops them; Zimbra stores them as NEEDS-ACTION. Neither + advertises RFC 10051, which the behaviour then says. + """ + + depends_on = {PrepareCalendar, CheckSupportedTaskModes} + LABEL = "todo-status-rfc10051" + FEATURE = "save-load.todo.status.rfc10051" + features_to_be_checked = {FEATURE} + UID = "csc_status_rfc10051_task" + NAME = "STATUS" + VALUES = ("PENDING", "FAILED") + + def _unkept_notes(self): + recorded = self.checker.features_checked.dotted_feature_set_list().get(CheckSupportedTaskModes.FEATURE) or {} + if recorded.get("support") == "unsupported": + return ["the server does not advertise RFC 10051"] + if recorded.get("support") == "full": + return ["although the server advertises RFC 10051"] + return [] + + +class CheckTodoPriority(_ValueSweep, Check): + """ + Checks which PRIORITY values, 0 to 9, a task keeps. Ox keeps 1, 5 and 9 + only. PRIORITY:0 is no priority given, so dropping it changes nothing. + """ + + depends_on = {PrepareCalendar} + LABEL = "todo-priority" + FEATURE = "save-load.todo.priority" + features_to_be_checked = {FEATURE} + UID = "csc_priority_task" + NAME = "PRIORITY" + VALUES = tuple(range(10)) + SAME_AS_ABSENT = 0 + + +class CheckXParameter(_RoundTrip, Check): + """ + Checks whether an X- parameter on a standard property (SUMMARY) is + stored, in an event and then in a task. Ox and Zimbra drop it, so the + task is not probed there: the verdict names the first component that + lost it. + """ + + depends_on = {PrepareCalendar} + LABEL = "x-parameter" + FEATURE = "save-load.icalendar.x-parameter" + features_to_be_checked = {FEATURE} + UID = "csc_x_parameter" + WHAT = "an object with an X- parameter" + COMPONENTS = ("VEVENT", "VTODO") + + def _body(self): + return super()._body().replace("\r\nSUMMARY:", "\r\nSUMMARY;X-CALDAV-SERVER-TESTER=kept:", 1) + + def _grade(self, raw): + for line in component_lines(raw, self.component): + if re.match(r"SUMMARY[;:]", line, re.IGNORECASE): + if re.search(r";X-CALDAV-SERVER-TESTER=\"?kept\"?[;:]", line, re.IGNORECASE): + return "full" + return self._graded("unsupported", "X-CALDAV-SERVER-TESTER on SUMMARY is dropped") + return self._graded("unknown", "cannot test, the object came back without SUMMARY") + + class CheckAttendeePartstat(Check): """ Checks whether an attendee's PARTSTAT can be modified via a direct PUT. @@ -7965,13 +8225,15 @@ class CheckMultiget(_RawPut, _RawSync, Check): depends_on = {PrepareCalendar} LABEL = "multiget" MISSING_HREF = "multiget.missing-href" + DELETED = "multiget.deleted" LIMIT = "multiget.limit" PROPFIND_LIMIT = "propfind.limit" SEARCH_LIMIT = "search.limit" - features_to_be_checked = {MISSING_HREF, LIMIT, PROPFIND_LIMIT, SEARCH_LIMIT} + features_to_be_checked = {MISSING_HREF, DELETED, LIMIT, PROPFIND_LIMIT, SEARCH_LIMIT} ENV = "CALDAV_SERVER_TESTER_LIMIT_OBJECTS" PRESENT = "csc_multiget_present" ABSENT = "csc_multiget_missing" + GONE = "csc_multiget_deleted" PROPFIND = ( '' ) @@ -7983,11 +8245,13 @@ def _run_check(self) -> None: self._delete(self._url(self.ABSENT)) try: if self._ok(self._put(present, self._ical(self.PRESENT))): - self.set_feature(self.MISSING_HREF, self._grade_missing()) + self.missing = self._grade_missing() + self.set_feature(self.MISSING_HREF, self.missing) else: self.set_feature(self.MISSING_HREF, None) finally: self._delete(present) + self.set_feature(self.DELETED, self._grade_deleted()) count = self._object_count() if not count: for feature in (self.LIMIT, self.PROPFIND_LIMIT, self.SEARCH_LIMIT): @@ -8030,6 +8294,28 @@ def _grade_missing(self): return self._graded("full", f"a missing href is answered with {statuses[0]}") return "full" + def _grade_deleted(self): + """Zimbra answers a GET of a deleted object with 404 and a multiget of it with the old data""" + missing = getattr(self, "missing", None) + if isinstance(missing, dict) and missing.get("support") == "broken": + return self._graded("unknown", "cannot test, a missing href is answered as if it existed too") + gone = self._url(self.GONE) + try: + if not self._ok(self._put(gone, self._ical(self.GONE))): + return None + if not self._ok(self._answer(self.client.delete, gone)): + return self._graded("unknown", "cannot test, the object could not be deleted") + if self._status(self._answer(self.client.request, gone)) != 404: + return self._graded("unknown", "cannot test, a GET of the deleted object did not answer 404") + (entries, _) = self._multiget((self.GONE,)) + except (DAVError, ReportError) as e: + return self._graded("unknown", f"cannot test, the multiget failed: {e}") + finally: + self._delete(gone) + if any(name == f"{self.GONE}.ics" and status is None for name, status in entries): + return self._graded("broken", "a deleted object is still returned by a multiget, while a GET answers 404") + return "full" + def _probe_limits(self, count) -> None: names = [f"csc_limit_{i:05d}" for i in range(count)] try: diff --git a/src/caldav_server_tester/future_features.py b/src/caldav_server_tester/future_features.py index 1d64495..95b801f 100644 --- a/src/caldav_server_tester/future_features.py +++ b/src/caldav_server_tester/future_features.py @@ -26,6 +26,52 @@ "move.if-match": { "description": "A MOVE with an If-Match the object no longer has fails with 412 and moves nothing (RFC 9110 section 13.1.1). Where unsupported, a MOVE cannot guard against an object changed since it was read." }, + ## caldav PR 848 (https://github.com/python-caldav/caldav/pull/848) + "save-load.todo.status": { + "description": "Each STATUS RFC 5545 section 3.8.1.11 gives a task (NEEDS-ACTION, IN-PROCESS, COMPLETED, CANCELLED) is stored as sent. 'unsupported' when one is dropped or stored as another, 'ungraceful' when a task with one is refused, the worse of the two where both apply; the extra keys say which. Zimbra refuses CANCELLED. The statuses RFC 10051 adds are save-load.todo.status.rfc10051.", + "default": {"support": "full"}, + "extra_keys": { + "values": "The statuses stored as sent.", + "map": "A status, to the one stored instead.", + "refused": "The statuses a task is refused with.", + }, + "links": ["https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.1.11"], + }, + "save-load.todo.status.rfc10051": { + "description": "The statuses RFC 10051 adds for a task, PENDING and FAILED, are stored as sent. Graded and keyed as save-load.todo.status. A profile stating save-load.todo.status states this one too: without it, this feature would answer with the parent's node, values and all. A server not advertising RFC 10051 (supported-task-modes) need not keep them, and the behaviour says so: Ox drops both, Zimbra stores both as NEEDS-ACTION, and neither advertises it. 'unknown' by default, as for supported-task-modes: an optional extension is not assumed on a server not probed.", + "default": {"support": "unknown"}, + "extra_keys": { + "values": "The statuses stored as sent.", + "map": "A status, to the one stored instead.", + "refused": "The statuses a task is refused with.", + }, + "links": ["https://datatracker.ietf.org/doc/html/rfc10051"], + }, + "save-load.todo.priority": { + "description": "Each PRIORITY from 0 to 9 (RFC 5545 section 3.8.1.9) is stored as sent. PRIORITY:0 means no priority given, so a server dropping it changes nothing. 'unsupported' when one is dropped or stored as another, 'ungraceful' when a task with one is refused, the worse of the two where both apply; the extra keys say which, with the priorities as integers. Ox keeps 1, 5 and 9 only: it stores 2 as 1, 0 and 3 to 6 as 5, and 7 and 8 as 9.", + "default": {"support": "full"}, + "extra_keys": { + "values": "The priorities stored as sent.", + "map": "A priority, to the one stored instead.", + "refused": "The priorities a task is refused with.", + }, + "links": ["https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.1.9"], + }, + "supported-task-modes": { + "description": "The server advertises the CALDAV:supported-task-mode-set property (RFC 10051 section 13.1) on the calendar home or a calendar, which is how it says it supports RFC 10051. Without it a client must assume the server does not. 'unsupported' when neither has it (Ox, Zimbra); the extra key values lists the TASK-MODE values advertised. 'unknown' by default: few servers advertise it, but one not probed is not known to lack it.", + "default": {"support": "unknown"}, + "extra_keys": {"values": "The TASK-MODE values the property lists."}, + "links": ["https://datatracker.ietf.org/doc/html/rfc10051#section-13.1"], + }, + "save-load.icalendar.x-parameter": { + "description": "An X- parameter (RFC 5545 section 3.2) on a standard property is stored with it, in an event and in a task. 'unsupported' when it is dropped (Ox and Zimbra drop SUMMARY's); the behaviour names the first component it was dropped from.", + "default": {"support": "full"}, + "links": ["https://datatracker.ietf.org/doc/html/rfc5545#section-3.2"], + }, + "multiget.deleted": { + "description": "A calendar-multiget naming an object that was deleted answers it as missing, as a GET does. 'broken' when it still returns the object's data after the DELETE succeeded and a GET answers 404, so a client fetching by multiget sees deleted objects.", + "default": {"support": "full"}, + }, } diff --git a/tests/test_icalendar_roundtrip.py b/tests/test_icalendar_roundtrip.py index 106697c..32f8b8f 100644 --- a/tests/test_icalendar_roundtrip.py +++ b/tests/test_icalendar_roundtrip.py @@ -12,7 +12,7 @@ from caldav.compatibility_hints import FeatureSet from caldav.lib.error import AuthorizationError -from caldav_server_tester.checks import CheckParticipant, CheckVtimezone, CheckXProperty +from caldav_server_tester.checks import CheckParticipant, CheckVtimezone, CheckXParameter, CheckXProperty from .test_floating_event import RewritingServer @@ -148,3 +148,17 @@ def test_unread_without_a_status_says_so_plainly(check): verdict = _run(check, RewritingServer(get_status=503)) assert verdict["support"] == "unknown" assert "None" not in verdict["behaviour"] + + +def test_x_parameter_kept_is_full_and_sent_on_summary(): + sent = [] + assert _run(CheckXParameter, RewritingServer(rewrite=lambda body: sent.append(body) or body))["support"] == "full" + assert all("\r\nSUMMARY;X-CALDAV-SERVER-TESTER=kept:" in body for body in sent) + assert len(sent) == 2, "an event and a task" + + +def test_x_parameter_dropped_is_unsupported(): + """Ox and Zimbra""" + verdict = _run(CheckXParameter, RewritingServer(rewrite=lambda b: b.replace(";X-CALDAV-SERVER-TESTER=kept", ""))) + assert verdict["support"] == "unsupported" + assert "in an event" in verdict["behaviour"] diff --git a/tests/test_multiget.py b/tests/test_multiget.py index c022f48..cad6a42 100644 --- a/tests/test_multiget.py +++ b/tests/test_multiget.py @@ -21,6 +21,7 @@ BASE = "http://example.com/cal/" MISSING = "multiget.missing-href" +DELETED = "multiget.deleted" LIMIT = "multiget.limit" PROPFIND = "propfind.limit" SEARCH = "search.limit" @@ -45,7 +46,10 @@ def __init__( missing_as=None, propfind_status=None, query_status=207, + keeps_deleted=False, ): + self.keeps_deleted = keeps_deleted + self.deleted = set() self.query_status = query_status self.propfind_status = propfind_status self.missing_as = missing_as @@ -67,6 +71,8 @@ def put(self, url, body, headers=None): return Mock(status=201, headers={}) def delete(self, url, headers=None): + if self._name(url) in self.objects: + self.deleted.add(self._name(url)) self.objects.discard(self._name(url)) return Mock(status=204) @@ -78,7 +84,8 @@ def report(self, url, body, depth=0): if self.report_status != 207: return Mock(status=self.report_status, tree=None, raw="") names = [self._name(h) for h in re.findall(r"(.*?)", body)] - entries = [(n, None if n in self.objects else (self.missing_as or 404)) for n in names] + served = self.objects | (self.deleted if self.keeps_deleted else set()) + entries = [(n, None if n in served else (self.missing_as or 404)) for n in names] if self.omit_missing: entries = [e for e in entries if e[1] is None] return self._answer(entries) @@ -92,6 +99,8 @@ def propfind(self, url, props=None, depth=0): def request(self, url, method="GET", body="", headers=None): """The raw answer, left unparsed""" + if method == "GET": + return Mock(status=200 if self._name(url) in self.objects else 404, headers={}) assert method == "PROPFIND" if self.propfind_raises: raise self.propfind_raises @@ -141,7 +150,7 @@ def _run(server, monkeypatch, objects=None): checker.calendar.url = URL.objectify(BASE) CheckMultiget(checker)._run_check() fs = checker._features_checked - return {f: fs.is_supported(f, return_type=dict) for f in (MISSING, LIMIT, PROPFIND, SEARCH)} + return {f: fs.is_supported(f, return_type=dict) for f in (MISSING, DELETED, LIMIT, PROPFIND, SEARCH)} def test_a_404_entry_for_the_missing_href_is_full(monkeypatch): @@ -175,6 +184,19 @@ def test_a_missing_href_answered_otherwise_names_the_status(monkeypatch): } +def test_a_deleted_object_answered_as_missing_is_full(monkeypatch): + server = MultigetServer() + assert _run(server, monkeypatch)[DELETED] == {"support": "full"} + assert not server.objects + + +def test_a_deleted_object_still_served_is_broken(monkeypatch): + """Zimbra: the GET answers 404, the multiget the old data""" + verdict = _run(MultigetServer(keeps_deleted=True), monkeypatch)[DELETED] + assert verdict["support"] == "broken" + assert "404" in verdict["behaviour"] + + def test_a_failing_multiget_is_ungraceful(monkeypatch): assert _run(MultigetServer(report_status=400), monkeypatch)[MISSING]["support"] == "ungraceful" @@ -182,7 +204,7 @@ def test_a_failing_multiget_is_ungraceful(monkeypatch): def test_the_limits_are_not_probed_by_default(monkeypatch): server = MultigetServer() verdicts = _run(server, monkeypatch) - assert server.puts == 1 + assert server.puts == 2, "the present object, and the one deleted" for feature in (LIMIT, PROPFIND, SEARCH): assert verdicts[feature]["support"] == "unknown" assert ENV in verdicts[feature]["behaviour"] @@ -229,7 +251,7 @@ def test_an_unusable_object_count_does_not_probe(monkeypatch, value): checker.fixture_base_year = 2027 checker.calendar.url = URL.objectify(BASE) CheckMultiget(checker)._run_check() - assert server.puts == 1 + assert server.puts == 2, "the present object, and the one deleted" def test_a_propfind_answered_507_as_a_whole_is_unsupported(monkeypatch): @@ -255,3 +277,15 @@ def test_a_calendar_query_answered_507_as_a_whole_is_unsupported(monkeypatch): def test_a_failing_calendar_query_is_ungraceful(monkeypatch): assert _run(MultigetServer(query_status=500), monkeypatch, objects=12)[SEARCH]["support"] == "ungraceful" + + +def test_a_missing_href_answered_as_existing_leaves_deleted_unknown(monkeypatch): + """Then a deleted object answered with properties says nothing of deletion""" + verdict = _run(MultigetServer(missing_as="propstat 200", keeps_deleted=True), monkeypatch)[DELETED] + assert verdict["support"] == "unknown" + + +def test_a_deleted_object_still_readable_is_unknown(monkeypatch): + server = MultigetServer() + server.delete = lambda url, headers=None: Mock(status=204) # nothing is deleted + assert _run(server, monkeypatch)[DELETED]["support"] == "unknown" diff --git a/tests/test_stable_url_probe.py b/tests/test_stable_url_probe.py index a5c28dd..88a5a6f 100644 --- a/tests/test_stable_url_probe.py +++ b/tests/test_stable_url_probe.py @@ -39,6 +39,7 @@ def _make_checker(create_calendar_stable_url=None) -> Mock: checker._client_obj = Mock() checker._client_obj.features = FeatureSet() checker.expected_features = FeatureSet() + checker.tasklist = None return checker @@ -344,3 +345,62 @@ def test_a_redirect_elsewhere_says_nothing(self) -> None: def test_a_redirect_without_location_falls_back_to_the_lookup(self) -> None: node, _ = _name_probe(NAME_PROBE_UID + ".ics", put_status=302) assert node["forces_uid_ics"] is True + + +TASKS = "http://dav.example.com/caldav/tasks/" + + +def _task_probe(task_reported_as, create_calendar_stable_url=None) -> tuple[dict, Mock]: + """Events keep their name; a task PUT under the probe's name is reported as ``task_reported_as``""" + calendar, client = _name_probe_calendar(NAME_PROBE_NAME) + tasklist = Mock() + tasklist.url = URL.objectify(TASKS) + + def object_by_uid(uid): + obj = Mock() + obj.url = URL.objectify(TASKS + task_reported_as) + return obj + + tasklist.object_by_uid = object_by_uid + checker = _make_checker(create_calendar_stable_url) + checker._client_obj = client + checker.tasklist = tasklist + PrepareCalendar(checker)._check_stable_url(calendar) + return checker.features_checked.is_supported("save-load.stable-url", dict), client + + +class TestATaskStoredUnderAnArbitraryName: + """Ox keeps an event's name and names a task .ics.""" + + def test_a_task_named_uid_ics_is_unsupported_for_tasks_only(self) -> None: + node, client = _task_probe(NAME_PROBE_UID + ".ics") + assert node["support"] == "unsupported" + assert node["uid_ics_components"] == ["VTODO"] + assert "forces_uid_ics" not in node + assert "task" in node["behaviour"] + sent = [call.args[1] for call in client.put.call_args_list if str(call.args[0]).startswith(TASKS)] + assert sent and "BEGIN:VTODO" in sent[0] + + def test_a_task_keeping_its_name_changes_nothing(self) -> None: + node, _ = _task_probe(NAME_PROBE_NAME) + assert node["support"] == "full" + assert "uid_ics_components" not in node + + def test_a_relocated_collection_says_so_and_names_the_tasks(self) -> None: + """Ox: both at once""" + relocated = {"support": "unsupported", "behaviour": "an opaque cal://0/NNN"} + node, _ = _task_probe(NAME_PROBE_UID + ".ics", create_calendar_stable_url=relocated) + assert node["uid_ics_components"] == ["VTODO"] + assert "create-calendar.stable-url" in node["behaviour"] + assert "task" in node["behaviour"] + + def test_the_task_probe_is_removed(self) -> None: + _, client = _task_probe(NAME_PROBE_UID + ".ics") + deleted = {str(call.args[0]) for call in client.delete.call_args_list} + assert {TASKS + NAME_PROBE_NAME, TASKS + NAME_PROBE_UID + ".ics"} <= deleted + + def test_a_task_renamed_to_another_name_is_unsupported_and_named(self) -> None: + node, _ = _task_probe("7f3a9c12-server-assigned.ics") + assert node["support"] == "unsupported" + assert "uid_ics_components" not in node + assert "7f3a9c12-server-assigned.ics" in node["behaviour"] diff --git a/tests/test_supported_task_modes.py b/tests/test_supported_task_modes.py new file mode 100644 index 0000000..ed9c228 --- /dev/null +++ b/tests/test_supported_task_modes.py @@ -0,0 +1,90 @@ +"""Whether a server advertises RFC 10051 with CALDAV:supported-task-mode-set (section 13.1). + +Neither Ox nor Zimbra has the property, on the calendar home or a calendar. +""" + +from unittest.mock import Mock + +from caldav.compatibility_hints import FeatureSet +from lxml import etree + +from caldav_server_tester.checks import CheckSupportedTaskModes + +HOME = "http://example.com/home/" +CAL = "http://example.com/home/tasks/" + + +def _answer(modes): + if modes is None: + prop, status = "", "404 Not Found" + else: + inner = "".join(f"{m}" for m in modes) + prop, status = f"{inner}", "200 OK" + xml = ( + '' + f"/x/{prop}" + f"HTTP/1.1 {status}" + ) + return Mock(status=207, tree=etree.fromstring(xml.encode()), raw=xml) + + +def _run(home=None, calendar=None, fails=False, home_fails=False, tasklist=True): + """``home`` and ``calendar``: the modes each lists, None where the property is absent""" + client = Mock() + + def request(url, method="GET", body="", headers=None): + assert method == "PROPFIND" and "supported-task-mode-set" in body + if fails: + return Mock(status=500, tree=None, raw="") + return _answer(home if url == HOME else calendar) + + client.request.side_effect = request + checker = Mock() + checker._features_checked = FeatureSet() + checker.debug_mode = None + checker._client_obj = client + if home_fails: + type(checker.principal).calendar_home_set = property(lambda self: (_ for _ in ()).throw(OSError("gone"))) + else: + checker.principal.calendar_home_set.url = HOME + if tasklist: + checker.tasklist.url = CAL + else: + checker.tasklist = None + CheckSupportedTaskModes(checker)._run_check() + return checker._features_checked.is_supported("supported-task-modes", return_type=dict) + + +def test_absent_everywhere_is_unsupported(): + """Ox, Zimbra""" + verdict = _run() + assert verdict["support"] == "unsupported" + assert "supported-task-mode-set" in verdict["behaviour"] + + +def test_on_the_home_is_full_with_the_modes(): + assert _run(home=["AUTOMATIC-COMPLETION", "AUTOMATIC-FAILURE"]) == { + "support": "full", + "values": ["AUTOMATIC-COMPLETION", "AUTOMATIC-FAILURE"], + } + + +def test_on_a_calendar_only_is_full(): + assert _run(calendar=["AUTOMATIC-COMPLETION"])["support"] == "full" + + +def test_an_empty_set_is_unsupported(): + """No supported-task-mode inside: RFC 10051 says to assume no support""" + assert _run(home=[])["support"] == "unsupported" + + +def test_a_failing_propfind_is_unknown(): + assert _run(fails=True)["support"] == "unknown" + + +def test_a_failing_home_lookup_asks_the_calendar_only(): + assert _run(calendar=["AUTOMATIC-COMPLETION"], home_fails=True)["support"] == "full" + + +def test_without_a_task_calendar_the_home_is_asked(): + assert _run(home=["AUTOMATIC-COMPLETION"], tasklist=False)["support"] == "full" diff --git a/tests/test_todo_roundtrip.py b/tests/test_todo_roundtrip.py index 0ca7392..0a64819 100644 --- a/tests/test_todo_roundtrip.py +++ b/tests/test_todo_roundtrip.py @@ -13,6 +13,9 @@ from caldav_server_tester.checks import ( CheckCompletedWithoutStatus, CheckTodoAttendee, + CheckTodoPriority, + CheckTodoStatus, + CheckTodoStatusRfc10051, CheckUnknownProperty, PrepareCalendar, ) @@ -21,7 +24,14 @@ BASE = "http://example.com/cal/" TASKS = "http://example.com/tasks/" -CHECKS = [CheckTodoAttendee, CheckUnknownProperty, CheckCompletedWithoutStatus] +CHECKS = [ + CheckTodoAttendee, + CheckUnknownProperty, + CheckCompletedWithoutStatus, + CheckTodoStatus, + CheckTodoStatusRfc10051, + CheckTodoPriority, +] class VanishingServer(RewritingServer): @@ -39,12 +49,12 @@ def put(self, url, body, headers=None): return super().put(url, body, headers) -def _run(check, server, todo="full", tasklist=True, whole=False): +def _run(check, server, todo="full", tasklist=True, whole=False, recorded=None): """``whole``: through run_check(), with its check that every declared feature got a value""" checker = Mock() checker._checks_run = {PrepareCalendar} - checker._features_checked = FeatureSet({"save-load.todo": {"support": todo}}) + checker._features_checked = FeatureSet({"save-load.todo": {"support": todo}, **(recorded or {})}) checker.features_checked = checker._features_checked checker.debug_mode = None checker._client_obj = server @@ -127,6 +137,83 @@ def add_status(body): assert _run(CheckCompletedWithoutStatus, RewritingServer(rewrite=add_status))["support"] == "full" +class ValueServer(RewritingServer): + """Stores ``name:value`` as ``stored[value]`` (None drops it), and refuses the values in ``refused``.""" + + def __init__(self, name, stored=None, refused=()): + super().__init__() + self.name, self.stored, self.refused = name, stored or {}, refused + + def put(self, url, body, headers=None): + value = re.search(rf"\r\n{self.name}:([^\r]*)", body)[1] + if value in self.refused: + return Mock(status=403, headers={}) + if value in self.stored: + new = self.stored[value] + body = body.replace(f"\r\n{self.name}:{value}", "" if new is None else f"\r\n{self.name}:{new}") + return super().put(url, body, headers) + + +def test_the_rfc_5545_statuses_and_the_rfc_10051_ones_are_swept_apart(): + for check, expected in ( + (CheckTodoStatus, ["NEEDS-ACTION", "IN-PROCESS", "COMPLETED", "CANCELLED"]), + (CheckTodoStatusRfc10051, ["PENDING", "FAILED"]), + ): + sent = [] + _run(check, RewritingServer(rewrite=lambda body: sent.append(body) or body)) + assert [re.search(r"\r\nSTATUS:([^\r]*)", b)[1] for b in sent] == expected + + +def test_rfc_10051_statuses_dropped_where_not_advertised(): + """Ox keeps every RFC 5545 status, drops PENDING and FAILED, and does not advertise RFC 10051""" + server = ValueServer("STATUS", {"PENDING": None, "FAILED": None}) + assert _run(CheckTodoStatus, server)["support"] == "full" + not_advertised = {"supported-task-modes": {"support": "unsupported"}} + verdict = _run(CheckTodoStatusRfc10051, server, recorded=not_advertised) + assert verdict["support"] == "unsupported" + assert verdict["values"] == [] + assert verdict["behaviour"] == "PENDING is dropped; FAILED is dropped; the server does not advertise RFC 10051" + + +def test_rfc_10051_statuses_dropped_where_advertised_say_so(): + advertised = {"supported-task-modes": {"support": "full", "values": ["AUTOMATIC-COMPLETION"]}} + verdict = _run(CheckTodoStatusRfc10051, ValueServer("STATUS", {"PENDING": None}), recorded=advertised) + assert verdict["behaviour"] == "PENDING is dropped; although the server advertises RFC 10051" + + +def test_rfc_10051_statuses_dropped_where_advertising_is_unknown_say_nothing_more(): + verdict = _run(CheckTodoStatusRfc10051, ValueServer("STATUS", {"PENDING": None})) + assert verdict["behaviour"] == "PENDING is dropped" + + +def test_statuses_stored_as_another_and_refused(): + """Zimbra""" + server = ValueServer("STATUS", {"PENDING": "NEEDS-ACTION", "FAILED": "NEEDS-ACTION"}, refused=("CANCELLED",)) + verdict = _run(CheckTodoStatus, server) + assert verdict["support"] == "ungraceful" + assert verdict["values"] == ["NEEDS-ACTION", "IN-PROCESS", "COMPLETED"] + assert verdict["refused"] == ["CANCELLED"] + assert "CANCELLED is refused (403)" in verdict["behaviour"] + assert not server.objects + assert _run(CheckTodoStatusRfc10051, server)["map"] == {"PENDING": "NEEDS-ACTION", "FAILED": "NEEDS-ACTION"} + + +def test_priorities_kept_as_three_levels(): + """Ox: 1, 5 and 9, each other value stored as the nearest""" + stored = {"0": "5", "2": "1", "3": "5", "4": "5", "6": "5", "7": "9", "8": "9"} + verdict = _run(CheckTodoPriority, ValueServer("PRIORITY", stored)) + assert verdict["support"] == "unsupported" + assert verdict["values"] == [1, 5, 9] + assert verdict["map"] == {0: 5, 2: 1, 3: 5, 4: 5, 6: 5, 7: 9, 8: 9} + + +def test_priority_zero_dropped_means_the_same(): + """No PRIORITY is no priority given, as 0 is""" + verdict = _run(CheckTodoPriority, ValueServer("PRIORITY", {"0": None})) + assert verdict["support"] == "full" + assert "dropped" in verdict["behaviour"] + + @pytest.mark.parametrize("check", CHECKS) def test_refused_is_ungraceful(check): assert _run(check, RewritingServer(put_answer=403))["support"] == "ungraceful" @@ -152,3 +239,18 @@ def test_no_task_calendar_is_unknown(check): def test_an_unreadable_task_other_than_404_is_unknown(): assert _run(CheckTodoAttendee, RewritingServer(get_status=500))["support"] == "unknown" + + +def test_a_priority_written_back_as_no_number_is_mapped_as_text(): + verdict = _run(CheckTodoPriority, ValueServer("PRIORITY", {"3": "MEDIUM"})) + assert verdict["map"] == {3: "MEDIUM"} + + +def test_one_value_unreadable_makes_the_sweep_unknown(): + class OneUnreadable(ValueServer): + def request(self, url, method="GET"): + if "in-process" in url: + return Mock(status=500, headers={}, raw="") + return super().request(url, method) + + assert _run(CheckTodoStatus, OneUnreadable("STATUS"))["support"] == "unknown"