Skip to content

Commit

Permalink
ATProto.create_for: don't set DNS if the user has a custom domain handle
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Dec 11, 2024
1 parent a09a358 commit 38b0f70
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
9 changes: 7 additions & 2 deletions atproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
DOMAINS,
error,
PRIMARY_DOMAIN,
SUPERDOMAIN,
USER_AGENT,
)
import flask_app
Expand Down Expand Up @@ -403,7 +404,8 @@ def create_for(cls, user):
# deactivated or deleted, or maybe still active?
arroba.server.storage.activate_repo(repo)
common.create_task(queue='atproto-commit')
cls.set_dns(handle=handle, did=copy_did)
if handle.endswith(SUPERDOMAIN):
cls.set_dns(handle=handle, did=copy_did)
return

# create new DID, repo
Expand Down Expand Up @@ -549,10 +551,13 @@ def set_username(to_cls, user, username):
did.update_plc(did=copy_did, handle=username,
signing_key=repo.signing_key, rotation_key=repo.rotation_key,
get_fn=util.requests_get, post_fn=util.requests_post)
repo.handle = username
arroba.server.storage.store_repo(repo)
arroba.server.storage.write_event(repo=repo, type='identity', handle=username)

# refresh our stored DID doc
# refresh our stored DID doc and repo handle
to_cls.load(copy_did, did_doc=True, remote=True)
repo.handle = username

@classmethod
def send(to_cls, obj, url, from_user=None, orig_obj_id=None):
Expand Down
1 change: 0 additions & 1 deletion atproto_firehose.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
report_exception,
USER_AGENT,
)
from models import Object, reset_protocol_properties
from protocol import DELETE_TASK_DELAY
from web import Web

Expand Down
32 changes: 32 additions & 0 deletions tests/test_atproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,24 @@ def test_create_for_already_exists(self, mock_create_task, mock_zone,

mock_create_task.assert_called() # atproto-commit

@patch('atproto.DEBUG', new=False)
@patch('google.cloud.dns.client.ManagedZone', autospec=True)
@patch.object(tasks_client, 'create_task', return_value=Task(name='my task'))
def test_create_for_already_exists_custom_handle(self, mock_create_task,
mock_zone):
"""Shouldn't try to create DNS for custom handle's domain."""
self.make_user_and_repo()
repo = arroba.server.storage.load_repo('did:plc:user')

ATProto.create_for(self.user)

# shouldn't set DNS
mock_zone.assert_not_called()

# check repo
repo = arroba.server.storage.load_repo('did:plc:user')
self.assertEqual('han.dull', repo.handle)

@patch('atproto.DEBUG', new=False)
@patch.object(atproto.dns_discovery_api, 'resourceRecordSets')
@patch('google.cloud.dns.client.ManagedZone', autospec=True)
Expand Down Expand Up @@ -1312,6 +1330,8 @@ def test_set_username(self, mock_post, mock_get, mock_create_task, _):
}, timeout=15, stream=True, headers=ANY)

self.assertEqual('ne.w', user.handle_as(ATProto))
repo = arroba.server.storage.load_repo('did:plc:user')
self.assertEqual('ne.w', repo.handle)

# check #identity event
seq = self.storage.last_seq(SUBSCRIBE_REPOS_NSID)
Expand All @@ -1336,6 +1356,10 @@ def test_set_username_handle_doesnt_resolve(self, _, __):

self.assertIn("You'll need to connect that domain", str(e.exception))

self.assertEqual('ha.nl', user.handle_as(ATProto))
repo = arroba.server.storage.load_repo('did:plc:user')
self.assertEqual('han.dull', repo.handle)

# resolve handle, DNS method, not found
@patch('dns.resolver.resolve', side_effect=NXDOMAIN())
# resolve handle, HTTPS method, wrong did
Expand All @@ -1348,6 +1372,10 @@ def test_set_username_handle_resolves_to_wrong_did(self, _, __):

self.assertIn("You'll need to connect that domain", str(e.exception))

self.assertEqual('ha.nl', user.handle_as(ATProto))
repo = arroba.server.storage.load_repo('did:plc:user')
self.assertEqual('han.dull', repo.handle)

def test_set_username_atproto_not_enabled(self):
user = self.make_user_and_repo()

Expand All @@ -1364,6 +1392,10 @@ def test_set_username_not_domain(self):

self.assertEqual("bad nope doesn't look like a domain", str(e.exception))

self.assertEqual('ha.nl', user.handle_as(ATProto))
repo = arroba.server.storage.load_repo('did:plc:user')
self.assertEqual('han.dull', repo.handle)

@patch('google.cloud.dns.client.ManagedZone', autospec=True)
@patch.object(tasks_client, 'create_task', return_value=Task(name='my task'))
@patch('requests.post', return_value=requests_response('OK')) # create DID on PLC
Expand Down

0 comments on commit 38b0f70

Please sign in to comment.