for Objects for ATProto records, require at:// URIs to have DID repos

don't allow handles. https://atproto.com/specs/at-uri-scheme
pull/640/head
Ryan Barrett 2023-09-13 12:51:34 -07:00
rodzic 2bb5db826c
commit 61b585e715
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 15 dodań i 0 usunięć

Wyświetl plik

@ -486,6 +486,12 @@ class Object(StringIdModel):
def _pre_put_hook(self):
assert '^^' not in self.key.id()
if self.key.id().startswith('at://'):
repo, _, _ = arroba.util.parse_at_uri(self.key.id())
if not repo.startswith('did:'):
raise ValueError(
f'at:// URI ids must have DID repos; got {self.key.id()}')
if self.as1 and self.as1.get('objectType') == 'activity':
add(self.labels, 'activity')
elif 'activity' in self.labels:

Wyświetl plik

@ -441,6 +441,15 @@ class ObjectTest(TestCase):
self.assertIsNone(obj.mf2)
self.assertIsNone(obj.bsky)
def test_validate_id(self):
# DID repo ids
Object(id='at://did:plc:123/app.bsky.feed.post/abc').put()
Object(id='at://did:plc:foo.com/app.bsky.actor.profile/self').put()
with self.assertRaises(ValueError):
# non-DID (bare handle) repo id
Object(id='at://foo.com/app.bsky.feed.post/abc').put()
class FollowerTest(TestCase):