Browse Source
🐛 Strip whitespaces from `Authorization` header credentials (#14786)
pull/14816/head
Cecilia Madrid
4 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
13 additions and
1 deletions
-
fastapi/security/utils.py
-
tests/test_security_http_base.py
-
tests/test_security_oauth2_authorization_code_bearer.py
|
|
|
@ -7,4 +7,4 @@ def get_authorization_scheme_param( |
|
|
|
if not authorization_header_value: |
|
|
|
return "", "" |
|
|
|
scheme, _, param = authorization_header_value.partition(" ") |
|
|
|
return scheme, param |
|
|
|
return scheme, param.strip() |
|
|
|
|
|
|
|
@ -21,6 +21,12 @@ def test_security_http_base(): |
|
|
|
assert response.json() == {"scheme": "Other", "credentials": "foobar"} |
|
|
|
|
|
|
|
|
|
|
|
def test_security_http_base_with_whitespaces(): |
|
|
|
response = client.get("/users/me", headers={"Authorization": "Other foobar "}) |
|
|
|
assert response.status_code == 200, response.text |
|
|
|
assert response.json() == {"scheme": "Other", "credentials": "foobar"} |
|
|
|
|
|
|
|
|
|
|
|
def test_security_http_base_no_credentials(): |
|
|
|
response = client.get("/users/me") |
|
|
|
assert response.status_code == 401, response.text |
|
|
|
|
|
|
|
@ -37,6 +37,12 @@ def test_token(): |
|
|
|
assert response.json() == {"token": "testtoken"} |
|
|
|
|
|
|
|
|
|
|
|
def test_token_with_whitespaces(): |
|
|
|
response = client.get("/items", headers={"Authorization": "Bearer testtoken "}) |
|
|
|
assert response.status_code == 200, response.text |
|
|
|
assert response.json() == {"token": "testtoken"} |
|
|
|
|
|
|
|
|
|
|
|
def test_openapi_schema(): |
|
|
|
response = client.get("/openapi.json") |
|
|
|
assert response.status_code == 200, response.text |
|
|
|
|