Skip to content

Commit 2adc661

Browse files
committed
1 parent 9011fa2 commit 2adc661

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

atproto.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ def owns_handle(cls, handle, allow_internal=False):
241241

242242
@classmethod
243243
def handle_to_id(cls, handle):
244-
assert cls.owns_handle(handle) is not False
244+
if not handle or cls.owns_handle(handle) is False:
245+
return None
245246

246247
# TODO: shortcut our own handles? eg snarfed.org.web.brid.gy
247248

tests/test_atproto.py

+5
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ def test_handle_to_id(self):
154154
self.make_user('did:plc:user', cls=ATProto)
155155
self.assertEqual('did:plc:user', ATProto.handle_to_id('ha.nl'))
156156

157+
def test_handle_to_id_bad(self):
158+
for bad in None, '', '.bsky.social':
159+
with self.subTest(bad=bad):
160+
self.assertIsNone(ATProto.handle_to_id(bad))
161+
157162
def test_handle_to_id_first_opted_out(self):
158163
self.store_object(id='did:plc:user', raw=DID_DOC)
159164
user = self.make_user('did:plc:user', cls=ATProto)

tests/test_redirect.py

+20
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ def test_redirect_scheme_missing(self):
5050
got = self.client.get('/r/user.com')
5151
self.assertEqual(400, got.status_code)
5252

53+
def test_redirect_not_url(self):
54+
got = self.client.get('/r/foo:bar:baz')
55+
self.assertEqual(400, got.status_code)
56+
57+
def test_as2_not_web(self):
58+
got = self.client.get('/r/foo:bar:baz',
59+
headers={'Accept': as2.CONTENT_TYPE_LD_PROFILE})
60+
self.assertEqual(400, got.status_code)
61+
62+
def test_redirect_bsky_app_url(self):
63+
got = self.client.get('/r/https://bsky.app/profile/.bsky.social')
64+
self.assertEqual(301, got.status_code)
65+
self.assertEqual('https://bsky.app/profile/.bsky.social',
66+
got.headers['Location'])
67+
68+
def test_as2_bsky_app_url(self):
69+
got = self.client.get('/r/https://bsky.app/profile/.bsky.social',
70+
headers={'Accept': as2.CONTENT_TYPE_LD_PROFILE})
71+
self.assertEqual(404, got.status_code)
72+
5373
def test_redirect_url_missing(self):
5474
got = self.client.get('/r/')
5575
self.assertEqual(404, got.status_code)

0 commit comments

Comments
 (0)