root: fix credential variables overwriting each other

This commit is contained in:
Jens Langhammer 2020-01-17 11:16:23 +01:00
parent 78301b7bab
commit fc4a46bd9c

View file

@ -13,11 +13,11 @@ class MetricsView(View):
def get(self, request: HttpRequest) -> HttpResponse: def get(self, request: HttpRequest) -> HttpResponse:
"""Check for HTTP-Basic auth""" """Check for HTTP-Basic auth"""
auth_header = request.META.get("HTTP_AUTHORIZATION", "") auth_header = request.META.get("HTTP_AUTHORIZATION", "")
auth_type, _, credentials = auth_header.partition(" ") auth_type, _, given_credentials = auth_header.partition(" ")
credentials = f"monitor:{settings.SECRET_KEY}" credentials = f"monitor:{settings.SECRET_KEY}"
expected = b64encode(str.encode(credentials)).decode() expected = b64encode(str.encode(credentials)).decode()
if auth_type != "Basic" or credentials != expected: if auth_type != "Basic" or given_credentials != expected:
response = HttpResponse(status=401) response = HttpResponse(status=401)
response['WWW-Authenticate'] = 'Basic realm="passbook-monitoring"' response['WWW-Authenticate'] = 'Basic realm="passbook-monitoring"'
return response return response