Fix LD sig tests

main
Thomas Sileo 2022-07-29 09:24:51 +02:00
parent 9c325674c6
commit 1c9b73b170
3 changed files with 17 additions and 3 deletions

View File

@ -83,3 +83,6 @@ extend-exclude = '''
| alembic/versions
)/
'''
[tool.pytest.ini_options]
asyncio_mode = "auto"

View File

@ -1,6 +1,7 @@
from typing import Generator
import pytest
import pytest_asyncio
from fastapi.testclient import TestClient
from app.database import Base
@ -11,7 +12,7 @@ from app.main import app
from tests.factories import _Session
@pytest.fixture
@pytest_asyncio.fixture
async def async_db_session():
async with async_session() as session:
async with async_engine.begin() as conn:

View File

@ -1,7 +1,12 @@
from copy import deepcopy
import httpx
import pytest
from respx import MockRouter
from app import activitypub as ap
from app import ldsig
from app.database import AsyncSession
from app.key import Key
from tests import factories
@ -28,7 +33,11 @@ _SAMPLE_CREATE = {
}
def test_linked_data_sig():
@pytest.mark.asyncio
async def test_linked_data_sig(
async_db_session: AsyncSession,
respx_mock: MockRouter,
) -> None:
privkey, pubkey = factories.generate_key()
ra = factories.RemoteActorFactory(
base_url="https://microblog.pub",
@ -37,8 +46,9 @@ def test_linked_data_sig():
)
k = Key(ra.ap_id, f"{ra.ap_id}#main-key")
k.load(privkey)
respx_mock.get(ra.ap_id).mock(return_value=httpx.Response(200, json=ra.ap_actor))
doc = deepcopy(_SAMPLE_CREATE)
ldsig.generate_signature(doc, k)
assert ldsig.verify_signature(doc, k)
assert (await ldsig.verify_signature(async_db_session, doc)) is True