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
1 changed files with 2 additions and 2 deletions

View File

@ -13,11 +13,11 @@ class MetricsView(View):
def get(self, request: HttpRequest) -> HttpResponse:
"""Check for HTTP-Basic auth"""
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}"
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['WWW-Authenticate'] = 'Basic realm="passbook-monitoring"'
return response