kopia lustrzana https://github.com/snarfed/bridgy-fed
for Objects for ATProto records, require at:// URIs to have DID repos
don't allow handles. https://atproto.com/specs/at-uri-schemepull/640/head
rodzic
2bb5db826c
commit
61b585e715
|
@ -486,6 +486,12 @@ class Object(StringIdModel):
|
||||||
def _pre_put_hook(self):
|
def _pre_put_hook(self):
|
||||||
assert '^^' not in self.key.id()
|
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':
|
if self.as1 and self.as1.get('objectType') == 'activity':
|
||||||
add(self.labels, 'activity')
|
add(self.labels, 'activity')
|
||||||
elif 'activity' in self.labels:
|
elif 'activity' in self.labels:
|
||||||
|
|
|
@ -441,6 +441,15 @@ class ObjectTest(TestCase):
|
||||||
self.assertIsNone(obj.mf2)
|
self.assertIsNone(obj.mf2)
|
||||||
self.assertIsNone(obj.bsky)
|
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):
|
class FollowerTest(TestCase):
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue