♻️(backend) refactor Bearer Auth based authentification

Created a shared class for handling Header based authentification.
This avoid duplicating logic and helps with a maintaining a signle
security related peace of code.
This commit is contained in:
Florent Chehab
2026-07-02 15:27:15 +02:00
committed by aleb_the_flash
parent 7fa172d100
commit 3c0ba03976
2 changed files with 40 additions and 66 deletions
@@ -136,10 +136,10 @@ def test_authenticate_header():
def test_multiple_spaces_in_auth_header(settings):
"""Test failure when Authorization header contains multiple spaces."""
"""Test success when Authorization header contains multiple spaces."""
settings.RECORDING_STORAGE_EVENT_TOKEN = "valid-test-token"
request = RequestFactory().get("/")
request.headers = {"Authorization": "Bearer extra-spaces-token"}
with pytest.raises(AuthenticationFailed, match="Invalid authorization header"):
StorageEventAuthentication().authenticate(request)
header = StorageEventAuthentication().authenticate_header(request)
assert header == "Bearer realm='Storage event API'"