middleware: Make HostDomain into a process_request, not process_response.

It is more suited for `process_request`, since it should stop
execution of the request if the domain is invalid.  This code was
likely added as a process_response (in ea39fb2556) because there was
already a process_response at the time (added 7e786d5426, and no
longer necessary since dce6b4a40f).

It quiets an unnecessary warning when logging in at a non-existent
realm.

This stops performing unnecessary work when we are going to throw it
away and return a 404.  The edge case to this is if the request
_creates_ a realm, and is made using the URL of the new realm; this
change would prevent the request before it occurs. While this does
arise in tests, the tests do not reflect reality -- real requests to
/accounts/register/ are made via POST to the same (default) realm,
redirected there from `confirm-preregistrationuser`.  The tests are
adjusted to reflect real behavior.

Tweaked by tabbott to add a block comment in HostDomainMiddleware.
This commit is contained in:
Alex Vandiver
2020-08-06 17:09:59 -07:00
committed by Tim Abbott
parent 816f91ae27
commit f00ff1ef62
3 changed files with 25 additions and 42 deletions

View File

@@ -343,12 +343,7 @@ class OurAuthenticationForm(AuthenticationForm):
if username is not None and password:
subdomain = get_subdomain(self.request)
try:
realm = get_realm(subdomain)
except Realm.DoesNotExist:
logging.warning("User %s attempted password login to nonexistent subdomain %s",
username, subdomain)
raise ValidationError("Realm does not exist")
realm = get_realm(subdomain)
return_data: Dict[str, Any] = {}
try: