Skip to content

fix(server): discover CalDAV principals with PROPFIND - #15811

Merged
darkskygit merged 1 commit into
canaryfrom
darksky/improve-caldav-discovery
Nov 8, 2026
Merged

darkskygit merged 1 commit into
canaryfrom
darksky/improve-caldav-discovery

Conversation

@darkskygit

@darkskygit darkskygit commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

fix #15482

PR Dependency Tree

This tree was auto-generated by Charcoal

Summary by CodeRabbit

  • Bug Fixes
    • Improved CalDAV account setup across server configurations, including servers that redirect discovery requests or use relative calendar links.
    • CalDAV connection errors for unauthorized or forbidden access are now surfaced without attempting fallback requests.
    • Calendar and event retrieval continues to work across supported discovery scenarios.

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

CalDAV account discovery now uses PROPFIND to find the current-user principal. It resolves principal and calendar-home hrefs relative to response URLs. Tests cover redirects, relative hrefs, and 401 and 403 discovery responses.

Changes: CalDAV principal discovery

Layer / File(s) Summary
Principal discovery and validation
packages/backend/server/src/plugins/calendar/providers/caldav.ts, packages/backend/server/src/plugins/calendar/__tests__/caldav.spec.ts
Discovery starts with PROPFIND to /.well-known/caldav and retries the server URL for HTTP 400, 404, 405, or 501 when the URLs differ. The provider resolves principal and calendar-home hrefs against response URLs. Tests cover discovery redirects, relative hrefs, event parsing, and 401 and 403 responses.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant discoverAccount
  participant fetchCurrentUserPrincipal
  participant CalDAVServer
  participant CalendarHomeLookup
  discoverAccount->>fetchCurrentUserPrincipal: serverUrl
  fetchCurrentUserPrincipal->>CalDAVServer: PROPFIND /.well-known/caldav
  CalDAVServer-->>fetchCurrentUserPrincipal: response URL and principal href
  fetchCurrentUserPrincipal->>CalDAVServer: fallback PROPFIND serverUrl for selected statuses
  fetchCurrentUserPrincipal-->>discoverAccount: discovery URL and resolved principal URL
  discoverAccount->>CalendarHomeLookup: principal URL
  CalendarHomeLookup->>CalDAVServer: PROPFIND for calendar home
Loading

Suggested labels: app:server, test

Merge Risk: Low · up to 858f4

Some CalDAV servers redirect the well-known URL to a non-DAV page. Account linking can then fail even though the configured URL works. The core PROPFIND-based discovery fix is sound, so this is a bounded follow-up.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(server): discover CalDAV principals with PROPFIND" matches the main change. The provider now starts principal discovery with a PROPFIND at the preset server URL and derives the account …
Linked Issues check Passed Linked issue #15482 is the only active direct target. Its coding requirement: after following redirects, do not assume a 200 response is a valid DAV discovery target. Validate the resolved URL, or iss…
Out of Scope Changes check Passed The whole-PR diff (mergeBase 4ac1636 to head 858f45d) touches two files. caldav.ts changes are confined to the CalDAV discovery path. These are: removal of resolveDiscoveryUrl, folding discovery URL…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title "fix(server): discover CalDAV principals with PROPFIND" matches the main change. The provider now starts principal discovery with a PROPFIND at the preset server URL and derives the account ID from the principal URL. The linked issue asks for the same behavior, so the title names the core fix. It does not mention the redirect handling or the 401/403 error propagation, but it does not need to cover every detail.

Full details: Linked Issues check

Explanation

Linked issue #15482 is the only active direct target. Its coding requirement: after following redirects, do not assume a 200 response is a valid DAV discovery target. Validate the resolved URL, or issue a PROPFIND for current-user-principal per RFC 6764. The head implements the second option in caldav.ts. discoverAccount calls fetchCurrentUserPrincipal, which sends PROPFIND (Depth: 0) to /.well-known/caldav. It retries the preset serverUrl only for 400, 404, 405, or 501. A non-ok status throws CalendarProviderRequestError. The principal is read from the multistatus body, and a missing principal throws 'CalDAV principal not found.' The returned discoveryUrl is response.url from that PROPFIND. The old GET-based resolveDiscoveryUrl, which adopted any 200 redirect target, is removed. In the reported Radicale flow, a non-DAV page at /.web/ cannot yield a current-user-principal, so discovery no longer adopts it. The calendar-home PROPFIND and href resolution now use the response URL. Residual uncertainty: the PROPFIND redirect path depends on safeFetch (base/utils/request.ts, not inspected within the inspection limit) preserving the PROPFIND method across 301/302 responses. If it did not, the flow would fail loudly with a principal error, not silently adopt a wrong URL. The verdict assumes the method is preserved. The PR test mock is reported to redirect PROPFIND discovery requests, which is consistent with that assumption.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff (mergeBase 4ac1636 to head 858f45d) touches two files. caldav.ts changes are confined to the CalDAV discovery path. These are: removal of resolveDiscoveryUrl, folding discovery URL and principal lookup into fetchCurrentUserPrincipal, removal of the username@host providerAccountId fallback (dead code, because principalUrl is now always non-empty or the call throws), dropping the unused baseUrl parameter from fetchCalendarHomeSet, and resolving hrefs against response.url. All of these directly implement the #15482 fix. The caldav.spec.ts changes add mock discovery scenarios and tests for 401/403 propagation. These support the discovery change. The summary also notes test-infrastructure edits: AVA serial API, a typed Models return without an any cast. These are minor and sit in the same test file as the supporting tests. No change was found that is unrelated to #15482. Inspection of the test file was limited, so its exact contents were not verified.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a748707-1d6f-45e1-be58-87a945a7cc59
Commits

Reviewing files that changed from the base of the PR and between 4ac1636 and 858f45d.

Files selected for processing: 2

  • packages/backend/server/src/plugins/calendar/__tests__/caldav.spec.ts
  • packages/backend/server/src/plugins/calendar/providers/caldav.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying blocksuite-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 858f45d
Status: ✅  Deploy successful!
Preview URL: https://9c69dded.blocksuite-docs.pages.dev
Branch Preview URL: https://darksky-improve-caldav-disco.blocksuite-docs.pages.dev

View logs

@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.13%. Comparing base (4ac1636) to head (858f45d).
⚠️ Report is 3 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #15811      +/-   ##
==========================================
+ Coverage   55.12%   55.13%   +0.01%     
==========================================
  Files        4032     4032              
  Lines      193915   193899      -16     
  Branches    31458    31472      +14     
==========================================
+ Hits       106886   106899      +13     
+ Misses      83020    82989      -31     
- Partials     4009     4011       +2     
Flag Coverage Δ
server-test 78.77% <100.00%> (+0.01%) ⬆️
unittest 34.39% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@darkskygit
darkskygit merged commit 9c31663 into canary Nov 8, 2026
@darkskygit
darkskygit deleted the darksky/improve-caldav-discovery branch November 8, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app:server test Related to test cases

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Bug]: CalDAV discovery follows redirect to Radicale web UI, then PROPFIND fails with 403

1 participant