Browse Source

Fix HTTPBasic realm compatibility and restore FastAPI header behavior

pull/14711/head
AnshMNSoni 6 months ago
parent
commit
ad09073385
  1. 2
      fastapi/dependencies/utils.py
  2. 1
      fastapi/security/http.py
  3. 6
      tests/test_security_http_base.py

2
fastapi/dependencies/utils.py

@ -5,7 +5,6 @@ from collections.abc import Coroutine, Mapping, Sequence
from contextlib import AsyncExitStack, contextmanager
from copy import copy, deepcopy
from dataclasses import dataclass
from typing import get_type_hints
from typing import (
Annotated,
Any,
@ -14,6 +13,7 @@ from typing import (
Optional,
Union,
cast,
get_type_hints,
)
import anyio

1
fastapi/security/http.py

@ -126,7 +126,6 @@ class HTTPBasic(HTTPBase):
def make_authenticate_headers(self) -> dict[str, str]:
return {"WWW-Authenticate": "Basic"}
async def __call__( # type: ignore
self, request: Request
) -> Optional[HTTPBasicCredentials]:

6
tests/test_security_http_base.py

@ -1,7 +1,7 @@
from fastapi import FastAPI, Security, Depends
from fastapi import Depends, FastAPI, Security
from fastapi.security import HTTPBasic
from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBase
from fastapi.testclient import TestClient
from fastapi.security import HTTPBasic
app = FastAPI()
@ -55,6 +55,7 @@ def test_openapi_schema():
},
}
def test_http_basic_includes_realm():
app = FastAPI()
security = HTTPBasic(realm="MyRealm")
@ -68,4 +69,3 @@ def test_http_basic_includes_realm():
assert response.status_code == 401
assert response.headers["WWW-Authenticate"] == 'Basic realm="MyRealm"'
Loading…
Cancel
Save