feat(v2): complete v2 reimplementation

This commit is contained in:
2026-07-31 13:33:39 +02:00
parent 396219e776
commit bd107d6a30
137 changed files with 20737 additions and 155 deletions
+27 -1
View File
@@ -1,11 +1,14 @@
from __future__ import annotations
from pathlib import Path
from typing import Any, cast
import httpx
import pytest
from backup_tool.api.app import create_app
from backup_tool.config import Settings
from backup_tool.db.models import RepositoryDataKeyEpoch
from sqlalchemy import select
@pytest.mark.asyncio
@@ -30,7 +33,7 @@ async def test_admin_can_create_and_inspect_allowlisted_repository(
async with app.state.engine.begin() as connection:
await connection.run_sync(Base.metadata.create_all)
transport = httpx.ASGITransport(app=app)
transport = httpx.ASGITransport(app=cast(Any, app))
async with httpx.AsyncClient(transport=transport, base_url="https://test") as client:
setup = await client.post(
"/api/v2/setup", json={"username": "admin", "password": "a secure password"}
@@ -52,6 +55,29 @@ async def test_admin_can_create_and_inspect_allowlisted_repository(
assert body["name"] == "main"
assert body["format_version"] == 1
assert (root / "main" / "repository.json").is_file()
encrypted = await client.post(
"/api/v2/repositories",
json={
"name": "encrypted",
"relative_path": "encrypted",
"compression": "none",
"encryption": "aes-256-gcm",
},
headers={"X-CSRF-Token": csrf},
)
assert encrypted.status_code == 201, encrypted.text
async with app.state.sessions() as db:
epochs = list(
(
await db.scalars(
select(RepositoryDataKeyEpoch).where(
RepositoryDataKeyEpoch.repository_id == encrypted.json()["id"]
)
)
).all()
)
assert len(epochs) == 1
assert epochs[0].state == "active"
got = await client.get(f"/api/v2/repositories/{body['id']}")
assert got.status_code == 200
changed = await client.patch(