Führe die Konfigurationsansicht der Connectoren ein, damit Paperless und IMAP ihre Felder selbst deklarieren.
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 3m12s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 21s

Das Modul liefert ein Feldmanifest und validiert es; ein leeres Geheimnisfeld behält das gespeicherte. Die Oberfläche rendert die Felder generisch in einer Detailansicht je Zugang mit Prüfstand, Fähigkeiten und Verwendung. Die providerspezifischen Formulare in Sources.jsx entfallen, die flachen API-Felder bleiben als Kompatibilität. Das Standardfach eines IMAP-Kontos öffnet der Picker zuerst.

Die Backend-Tests wurden in der Entwicklungsumgebung nicht ausgeführt; der Lauf auf develop steht aus.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-10-20 09:34:37 +02:00
1 parent c29bd29f34
commit eb58dce4cd
20 files changed
+1071 -244

No files matched your search

+1 -1
View File
@@ -304,7 +304,7 @@ class ConnectorIn(APIModel):
password: str | None = None
mailbox: str | None = Field(default=None, max_length=200)
security: Literal["ssl", "starttls"] | None = None
config: dict[str, str] | None = None
config: dict[str, str | int | None] | None = None
class SourceAssignmentIn(APIModel):
+15 -7
View File
@@ -21,10 +21,13 @@ from app.sourcebind import assign_reference
from app.sourceport import capability_payload, with_capabilities
from app.sourceregistry import get_source, require_source
from app.sources import (
connector_detail,
delete_connector,
imap_preview,
list_connectors,
owned_connector,
paperless_content,
parse_connector,
probe,
save_connector,
update_connector,
@@ -52,11 +55,16 @@ def source_capabilities(principal: Principal = Depends(get_principal)):
@router.post("/api/v1/connectors", status_code=201)
def post_connector(body: ConnectorIn, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
name, settings, secret = _connector_parts(body)
name, settings, secret = _connector_parts(body, None)
row = save_connector(conn, principal.account_id, body.kind, name, settings, secret)
return row
@router.get("/api/v1/connectors/{connector_id}")
def get_connector(connector_id: UUID, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
return connector_detail(conn, principal.account_id, connector_id)
@router.patch("/api/v1/connectors/{connector_id}")
def patch_connector(
connector_id: UUID,
@@ -64,12 +72,10 @@ def patch_connector(
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
name, settings, secret = _connector_parts(body)
current = next((item for item in list_connectors(conn, principal.account_id) if item["id"] == str(connector_id)), None)
if current is None:
raise not_found()
current = owned_connector(conn, principal.account_id, connector_id)
if current["kind"] != body.kind:
raise unprocessable("Der Zugang bleibt bei seiner Quellenart.")
name, settings, secret = _connector_parts(body, current)
return update_connector(conn, principal.account_id, connector_id, name, settings, secret)
@@ -382,8 +388,10 @@ def assign_source(
return {"id": str(element_id), "connector_id": str(body.connector_id), "resolution": "bound"}
def _connector_parts(body: ConnectorIn) -> tuple[str, dict, str]:
return require_source(body.kind).parse_config(body.model_dump())
def _connector_parts(body: ConnectorIn, current: dict | None) -> tuple[str, dict, str]:
"""The registered module validates. Flat fields of the first release are folded into ``config``."""
flat = body.model_dump(exclude={"kind", "name", "config"})
return parse_connector(body.kind, body.name, flat, body.config, current)
_SEARCH_FLAGS = {
+9
View File
@@ -73,6 +73,15 @@ def capability_payload() -> dict:
return {
"sources": [module.capabilities for module in registered_sources()],
"modules": [
{
"kind": module.kind,
"label": module.label,
"representation": module.representation,
"config_fields": [item.public() for item in module.config_fields],
}
for module in registered_sources()
],
"editors": EDITORS,
"protection_profiles": {
"legacy-plaintext": "cleartext",
+109 -1
View File
@@ -7,6 +7,46 @@ from typing import Callable
from app.core.errors import unprocessable
FIELD_TYPES = ("text", "url", "number", "password", "select")
@dataclass(frozen=True)
class ConfigField:
"""One configuration field a module declares for its connector instances.
At most one field per module is a secret. Its value is stored apart from
the settings and is never handed out again.
"""
key: str
label: str
type: str = "text"
required: bool = False
secret: bool = False
default: str | int | None = None
options: tuple[tuple[str, str], ...] = ()
help: str = ""
placeholder: str = ""
minimum: int | None = None
maximum: int | None = None
max_length: int = 200
def public(self) -> dict:
return {
"key": self.key,
"label": self.label,
"type": self.type,
"required": self.required,
"secret": self.secret,
"default": self.default,
"options": [{"value": value, "label": label} for value, label in self.options],
"help": self.help,
"placeholder": self.placeholder,
"minimum": self.minimum,
"maximum": self.maximum,
"max_length": self.max_length,
}
@dataclass
class SourceModule:
@@ -14,11 +54,14 @@ class SourceModule:
label: str
representation: str
capabilities: dict
parse_config: Callable[[dict], tuple[str, dict, str]]
probe: Callable
find: Callable
open_original: Callable
export_original: Callable
# A module either declares fields (generic validation) or parses the payload itself.
parse_config: Callable[[dict], tuple[str, dict, str]] | None = None
config_fields: tuple[ConfigField, ...] = ()
normalize_config: Callable[[dict, str], dict] | None = None
navigate: Callable | None = None
preview: Callable | None = None
facets: Callable | None = None
@@ -28,6 +71,13 @@ _MODULES: dict[str, SourceModule] = {}
def register_source(module: SourceModule) -> None:
if module.parse_config is None and not module.config_fields:
raise ValueError(f"Quelle {module.kind} braucht Konfigurationsfelder oder parse_config.")
if sum(1 for item in module.config_fields if item.secret) > 1:
raise ValueError(f"Quelle {module.kind} darf höchstens ein Geheimnisfeld haben.")
for item in module.config_fields:
if item.type not in FIELD_TYPES:
raise ValueError(f"Feldtyp {item.type} ist unbekannt.")
_MODULES[module.kind] = module
@@ -52,3 +102,61 @@ def require_source(kind: str) -> SourceModule:
def accepts_reference(source: str) -> bool:
return source == "url" or source in _MODULES
def _blank(value) -> bool:
return value is None or (isinstance(value, str) and not value.strip())
def _coerce(field: ConfigField, value):
if field.type == "number":
try:
number = int(str(value).strip())
except (TypeError, ValueError):
raise unprocessable(f"{field.label} muss eine ganze Zahl sein.") from None
if field.minimum is not None and number < field.minimum:
raise unprocessable(f"{field.label} ist zu klein.")
if field.maximum is not None and number > field.maximum:
raise unprocessable(f"{field.label} ist zu groß.")
return number
text = str(value) if field.secret else str(value).strip()
if len(text) > field.max_length:
raise unprocessable(f"{field.label} ist zu lang.")
if field.type == "select" and text not in {option for option, _label in field.options}:
raise unprocessable(f"{field.label} ist keine zulässige Auswahl.")
return text
def parse_fields(
fields: tuple[ConfigField, ...],
values: dict,
current_settings: dict | None = None,
current_secret: str = "",
) -> tuple[dict, str]:
"""Validate declared fields. Unknown keys are refused, a blank secret keeps the stored one."""
known = {item.key for item in fields}
extra = sorted(key for key, value in values.items() if key not in known and not _blank(value))
if extra:
raise unprocessable("Unbekanntes Konfigurationsfeld: " + ", ".join(extra[:3]) + ".")
current_settings = current_settings or {}
settings: dict = {}
secret = current_secret
for item in fields:
raw = values.get(item.key)
if item.secret:
if _blank(raw):
if not current_secret and item.required:
raise unprocessable(f"{item.label} fehlt.")
continue
secret = _coerce(item, raw)
continue
if _blank(raw):
raw = current_settings.get(item.key)
if _blank(raw):
raw = item.default
if _blank(raw):
if item.required:
raise unprocessable(f"{item.label} fehlt.")
continue
settings[item.key] = _coerce(item, raw)
return settings, secret
+155 -34
View File
@@ -44,15 +44,47 @@ from app.sourceaccess import (
release_for_external,
)
from app.sourceport import CAPABILITIES
from app.sourceregistry import SourceModule, get_source, register_source
from app.sourceregistry import ConfigField, SourceModule, get_source, parse_fields, register_source, require_source
_PUBLIC_COLUMNS = """
id, kind, name, settings, created_at,
secret <> '' AS has_secret,
last_probe_at, last_probe_ok, last_probe_detail
"""
def parse_connector(
kind: str,
name: str,
flat: dict,
config: dict | None,
current: dict | None = None,
) -> tuple[str, dict, str]:
"""Validate a connector body with the registered module. ``current`` is the stored row on change."""
module = require_source(kind)
name = " ".join(str(name or "").split())
values = {key: value for key, value in flat.items() if value is not None}
values.update(config or {})
if module.config_fields:
settings, secret = parse_fields(
module.config_fields,
values,
current["settings"] if current else None,
current["secret"] if current else "",
)
if module.normalize_config is not None:
settings = module.normalize_config(settings, secret)
return name, settings, secret
return module.parse_config({**values, "kind": kind, "name": name, "config": config or {}})
def save_connector(conn, owner_id: UUID, kind: str, name: str, settings: dict, secret: str) -> dict:
row = conn.execute(
"""
f"""
INSERT INTO connectors (owner_id, kind, name, settings, secret)
VALUES (%s, %s, %s, %s, %s)
RETURNING id, kind, name, settings, created_at
RETURNING {_PUBLIC_COLUMNS}
""",
(owner_id, kind, name, Json(settings), secret),
).fetchone()
@@ -63,11 +95,12 @@ def update_connector(conn, owner_id: UUID, connector_id: UUID, name: str, settin
"""Credential or name change on the same instance. The id does not move."""
current = _owned(conn, owner_id, connector_id)
row = conn.execute(
"""
f"""
UPDATE connectors
SET name = %s, settings = %s, secret = %s
SET name = %s, settings = %s, secret = %s,
last_probe_at = NULL, last_probe_ok = NULL, last_probe_detail = NULL
WHERE id = %s AND owner_id = %s
RETURNING id, kind, name, settings, created_at
RETURNING {_PUBLIC_COLUMNS}
""",
(name, Json(settings), secret, current["id"], owner_id),
).fetchone()
@@ -76,8 +109,8 @@ def update_connector(conn, owner_id: UUID, connector_id: UUID, name: str, settin
def list_connectors(conn, owner_id: UUID) -> list[dict]:
rows = conn.execute(
"""
SELECT id, kind, name, settings, created_at
f"""
SELECT {_PUBLIC_COLUMNS}
FROM connectors WHERE owner_id = %s
ORDER BY kind, name
""",
@@ -86,6 +119,30 @@ def list_connectors(conn, owner_id: UUID) -> list[dict]:
return [_public(row) for row in rows]
def connector_detail(conn, owner_id: UUID, connector_id: UUID) -> dict:
"""One own instance with its use. The secret itself is never part of it."""
row = conn.execute(
f"SELECT {_PUBLIC_COLUMNS} FROM connectors WHERE id = %s AND owner_id = %s",
(connector_id, owner_id),
).fetchone()
if row is None:
raise not_found()
used = conn.execute(
"""
SELECT count(*) AS total
FROM external_references er
JOIN elements e ON e.id = er.element_id
WHERE (er.connector_id = %s OR er.detail ->> 'connector_id' = %s)
AND e.deleted_at IS NULL AND e.owner_subject_id = %s
""",
(connector_id, str(connector_id), owner_id),
).fetchone()
body = _public(row)
body["references"] = int(used["total"])
body["protection_profile"] = "legacy-plaintext"
return body
def delete_connector(conn, owner_id: UUID, connector_id: UUID) -> None:
row = conn.execute(
"DELETE FROM connectors WHERE id = %s AND owner_id = %s RETURNING id",
@@ -101,11 +158,30 @@ def probe(conn, owner_id: UUID, connector_id: UUID) -> dict:
if module is None:
raise unprocessable("Diese Quelle ist nicht registriert.")
release_for_external(conn)
result = module.probe(row)
try:
result = module.probe(row)
except Problem as exc:
assert_still_owned(conn, row["id"], owner_id)
_record_probe(conn, row["id"], False, exc.detail)
conn.commit()
raise
assert_still_owned(conn, row["id"], owner_id)
_record_probe(conn, row["id"], bool(result.get("ok", True)), str(result.get("detail") or ""))
return result
def _record_probe(conn, connector_id: UUID, ok: bool, detail: str) -> None:
"""Display only. The detail comes from the module and must not carry a secret."""
conn.execute(
"""
UPDATE connectors
SET last_probe_at = now(), last_probe_ok = %s, last_probe_detail = %s
WHERE id = %s
""",
(ok, detail[:300] or None, connector_id),
)
def _paperless_choice(value, label: str) -> str | None:
text = str(value or "").strip()
if not text:
@@ -325,6 +401,11 @@ def _owned(conn, owner_id: UUID, connector_id: UUID) -> dict:
return row
def owned_connector(conn, owner_id: UUID, connector_id: UUID) -> dict:
"""The stored row of an own instance, secret included. For server-side use only."""
return _owned(conn, owner_id, connector_id)
def _public(row) -> dict:
return {
"id": str(row["id"]),
@@ -333,6 +414,14 @@ def _public(row) -> dict:
"settings": row["settings"],
"created_at": row["created_at"].strftime("%Y-%m-%dT%H:%M:%SZ"),
"capabilities": (get_source(row["kind"]).capabilities if get_source(row["kind"]) else None),
"has_secret": bool(row["has_secret"]),
"probe": {
"at": row["last_probe_at"].strftime("%Y-%m-%dT%H:%M:%SZ"),
"ok": bool(row["last_probe_ok"]),
"detail": row["last_probe_detail"] or "",
}
if row["last_probe_at"]
else None,
}
@@ -1456,32 +1545,62 @@ def _search_rfc822(client: imaplib.IMAP4, expected_id: str, max_bytes: int) -> l
return found
def _paperless_config(payload: dict) -> tuple[str, dict, str]:
base_url = str(payload.get("base_url") or "").strip()
token = str(payload.get("token") or "").strip()
name = str(payload.get("name") or "").strip()
if not base_url or len(token) < 8:
raise unprocessable("Paperless braucht eine Adresse und einen API-Schlüssel.")
return name, {"base_url": clean_base_url(base_url)}, token
PAPERLESS_FIELDS = (
ConfigField(
"base_url",
"Adresse",
type="url",
required=True,
placeholder="https://paperless.example",
help="Adresse deiner Paperless-Instanz ohne Pfad.",
max_length=300,
),
ConfigField(
"token",
"API-Schlüssel",
type="password",
required=True,
secret=True,
help="Den Schlüssel erzeugst du in Paperless unter deinem Profil.",
max_length=200,
),
)
IMAP_FIELDS = (
ConfigField("host", "Server", required=True, placeholder="imap.example", max_length=200),
ConfigField("port", "Port", type="number", required=True, default=993, minimum=1, maximum=65535),
ConfigField(
"security",
"Verbindung",
type="select",
required=True,
default="ssl",
options=(("ssl", "SSL"), ("starttls", "STARTTLS")),
),
ConfigField("username", "Benutzername", required=True, max_length=200),
ConfigField("password", "Passwort", type="password", required=True, secret=True, max_length=500),
ConfigField(
"mailbox",
"Standardfach",
default="INBOX",
help="Dieses Fach öffnet die Auswahl zuerst.",
max_length=200,
),
)
def _imap_config(payload: dict) -> tuple[str, dict, str]:
host = str(payload.get("host") or "").strip()
username = str(payload.get("username") or "").strip()
password = str(payload.get("password") or "")
name = str(payload.get("name") or "").strip()
if not host or not username or not password:
raise unprocessable("Ein E-Mail-Konto braucht Server, Benutzername und Passwort.")
if " " in host or len(host) > 200:
def _paperless_normalize(settings: dict, secret: str) -> dict:
if len(secret.strip()) < 8:
raise unprocessable("Der API-Schlüssel ist zu kurz.")
return {**settings, "base_url": clean_base_url(settings["base_url"])}
def _imap_normalize(settings: dict, secret: str) -> dict:
del secret
if " " in settings["host"]:
raise unprocessable("Der Mailserver ist ungültig.")
port = payload.get("port") or 993
return name, {
"host": host,
"port": int(port),
"username": username,
"mailbox": str(payload.get("mailbox") or "INBOX").strip() or "INBOX",
"security": payload.get("security") or "ssl",
}, password
_check_mailbox(settings.get("mailbox") or "INBOX")
return settings
def _paperless_find(conn, owner_id: UUID, connector_id: UUID | None, query: str, options: dict) -> dict:
@@ -1624,7 +1743,8 @@ def _install_sources() -> None:
label="Paperless",
representation="pdf",
capabilities=CAPABILITIES["paperless"],
parse_config=_paperless_config,
config_fields=PAPERLESS_FIELDS,
normalize_config=_paperless_normalize,
probe=paperless.probe,
find=paperless.find,
open_original=read_linked_paperless,
@@ -1638,7 +1758,8 @@ def _install_sources() -> None:
label="E-Mail",
representation="email",
capabilities=CAPABILITIES["imap"],
parse_config=_imap_config,
config_fields=IMAP_FIELDS,
normalize_config=_imap_normalize,
probe=imap.probe,
find=imap.find,
open_original=_imap_bytes,
@@ -0,0 +1,8 @@
-- Last connection check per connector instance. Display only: it grants nothing
-- and carries no secret.
ALTER TABLE connectors
ADD COLUMN last_probe_at timestamptz,
ADD COLUMN last_probe_ok boolean,
ADD COLUMN last_probe_detail text,
ADD CONSTRAINT connectors_probe_detail_len CHECK (last_probe_detail IS NULL OR char_length(last_probe_detail) <= 300);
+12 -8
View File
@@ -10,7 +10,7 @@ from uuid import UUID
from app.core.errors import not_found, unprocessable
from app.retrieval import FilePayload, RetrievalFailure
from app.sourcebind import resolve_for_read
from app.sourceregistry import SourceModule, register_source, unregister_source
from app.sourceregistry import ConfigField, SourceModule, register_source, unregister_source
from app.sourceaccess import borrow_original, complete_borrow
KIND = "sample"
@@ -51,13 +51,16 @@ CAPABILITIES = {
}
def parse_config(payload: dict) -> tuple[str, dict, str]:
config = payload.get("config") or {}
catalog = str(config.get("catalog") or "").strip()
name = str(payload.get("name") or "").strip() or catalog
if catalog not in CATALOG:
CONFIG_FIELDS = (
ConfigField("catalog", "Katalog", required=True, default="alpha", help="Name des Beispielkatalogs."),
)
def normalize_config(settings: dict, secret: str) -> dict:
del secret
if settings["catalog"] not in CATALOG:
raise unprocessable("Der Katalog dieser Beispielquelle ist unbekannt.")
return name, {"catalog": catalog}, ""
return settings
def probe(row) -> dict:
@@ -109,7 +112,8 @@ def install_sample_source() -> None:
label="Beispielquelle",
representation="text",
capabilities=CAPABILITIES,
parse_config=parse_config,
config_fields=CONFIG_FIELDS,
normalize_config=normalize_config,
probe=probe,
find=find,
open_original=open_original,
+215
View File
@@ -0,0 +1,215 @@
"""Connector configuration: fields come from the module, secrets never leave the server."""
from __future__ import annotations
import pytest
from app.core.errors import Problem
from app.sourceregistry import ConfigField, parse_fields
from tests.sample_source import install_sample_source, remove_sample_source
from tests.support import Actor, register
SECRET_WORDS = ("secret", "token-geheim-1234", "passwort-geheim")
PAPERLESS = {"kind": "paperless", "name": "Archiv", "base_url": "https://paper.example.test", "token": "token-geheim-1234"}
IMAP = {
"kind": "imap",
"name": "Postfach",
"host": "imap.example.test",
"port": 993,
"username": "ada",
"password": "passwort-geheim",
"security": "ssl",
}
@pytest.fixture
def sample_source():
install_sample_source()
try:
yield
finally:
remove_sample_source()
def _ada(client, db) -> Actor:
ada = Actor(client, "ada-config@example.test", "Ada Konfig")
register(db, ada.email, ada.name)
ada.login()
return ada
def _stored(db, connector_id: str) -> dict:
return db.execute("SELECT settings, secret FROM connectors WHERE id = %s", (connector_id,)).fetchone()
def test_parse_fields_checks_types_and_refuses_unknown_keys():
fields = (
ConfigField("host", "Server", required=True),
ConfigField("port", "Port", type="number", default=993, minimum=1, maximum=65535),
ConfigField("mode", "Modus", type="select", default="a", options=(("a", "A"), ("b", "B"))),
ConfigField("key", "Schlüssel", type="password", required=True, secret=True),
)
settings, secret = parse_fields(fields, {"host": " h ", "key": "k"})
assert settings == {"host": "h", "port": 993, "mode": "a"}
assert secret == "k"
for bad in (
{"host": "h", "key": "k", "port": "abc"},
{"host": "h", "key": "k", "port": 0},
{"host": "h", "key": "k", "mode": "c"},
{"host": "h", "key": "k", "fremd": "x"},
{"key": "k"},
{"host": "h"},
):
with pytest.raises(Problem) as caught:
parse_fields(fields, bad)
assert caught.value.status == 422
kept_settings, kept_secret = parse_fields(fields, {"host": "neu", "key": ""}, {"host": "alt", "port": 143}, "bleibt")
assert kept_settings["host"] == "neu" and kept_settings["port"] == 143
assert kept_secret == "bleibt"
def test_capabilities_list_the_fields_of_each_module(client, db):
ada = _ada(client, db)
modules = {item["kind"]: item for item in ada.request("GET", "/api/v1/sources/capabilities")["modules"]}
assert {"paperless", "imap"} <= set(modules)
paperless = {item["key"]: item for item in modules["paperless"]["config_fields"]}
assert paperless["token"]["secret"] is True and paperless["base_url"]["required"] is True
imap = {item["key"]: item for item in modules["imap"]["config_fields"]}
assert imap["password"]["secret"] is True
assert imap["port"]["type"] == "number" and imap["port"]["default"] == 993
assert [option["value"] for option in imap["security"]["options"]] == ["ssl", "starttls"]
assert imap["mailbox"]["default"] == "INBOX"
def test_create_with_config_and_flat_fields_gives_the_same_stored_result(client, db):
ada = _ada(client, db)
flat = ada.request("POST", "/api/v1/connectors", json=PAPERLESS, status=201)
config = ada.request(
"POST",
"/api/v1/connectors",
json={
"kind": "paperless",
"name": "Zweites Archiv",
"config": {"base_url": "https://paper.example.test/", "token": "token-geheim-1234"},
},
status=201,
)
assert _stored(db, flat["id"]) == _stored(db, config["id"])
assert _stored(db, flat["id"])["settings"] == {"base_url": "https://paper.example.test"}
def test_secrets_never_leave_the_server(client, db):
ada = _ada(client, db)
created = ada.request("POST", "/api/v1/connectors", json=IMAP, status=201)
detail = ada.request("GET", f"/api/v1/connectors/{created['id']}")
listed = ada.request("GET", "/api/v1/connectors")
for body in (created, detail, listed):
text = str(body)
assert not any(word in text for word in SECRET_WORDS if word != "secret"), text
assert "'secret'" not in text and "'password'" not in text and "'token'" not in text
assert detail["has_secret"] is True
assert detail["settings"]["mailbox"] == "INBOX"
assert detail["settings"]["port"] == 993
assert detail["protection_profile"] == "legacy-plaintext"
assert detail["references"] == 0
assert detail["probe"] is None
def test_change_without_secret_keeps_the_stored_one_and_the_instance(client, db):
ada = _ada(client, db)
created = ada.request("POST", "/api/v1/connectors", json=IMAP, status=201)
changed = ada.request(
"PATCH",
f"/api/v1/connectors/{created['id']}",
json={"kind": "imap", "name": "Umbenannt", "config": {"host": "mail.example.test", "port": "143", "security": "starttls"}},
)
assert changed["id"] == created["id"]
assert changed["name"] == "Umbenannt"
stored = _stored(db, created["id"])
assert stored["secret"] == "passwort-geheim"
assert stored["settings"]["host"] == "mail.example.test"
assert stored["settings"]["port"] == 143
assert stored["settings"]["security"] == "starttls"
assert stored["settings"]["username"] == "ada"
renewed = ada.request(
"PATCH",
f"/api/v1/connectors/{created['id']}",
json={"kind": "imap", "name": "Umbenannt", "config": {"password": "neues-passwort"}},
)
assert renewed["id"] == created["id"]
assert _stored(db, created["id"])["secret"] == "neues-passwort"
def test_module_validation_refuses_bad_input(client, db):
ada = _ada(client, db)
ada.request("POST", "/api/v1/connectors", json={**PAPERLESS, "base_url": "ftp://paper.example.test"}, status=422)
ada.request("POST", "/api/v1/connectors", json={**PAPERLESS, "token": "kurz"}, status=422)
ada.request("POST", "/api/v1/connectors", json={**IMAP, "host": "mail server"}, status=422)
ada.request("POST", "/api/v1/connectors", json={**IMAP, "port": 70000}, status=422)
ada.request("POST", "/api/v1/connectors", json={**IMAP, "password": None}, status=422)
ada.request(
"POST",
"/api/v1/connectors",
json={"kind": "paperless", "name": "Fremdfeld", "config": {"base_url": "https://paper.example.test", "token": "token-geheim-1234", "host": "x"}},
status=422,
)
created = ada.request("POST", "/api/v1/connectors", json=PAPERLESS, status=201)
ada.request(
"PATCH",
f"/api/v1/connectors/{created['id']}",
json={**PAPERLESS, "kind": "imap"},
status=422,
)
assert _stored(db, created["id"])["settings"] == {"base_url": "https://paper.example.test"}
def test_a_foreign_instance_is_not_found(client, db):
ada = _ada(client, db)
ben = Actor(client, "ben-config@example.test", "Ben Konfig")
register(db, ben.email, ben.name)
created = ada.request("POST", "/api/v1/connectors", json=PAPERLESS, status=201)
ben.login()
ben.request("GET", f"/api/v1/connectors/{created['id']}", status=404)
ben.request("PATCH", f"/api/v1/connectors/{created['id']}", json=PAPERLESS, status=404)
ben.request("DELETE", f"/api/v1/connectors/{created['id']}", status=404)
def test_probe_result_is_kept_for_display(client, db, sample_source):
del sample_source
ada = _ada(client, db)
created = ada.request(
"POST",
"/api/v1/connectors",
json={"kind": "sample", "name": "Katalog", "config": {"catalog": "alpha"}},
status=201,
)
probed = ada.request("POST", f"/api/v1/connectors/{created['id']}/probe")
detail = ada.request("GET", f"/api/v1/connectors/{created['id']}")
assert detail["probe"]["ok"] is True
assert detail["probe"]["detail"] == probed["detail"]
ada.request(
"PATCH",
f"/api/v1/connectors/{created['id']}",
json={"kind": "sample", "name": "Katalog", "config": {"catalog": "alpha"}},
)
assert ada.request("GET", f"/api/v1/connectors/{created['id']}")["probe"] is None
def test_a_module_with_fields_needs_no_central_schema(client, db, sample_source):
del sample_source
ada = _ada(client, db)
modules = {item["kind"]: item for item in ada.request("GET", "/api/v1/sources/capabilities")["modules"]}
assert [item["key"] for item in modules["sample"]["config_fields"]] == ["catalog"]
ada.request(
"POST",
"/api/v1/connectors",
json={"kind": "sample", "name": "Ohne Wert", "config": {}},
status=201,
)
ada.request(
"POST",
"/api/v1/connectors",
json={"kind": "sample", "name": "Falsch", "config": {"catalog": "kein-katalog"}},
status=422,
)