mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-23 09:15:32 +00:00
Refactor; failing tests for some reason.
This commit is contained in:
@ -106,28 +106,31 @@ def _authorization_decorator(required_secrets):
|
|||||||
def decorator(f):
|
def decorator(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def route(self, request, *args, **kwargs):
|
def route(self, request, *args, **kwargs):
|
||||||
if not timing_safe_compare(
|
|
||||||
request.requestHeaders.getRawHeaders("Authorization", [""])[0].encode(
|
|
||||||
"utf-8"
|
|
||||||
),
|
|
||||||
swissnum_auth_header(self._swissnum),
|
|
||||||
):
|
|
||||||
request.setResponseCode(http.UNAUTHORIZED)
|
|
||||||
return b""
|
|
||||||
authorization = request.requestHeaders.getRawHeaders(
|
|
||||||
"X-Tahoe-Authorization", []
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
secrets = _extract_secrets(authorization, required_secrets)
|
|
||||||
except ClientSecretsException:
|
|
||||||
request.setResponseCode(http.BAD_REQUEST)
|
|
||||||
return b"Missing required secrets"
|
|
||||||
with start_action(
|
with start_action(
|
||||||
action_type="allmydata:storage:http-server:request",
|
action_type="allmydata:storage:http-server:handle_request",
|
||||||
method=request.method,
|
method=request.method,
|
||||||
path=request.path,
|
path=request.path,
|
||||||
) as ctx:
|
) as ctx:
|
||||||
try:
|
try:
|
||||||
|
# Check Authorization header:
|
||||||
|
if not timing_safe_compare(
|
||||||
|
request.requestHeaders.getRawHeaders("Authorization", [""])[0].encode(
|
||||||
|
"utf-8"
|
||||||
|
),
|
||||||
|
swissnum_auth_header(self._swissnum),
|
||||||
|
):
|
||||||
|
raise _HTTPError(http.UNAUTHORIZED)
|
||||||
|
|
||||||
|
# Check secrets:
|
||||||
|
authorization = request.requestHeaders.getRawHeaders(
|
||||||
|
"X-Tahoe-Authorization", []
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
secrets = _extract_secrets(authorization, required_secrets)
|
||||||
|
except ClientSecretsException:
|
||||||
|
raise _HTTPError(http.BAD_REQUEST)
|
||||||
|
|
||||||
|
# Run the business logic:
|
||||||
result = f(self, request, secrets, *args, **kwargs)
|
result = f(self, request, secrets, *args, **kwargs)
|
||||||
except _HTTPError as e:
|
except _HTTPError as e:
|
||||||
# This isn't an error necessarily for logging purposes,
|
# This isn't an error necessarily for logging purposes,
|
||||||
@ -136,8 +139,9 @@ def _authorization_decorator(required_secrets):
|
|||||||
ctx.add_success_fields(response_code=e.code)
|
ctx.add_success_fields(response_code=e.code)
|
||||||
ctx.finish()
|
ctx.finish()
|
||||||
raise
|
raise
|
||||||
ctx.add_success_fields(response_code=request.code)
|
else:
|
||||||
return result
|
ctx.add_success_fields(response_code=request.code)
|
||||||
|
return result
|
||||||
|
|
||||||
return route
|
return route
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user