1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-11-03 04:17:21 -05:00

Fix matching fully qualified account names

fixes #254
This commit is contained in:
Ivan Habunek 2022-12-12 12:37:24 +01:00
parent ef697c3bee
commit e2d89c2d85
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
2 changed files with 20 additions and 8 deletions

View File

@ -378,9 +378,16 @@ def test_whoami(user, run):
assert f"http://{HOSTNAME}/@{user.username}" in out
def test_whois(friend, run):
out = run("whois", friend.username)
def test_whois(app, friend, run):
variants = [
friend.username,
f"@{friend.username}",
f"{friend.username}@{app.instance}",
f"@{friend.username}@{app.instance}",
]
for username in variants:
out = run("whois", username)
assert f"@{friend.username}" in out
assert f"http://{HOSTNAME}/@{friend.username}" in out

View File

@ -270,15 +270,20 @@ def _do_upload(app, user, file, description):
def _find_account(app, user, account_name):
"""For a given account name, returns the Account object.
Raises an exception if not found.
"""
if not account_name:
raise ConsoleError("Empty account name given")
normalized_name = account_name.lstrip("@").lower()
# Strip @<instance_name> from accounts on the local instance. The `acct`
# field in account object contains the qualified name for users of other
# instances, but only the username for users of the local instance. This is
# required in order to match the account name below.
if "@" in normalized_name:
[username, instance] = normalized_name.split("@", maxsplit=1)
if instance == app.instance:
normalized_name = username
response = api.search(app, user, account_name, type="accounts", resolve=True)
for account in response["accounts"]:
if account["acct"].lower() == normalized_name: