Ensure usernames and domains are lowercase

This commit is contained in:
Andrew Godwin 2022-11-24 16:27:21 -07:00
parent ec634f2ad3
commit 3a608c2012
2 changed files with 6 additions and 4 deletions

View File

@ -59,13 +59,14 @@ class Domain(models.Model):
@classmethod
def get_remote_domain(cls, domain: str) -> "Domain":
return cls.objects.get_or_create(domain=domain, local=False)[0]
return cls.objects.get_or_create(domain=domain.lower(), local=False)[0]
@classmethod
def get_domain(cls, domain: str) -> Optional["Domain"]:
try:
return cls.objects.get(
models.Q(domain=domain) | models.Q(service_domain=domain)
models.Q(domain=domain.lower())
| models.Q(service_domain=domain.lower())
)
except cls.DoesNotExist:
return None

View File

@ -153,6 +153,7 @@ class Identity(StatorModel):
if username.startswith("@"):
raise ValueError("Username must not start with @")
username = username.lower()
domain = domain.lower()
try:
if local:
return cls.objects.get(username=username, domain_id=domain, local=True)
@ -300,7 +301,7 @@ class Identity(StatorModel):
Given a username@domain handle, returns a tuple of
(actor uri, canonical handle) or None, None if it does not resolve.
"""
domain = handle.split("@")[1]
domain = handle.split("@")[1].lower()
try:
response = await SystemActor().signed_request(
method="get",
@ -381,7 +382,7 @@ class Identity(StatorModel):
)
if webfinger_handle:
webfinger_username, webfinger_domain = webfinger_handle.split("@")
self.username = webfinger_username
self.username = webfinger_username.lower()
self.domain = await get_domain(webfinger_domain)
else:
self.domain = await get_domain(actor_url_parts.hostname)