mirror of https://github.com/tiangolo/fastapi.git
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
This commit is contained in:
parent
7596d0cbfd
commit
3d124f0b18
|
|
@ -1,4 +1,4 @@
|
|||
from fastapi import Depends, FastAPI, HTTPException
|
||||
from fastapi import Depends, FastAPI
|
||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
|
@ -6,17 +6,21 @@ app = FastAPI()
|
|||
|
||||
security = HTTPBasic(realm="")
|
||||
|
||||
|
||||
@app.get("/users/me")
|
||||
def read_current_user(credentials: HTTPBasicCredentials = Depends(security)):
|
||||
return {"username": credentials.username, "password": credentials.password}
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_security_http_basic_empty_realm():
|
||||
response = client.get("/users/me", auth=("john", "secret"))
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == {"username": "john", "password": "secret"}
|
||||
|
||||
|
||||
def test_security_http_basic_invalid_credentials_empty_realm():
|
||||
response = client.get(
|
||||
"/users/me", headers={"Authorization": "Basic notabase64token"}
|
||||
|
|
|
|||
Loading…
Reference in New Issue