Unified Nextcloud connect: one credential connects files, calendars and contacts

POST /api/nextcloud/connect composes the three per-user DAV roots
server-side, verifies the credential against each protocol in parallel
(netguard-pinned, sharing the siblings' /test budgets) BEFORE storing
anything, and creates one ordinary sibling connection per protocol that
passes. Orchestration, not a fourth connector: every sibling plan gate,
validation (incl. CardDAV https/443), cap and projection applies; partial
success is a 200 with per-connector created|exists|gated|error results;
repeat calls are idempotent by composed URL. GET /api/nextcloud/status
serves the new Settings -> Nextcloud tab (origin hint + allowed flags +
masked connections); the UI fires the existing /sync surfaces right after
connect so collections materialize immediately. Contacts sync untouched;
no schema change.

Tests: unified Nextcloud fake (sibling fakes re-rooted to Nextcloud paths
on one origin) covering happy path, idempotency, wrong-password-stores-
nothing, owner scoping, partial plan gate + restore; browser regression
for the full connect/sync/idempotent/Manage flow.
This commit is contained in:
Andrew S Erwin
2026-11-23 13:07:39 -06:00
parent 6bb68ef323
commit 084a1167da
10 changed files with 920 additions and 30 deletions
+7 -5
View File
@@ -16,17 +16,19 @@ import (
)
// fakeShare is a mutable minimal RFC 4918 server (Basic-auth erwin/s3cret)
// rooted at /dav. files maps share-relative paths to etags; the listing is
// rebuilt per PROPFIND so tests can add/change/remove files between syncs.
// rooted at root (default /dav; the unified Nextcloud fake re-roots it).
// files maps share-relative paths to etags; the listing is rebuilt per
// PROPFIND so tests can add/change/remove files between syncs.
type fakeShare struct {
mu sync.Mutex
root string
files map[string]string
srv *httptest.Server
}
func newFakeShare(t *testing.T) *fakeShare {
t.Helper()
f := &fakeShare{files: map[string]string{
f := &fakeShare{root: "/dav", files: map[string]string{
"a.txt": "A1", "b c.md": "B1", "sub/d.txt": "D1",
}}
f.srv = httptest.NewServer(http.HandlerFunc(f.serve))
@@ -57,7 +59,7 @@ func (f *fakeShare) serve(w http.ResponseWriter, r *http.Request) {
http.Error(w, "no", http.StatusMethodNotAllowed)
return
}
dir := strings.Trim(strings.TrimPrefix(r.URL.Path, "/dav"), "/")
dir := strings.Trim(strings.TrimPrefix(r.URL.Path, f.root), "/")
f.mu.Lock()
defer f.mu.Unlock()
if dir != "" {
@@ -88,7 +90,7 @@ func (f *fakeShare) serve(w http.ResponseWriter, r *http.Request) {
segs[i] = url.PathEscape(segs[i])
}
}
out := "/dav/" + strings.Join(segs, "/")
out := f.root + "/" + strings.Join(segs, "/")
if isDir {
out += "/"
}