pull/545/head
Ryan Barrett 2023-06-12 15:50:47 -07:00
rodzic 0902994af0
commit f951c143e3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
4 zmienionych plików z 32 dodań i 24 usunięć

Wyświetl plik

@ -116,7 +116,7 @@ class Protocol:
raise NotImplementedError()
@classmethod
def fetch(cls, obj):
def fetch(cls, obj, **kwargs):
"""Fetches a protocol-specific object and returns it in an :class:`Object`.
To be implemented by subclasses. The returned :class:`Object` is loaded
@ -126,6 +126,7 @@ class Protocol:
Args:
obj: :class:`Object` with the id to fetch. Data is filled into one of
the protocol-specific properties, eg as2, mf2, bsky.
**kwargs: subclass-specific
Raises:
:class:`werkzeug.HTTPException` if the fetch fails

Wyświetl plik

@ -307,29 +307,30 @@ class ActivityPubTest(TestCase):
return self.client.post(path, data=body, headers=self.sign(path, body))
def test_actor_fake(self, *_):
self.make_user('fake.com', cls=Fake)
got = self.client.get('/ap/fake/fake.com')
self.make_user('user.com', cls=Fake, actor_as2={
'type': 'Person',
'id': 'https://user.com/',
})
got = self.client.get('/ap/fake/user.com')
self.assertEqual(200, got.status_code, got.get_data(as_text=True))
type = got.headers['Content-Type']
self.assertTrue(type.startswith(as2.CONTENT_TYPE), type)
self.assertEqual({
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
],
'@context': ['https://w3id.org/security/v1'],
'type': 'Person',
'id': 'http://bf/fake.com/ap',
'preferredUsername': 'fake.com',
'url': 'http://localhost/r/https://fake.com',
'id': 'http://bf/fake/user.com/ap',
'preferredUsername': 'user.com',
'url': 'http://localhost/r/fake://user.com',
'summary': '',
'inbox': 'http://bf/fake.com/ap/inbox',
'outbox': 'http://bf/fake.com/ap/outbox',
'following': 'http://bf/fake.com/ap/following',
'followers': 'http://bf/fake.com/ap/followers',
'inbox': 'http://bf/fake/user.com/ap/inbox',
'outbox': 'http://bf/fake/user.com/ap/outbox',
'following': 'http://bf/fake/user.com/ap/following',
'followers': 'http://bf/fake/user.com/ap/followers',
'endpoints': {'sharedInbox': 'http://localhost/ap/sharedInbox'},
'publicKey': {
'id': 'http://localhost/fake.com',
'owner': 'http://localhost/fake.com',
'id': 'http://localhost/user.com',
'owner': 'http://localhost/user.com',
'publicKeyPem': self.user.public_pem().decode(),
},
}, got.json)
@ -1427,16 +1428,16 @@ class ActivityPubUtilsTest(TestCase):
'actor': {
'id': 'baj',
'preferredUsername': 'site',
'url': 'http://localhost/r/https://site',
'url': 'http://localhost/r/fake://site',
},
'attributedTo': [{
'id': 'bar',
'preferredUsername': 'site',
'url': 'http://localhost/r/https://site',
'url': 'http://localhost/r/fake://site',
}, {
'id': 'baz',
'preferredUsername': 'site',
'url': 'http://localhost/r/https://site',
'url': 'http://localhost/r/fake://site',
}],
'to': [as2.PUBLIC_AUDIENCE],
}, activitypub.postprocess_as2({

Wyświetl plik

@ -152,7 +152,10 @@ class PagesTest(TestCase):
def test_followers(self):
Follower.get_or_create(
to=self.user,
from_=self.make_user('no.stored/users/follow', cls=Fake))
from_=self.make_user('unused', cls=Fake, actor_as2={
**ACTOR,
'url': 'http://stored/users/follow',
}))
Follower.get_or_create(
to=self.user,
from_=self.make_user('masto/user', cls=Fake,
@ -162,7 +165,7 @@ class PagesTest(TestCase):
self.assert_equals(200, got.status_code)
body = got.get_data(as_text=True)
self.assertIn('@follow@no.stored', body)
self.assertIn('@follow@stored', body)
self.assertIn('@me@plus.google.com', body)
def test_followers_fake(self):
@ -187,7 +190,10 @@ class PagesTest(TestCase):
def test_following(self):
Follower.get_or_create(
from_=self.user,
to=self.make_user('no.stored/users/follow', cls=Fake))
to=self.make_user('unused', cls=Fake, actor_as2={
**ACTOR,
'url': 'http://stored/users/follow',
}))
Follower.get_or_create(
from_=self.user,
to=self.make_user('masto/user', cls=Fake,
@ -197,7 +203,7 @@ class PagesTest(TestCase):
self.assert_equals(200, got.status_code)
body = got.get_data(as_text=True)
self.assertIn('@follow@no.stored', body)
self.assertIn('@follow@stored', body)
self.assertIn('masto/user', body)
def test_following_empty(self):

Wyświetl plik

@ -63,7 +63,7 @@ class Fake(User, protocol.Protocol):
cls.objects[obj.key.id()] = obj
@classmethod
def fetch(cls, obj):
def fetch(cls, obj, **kwargs):
id = obj.key.id()
logger.info(f'Fake.load {id}')
cls.fetched.append(id)