Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This release works with caldav 3.7.0: the tester carries the definitions of the
- 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.
- On a server that makes calendars but will not delete them (Synology), a run no longer leaves new calendars behind: the create/delete probe takes the calendar an earlier run left at its fixed cal_id as the evidence that creation works, instead of making a fresh `testcalendar-<uuid>` one, and the second calendars of the duplicate-UID and MOVE probes get fixed cal_ids, `csc_duplicate_uid_cal2` and `csc_move_cal2`, and are emptied and used again. One test account had collected over 200 calendars. `synchronous-write.create-calendar` stays unknown there after the first run, and a server that takes MKCOL only still gets a new calendar on every run.

## 1.8.0 - 2026-10-30

Expand Down
21 changes: 21 additions & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,24 @@ server deletes whatever the etag says, so skipping the header would change
nothing. Decide whether `delete(if_match=True)` should warn or raise when the
hint says `broken`, or emulate the check with a GET and an etag compare
before the DELETE (racy, but closer to what was asked for).

## Re-runs on a server that cannot delete calendars

(Clean-context review 2026-11-17, filed rather than fixed.)

On a server that makes calendars but will not delete them (Synology),
only the first run on an account creates the probes' calendars; later
runs find them already there. Two consequences:

* The create/delete probe takes the calendar left at its fixed cal_id as
the evidence that creation works and records `create-calendar` as plain
`full`. A first run that graded it `quirk` (the empty 207) or `fragile`
is overruled on every later run. It should not upgrade the verdict,
say by keeping the configured profile's grade where that is worse.
* The probes at fixed cal_ids - `caldav-server-checker-displayname-test`
in `_check_set_displayname`, and `CAL_ID`/`CAL_ID_MULTIPLE` of
`CheckSupportedComponentSet` - get 405 on MKCALENDAR from the second
run on, so `create-calendar.set-displayname`, `create-calendar.stable-url`
and the supported-component-set features come out `unknown`. Reusing
the leftover where the question allows it (the component set can be
read off an existing calendar) would keep the verdicts.
44 changes: 24 additions & 20 deletions src/caldav_server_tester/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,28 @@ def _probe_make_delete(self):
self.set_feature("delete-calendar", {"support": "unknown", "behaviour": _cannot})
self.set_feature("delete-calendar.free-namespace", {"support": "unknown", "behaviour": _cannot})
return
features = self.checker.features_checked
if (
leftover
and not features.is_supported("create-calendar.auto")
and features.is_supported("delete-calendar", str) == "unsupported"
):
## A previous run made the calendar at the fixed cal_id, and this
## run has just failed to delete it. On such a server (Synology)
## the fresh cal_id below would stay for good, one more on every
## run, so the leftover is taken as the evidence that creation
## works. Not where every cal_id answers (create-calendar.auto),
## and not on a delete merely unknown: there a calendar at the
## cal_id says nothing about an earlier run.
self.set_feature("create-calendar")
self._settle_unknown["synchronous-write.create-calendar"] = (
"not timed: calendars cannot be deleted here, so the calendar a previous run made is used"
)
self.set_feature(
"delete-calendar.free-namespace",
{"support": "unknown", "behaviour": "cannot test, delete-calendar not supported"},
)
return
## The fixed cal_id could not be created at all; a fresh unique cal_id
## tells us whether calendar creation works in the first place.
unique_id = "testcalendar-" + str(uuid.uuid4())
Expand Down Expand Up @@ -8198,16 +8220,6 @@ def _run_check(self) -> None:

## Reuse an event from PrepareCalendar instead of creating a new one
test_uid = "csc_simple_event1"
cal2_name = "csc_duplicate_uid_cal2"

## Try to find and delete existing cal2 test calendar
try:
for cal in self.client.principal().calendars():
if cal.name == cal2_name:
cal.delete()
break
except Exception:
pass

try:
## Get existing event from first calendar (created by PrepareCalendar).
Expand All @@ -8223,9 +8235,8 @@ def _run_check(self) -> None:
## Get the event data for reuse in cal2
event_ical = event1.data

## Create second calendar
try:
cal2 = self.client.principal().make_calendar(name=cal2_name)
cal2 = self.second_calendar("csc_duplicate_uid_cal2")
except DAVError:
self.set_feature(
"save.duplicate-uid.cross-calendar",
Expand Down Expand Up @@ -9810,15 +9821,8 @@ def _unknown(self, features, why: str) -> None:

def _run_check(self) -> None:
cal1 = self.checker.calendar
cal2_name = "csc_move_cal2"
try:
for cal in self.client.principal().calendars():
if cal.name == cal2_name:
cal.delete()
except Exception:
pass
try:
cal2 = self.client.principal().make_calendar(name=cal2_name)
cal2 = self.second_calendar("csc_move_cal2")
except DAVError:
self._unknown(self.features_to_be_checked, "cannot test, have access to only one calendar")
return
Expand Down
44 changes: 44 additions & 0 deletions src/caldav_server_tester/checks_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,50 @@ def make_calendar_with_retries(self, cal_id, **kwargs):
time.sleep(1)
return None, self.RETRY_ATTEMPTS, error

def second_calendar(self, cal_id):
"""An empty calendar at ``cal_id`` (also its name), for a probe that needs a second one.

Old ones by that name are deleted first (runs before the cal_id was
fixed made them by name only). Where calendars cannot be deleted
(Synology), each one made would stay for good, so the one an
earlier run left at the cal_id is emptied and used again - unless
something in it will not go, which would skew the probe. Where the
cal_id is still taken, say by a delete the server carries out late, a
calendar is made by name only. Raises what ``make_calendar()`` raises.
"""
principal = self.client.principal()
if self.checker.features_checked.is_supported("delete-calendar", str) == "unsupported":
left = principal.calendar(cal_id=cal_id)
if self._calendar_is_accessible(left) and self._emptied(left):
return left
else:
try:
named = [cal for cal in principal.calendars() if cal.name == cal_id]
except Exception:
named = []
for cal in named:
try:
cal.delete()
except Exception:
pass
try:
return principal.make_calendar(cal_id=cal_id, name=cal_id)
except DAVError:
return principal.make_calendar(name=cal_id)

@staticmethod
def _emptied(cal) -> bool:
"""Delete everything in ``cal``; whether it is empty afterwards."""
try:
for obj in cal.objects():
try:
obj.delete()
except DAVError:
pass
return not list(cal.objects())
except DAVError:
return False

@staticmethod
def _worth_retrying(error) -> bool:
"""Could this refusal plausibly go the other way on the next ask?
Expand Down
86 changes: 85 additions & 1 deletion tests/test_check_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest
from caldav.compatibility_hints import _RENAMED_FEATURES, FeatureSet
from caldav.lib.error import NotFoundError
from caldav.lib.error import DAVError, NotFoundError

from caldav_server_tester.checks_base import Check, ProbedFeatureSet

Expand Down Expand Up @@ -713,3 +713,87 @@ def _run_check(self) -> None:

with pytest.raises(AssertionError):
TestCheck(self.create_checker("assert")).run_check()


class TestSecondCalendar:
"""Check.second_calendar: an empty calendar at a fixed cal_id, for a probe that needs two.

Made afresh where calendars can be deleted. Where they cannot (Synology),
each one made would stay for good, so the one an earlier run left at that
cal_id is emptied and used again.
"""

def _check(self, delete_calendar: str) -> tuple[Check, Mock]:
checker = Mock()
checker._features_checked = FeatureSet()
checker.features_checked = checker._features_checked
checker.debug_mode = None
checker._client_obj = Mock()
checker._client_obj.features = FeatureSet()
checker.features_checked.set_feature("delete-calendar", {"support": delete_calendar})
principal = checker._client_obj.principal.return_value
principal.calendars.return_value = []
return Check(checker), principal

@staticmethod
def _left(name: str, objects: list[Mock], keeps: int = 0) -> Mock:
"""A calendar left by an earlier run; the last ``keeps`` objects survive a delete."""
held = list(objects)
doomed = objects[: len(objects) - keeps]
for obj in doomed:
obj.delete.side_effect = lambda obj=obj: held.remove(obj)
cal = Mock()
cal.name = name
cal.events.return_value = []
cal.objects.side_effect = lambda: list(held)
return cal

def test_undeletable_reuses_and_empties_the_old_one(self) -> None:
check, principal = self._check("unsupported")
objects = [Mock(), Mock()]
old = self._left("csc_probe_cal2", objects)
principal.calendar.return_value = old

assert check.second_calendar("csc_probe_cal2") is old

principal.calendar.assert_called_with(cal_id="csc_probe_cal2")
principal.make_calendar.assert_not_called()
for obj in objects:
obj.delete.assert_called_once()

def test_undeletable_does_not_reuse_one_it_could_not_empty(self) -> None:
check, principal = self._check("unsupported")
principal.calendar.return_value = self._left("csc_probe_cal2", [Mock(), Mock()], keeps=1)

made = check.second_calendar("csc_probe_cal2")

assert made is principal.make_calendar.return_value

def test_undeletable_makes_one_at_the_fixed_cal_id_when_none_is_left(self) -> None:
check, principal = self._check("unsupported")
principal.calendar.return_value.events.side_effect = NotFoundError("gone")

made = check.second_calendar("csc_probe_cal2")

assert made is principal.make_calendar.return_value
principal.make_calendar.assert_called_once_with(cal_id="csc_probe_cal2", name="csc_probe_cal2")

def test_deletable_deletes_old_ones_by_name_and_makes_a_new(self) -> None:
check, principal = self._check("full")
old = self._left("csc_probe_cal2", [])
principal.calendars.return_value = [self._left("other", []), old]

made = check.second_calendar("csc_probe_cal2")

old.delete.assert_called_once()
assert made is principal.make_calendar.return_value
principal.make_calendar.assert_called_once_with(cal_id="csc_probe_cal2", name="csc_probe_cal2")

def test_a_taken_cal_id_falls_back_to_one_made_by_name(self) -> None:
"""A delete the server carries out late leaves the cal_id taken for a while."""
check, principal = self._check("full")
fresh = Mock()
principal.make_calendar.side_effect = [DAVError("405 Method Not Allowed"), fresh]

assert check.second_calendar("csc_probe_cal2") is fresh
principal.make_calendar.assert_called_with(name="csc_probe_cal2")
81 changes: 81 additions & 0 deletions tests/test_checks_with_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1828,3 +1828,84 @@ def test_leftover_with_a_working_creation_changes_nothing(self, monkeypatch) ->
CheckMakeDeleteCalendar(checker)._probe_make_delete()

assert checker.features_checked.is_supported("create-calendar", str) == "full"


class TestUndeletableCalendars:
"""A server that makes calendars but will not delete them (Synology).

Every calendar the probe makes there stays for good, so a calendar made
afresh on each run piles up: one test account held over 200 of them. The
make/delete probe is to use what an earlier run left instead.
"""

def _server(self, monkeypatch, existing: set[str], auto: bool = False) -> tuple[ServerQuirkChecker, list[str]]:
"""A checker against a server holding calendars ``existing``; the list fills with every cal_id made.

``auto``: every cal_id answers, as on a server that makes a calendar on access."""
import caldav_server_tester.checks as checks_mod

made: list[str] = []
held = set(existing)

def calendar(cal_id=None, **_kwargs):
cal = Mock()
if cal_id in held or auto:
cal.events.return_value = []
else:
cal.events.side_effect = NotFoundError("Node could not be found")
return cal

def make_calendar(cal_id=None, **_kwargs):
if cal_id in held:
raise DAVError("405 Method Not Allowed")
held.add(cal_id)
made.append(cal_id)
return calendar(cal_id)

def refuse(_self):
raise DAVError("403 Forbidden")

client = Mock()
client.features = FeatureSet()
client.request = Mock(return_value="response")
checker = ServerQuirkChecker(client, debug_mode=None)
checker.principal = Mock()
checker.principal.calendar.side_effect = calendar
checker.principal.make_calendar.side_effect = make_calendar
checker.principal.calendars.return_value = [calendar(c) for c in held]
checker._checks_run.add(CheckGetCurrentUserPrincipal)
monkeypatch.setattr(checks_mod.time, "sleep", lambda _s: None)
monkeypatch.setattr(checks_mod.DAVObject, "delete", refuse)
return checker, made

def test_a_rerun_makes_no_calendar(self, monkeypatch) -> None:
checker, made = self._server(monkeypatch, {CheckMakeDeleteCalendar.MKDEL_CAL_ID})

check = CheckMakeDeleteCalendar(checker)
check._probe_make_delete()
check._record_settle_delays()

assert made == []
features = checker.features_checked
assert features.is_supported("create-calendar", str) == "full"
assert features.is_supported("delete-calendar", str) == "unsupported"
assert features.is_supported("delete-calendar.free-namespace", str) == "unknown"
assert "previous run" in features.is_supported("synchronous-write.create-calendar", dict)["behaviour"]

def test_the_first_run_makes_one(self, monkeypatch) -> None:
checker, made = self._server(monkeypatch, set())

CheckMakeDeleteCalendar(checker)._probe_make_delete()

assert made == [CheckMakeDeleteCalendar.MKDEL_CAL_ID]
assert checker.features_checked.is_supported("create-calendar", str) == "full"
assert checker.features_checked.is_supported("delete-calendar", str) == "unsupported"

def test_on_a_server_making_calendars_on_access_any_cal_id_is_no_leftover(self, monkeypatch) -> None:
"""There every cal_id answers, so one at the fixed cal_id says nothing about an earlier run."""
checker, _made = self._server(monkeypatch, set(), auto=True)
checker.principal.make_calendar.side_effect = DAVError("403 Forbidden")

CheckMakeDeleteCalendar(checker)._probe_make_delete()

assert checker.features_checked.is_supported("create-calendar", str) == "unsupported"
Loading