The following issues were found
tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py
8 issues
Line: 4
Column: 1
import gzip
import json
import pytest
from fastapi import Request
from fastapi.testclient import TestClient
from docs_src.custom_request_and_route.tutorial001 import app
Reported by Pylint.
Line: 1
Column: 1
import gzip
import json
import pytest
from fastapi import Request
from fastapi.testclient import TestClient
from docs_src.custom_request_and_route.tutorial001 import app
Reported by Pylint.
Line: 12
Column: 1
@app.get("/check-class")
async def check_gzip_request(request: Request):
return {"request_class": type(request).__name__}
client = TestClient(app)
Reported by Pylint.
Line: 20
Column: 1
@pytest.mark.parametrize("compress", [True, False])
def test_gzip_request(compress):
n = 1000
headers = {}
body = [1] * n
data = json.dumps(body).encode()
if compress:
Reported by Pylint.
Line: 21
Column: 5
@pytest.mark.parametrize("compress", [True, False])
def test_gzip_request(compress):
n = 1000
headers = {}
body = [1] * n
data = json.dumps(body).encode()
if compress:
data = gzip.compress(data)
Reported by Pylint.
Line: 30
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
headers["Content-Encoding"] = "gzip"
headers["Content-Type"] = "application/json"
response = client.post("/sum", data=data, headers=headers)
assert response.json() == {"sum": n}
def test_request_class():
response = client.get("/check-class")
assert response.json() == {"request_class": "GzipRequest"}
Reported by Bandit.
Line: 33
Column: 1
assert response.json() == {"sum": n}
def test_request_class():
response = client.get("/check-class")
assert response.json() == {"request_class": "GzipRequest"}
Reported by Pylint.
Line: 35
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_request_class():
response = client.get("/check-class")
assert response.json() == {"request_class": "GzipRequest"}
Reported by Bandit.
tests/test_tutorial/test_body_multiple_params/test_tutorial003.py
8 issues
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.body_multiple_params.tutorial003 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.body_multiple_params.tutorial003 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 115
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 117
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
# Test required and embedded body parameters with no bodies sent
@pytest.mark.parametrize(
Reported by Bandit.
Line: 118
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
# Test required and embedded body parameters with no bodies sent
@pytest.mark.parametrize(
"path,body,expected_status,expected_response",
Reported by Bandit.
Line: 189
Column: 1
"loc": ["body", "importance"],
"msg": "field required",
"type": "value_error.missing",
},
]
},
),
],
)
Reported by Pylint.
Line: 197
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test_post_body(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
Line: 198
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_post_body(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
docs_src/body_multiple_params/tutorial003.py
8 issues
Line: 3
Column: 1
from typing import Optional
from fastapi import Body, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
Reported by Pylint.
Line: 4
Column: 1
from typing import Optional
from fastapi import Body, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
Reported by Pylint.
Line: 1
Column: 1
from typing import Optional
from fastapi import Body, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
Reported by Pylint.
Line: 16
Column: 1
tax: Optional[float] = None
class User(BaseModel):
username: str
full_name: Optional[str] = None
@app.put("/items/{item_id}")
Reported by Pylint.
Line: 16
Column: 1
tax: Optional[float] = None
class User(BaseModel):
username: str
full_name: Optional[str] = None
@app.put("/items/{item_id}")
Reported by Pylint.
Line: 22
Column: 1
@app.put("/items/{item_id}")
async def update_item(
item_id: int, item: Item, user: User, importance: int = Body(...)
):
results = {"item_id": item_id, "item": item, "user": user, "importance": importance}
return results
Reported by Pylint.
tests/test_openapi_servers.py
8 issues
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.testclient import TestClient
app = FastAPI(
servers=[
{"url": "/", "description": "Default, relative server"},
{
"url": "http://staging.localhost.tiangolo.com:8000",
"description": "Staging but actually localhost still",
Reported by Pylint.
Line: 17
Column: 1
@app.get("/foo")
def foo():
return {"message": "Hello World"}
client = TestClient(app)
Reported by Pylint.
Line: 17
Column: 1
@app.get("/foo")
def foo():
return {"message": "Hello World"}
client = TestClient(app)
Reported by Pylint.
Line: 52
Column: 1
}
def test_openapi_servers():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 54
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_servers():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_app():
response = client.get("/foo")
Reported by Bandit.
Line: 55
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_servers():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_app():
response = client.get("/foo")
assert response.status_code == 200, response.text
Reported by Bandit.
Line: 58
Column: 1
assert response.json() == openapi_schema
def test_app():
response = client.get("/foo")
assert response.status_code == 200, response.text
Reported by Pylint.
Line: 60
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_app():
response = client.get("/foo")
assert response.status_code == 200, response.text
Reported by Bandit.
tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py
8 issues
Line: 1
Column: 1
from fastapi.testclient import TestClient
from docs_src.custom_request_and_route.tutorial003 import app
client = TestClient(app)
def test_get():
response = client.get("/")
Reported by Pylint.
Line: 8
Column: 1
client = TestClient(app)
def test_get():
response = client.get("/")
assert response.json() == {"message": "Not timed"}
assert "X-Response-Time" not in response.headers
Reported by Pylint.
Line: 10
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_get():
response = client.get("/")
assert response.json() == {"message": "Not timed"}
assert "X-Response-Time" not in response.headers
def test_get_timed():
response = client.get("/timed")
Reported by Bandit.
Line: 11
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_get():
response = client.get("/")
assert response.json() == {"message": "Not timed"}
assert "X-Response-Time" not in response.headers
def test_get_timed():
response = client.get("/timed")
assert response.json() == {"message": "It's the time of my life"}
Reported by Bandit.
Line: 14
Column: 1
assert "X-Response-Time" not in response.headers
def test_get_timed():
response = client.get("/timed")
assert response.json() == {"message": "It's the time of my life"}
assert "X-Response-Time" in response.headers
assert float(response.headers["X-Response-Time"]) >= 0
Reported by Pylint.
Line: 16
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_get_timed():
response = client.get("/timed")
assert response.json() == {"message": "It's the time of my life"}
assert "X-Response-Time" in response.headers
assert float(response.headers["X-Response-Time"]) >= 0
Reported by Bandit.
Line: 17
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_get_timed():
response = client.get("/timed")
assert response.json() == {"message": "It's the time of my life"}
assert "X-Response-Time" in response.headers
assert float(response.headers["X-Response-Time"]) >= 0
Reported by Bandit.
Line: 18
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
response = client.get("/timed")
assert response.json() == {"message": "It's the time of my life"}
assert "X-Response-Time" in response.headers
assert float(response.headers["X-Response-Time"]) >= 0
Reported by Bandit.
docs_src/body_multiple_params/tutorial002.py
8 issues
Line: 3
Column: 1
from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
Reported by Pylint.
Line: 4
Column: 1
from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
Reported by Pylint.
Line: 1
Column: 1
from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
Reported by Pylint.
Line: 16
Column: 1
tax: Optional[float] = None
class User(BaseModel):
username: str
full_name: Optional[str] = None
@app.put("/items/{item_id}")
Reported by Pylint.
Line: 16
Column: 1
tax: Optional[float] = None
class User(BaseModel):
username: str
full_name: Optional[str] = None
@app.put("/items/{item_id}")
Reported by Pylint.
Line: 22
Column: 1
@app.put("/items/{item_id}")
async def update_item(item_id: int, item: Item, user: User):
results = {"item_id": item_id, "item": item, "user": user}
return results
Reported by Pylint.
tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py
8 issues
Line: 1
Column: 1
from fastapi.testclient import TestClient
from docs_src.path_operation_configuration.tutorial005 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
Reported by Pylint.
Line: 34
Column: 1
},
},
"summary": "Create an item",
"description": "Create an item with all the information:\n\n- **name**: each item must have a name\n- **description**: a long description\n- **price**: required\n- **tax**: if the item doesn't have tax, you can omit this\n- **tags**: a set of unique tag strings for this item",
"operationId": "create_item_items__post",
"requestBody": {
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/Item"}
Reported by Pylint.
Line: 97
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 99
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
Reported by Bandit.
Line: 100
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
Reported by Bandit.
Line: 103
Column: 1
assert response.json() == openapi_schema
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
"name": "Foo",
"price": 42,
Reported by Pylint.
Line: 105
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
"name": "Foo",
"price": 42,
"description": None,
"tax": None,
Reported by Bandit.
Line: 106
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
"name": "Foo",
"price": 42,
"description": None,
"tax": None,
"tags": [],
Reported by Bandit.
fastapi/security/open_id_connect_url.py
8 issues
Line: 5
Column: 1
from fastapi.openapi.models import OpenIdConnect as OpenIdConnectModel
from fastapi.security.base import SecurityBase
from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.status import HTTP_403_FORBIDDEN
class OpenIdConnect(SecurityBase):
Reported by Pylint.
Line: 6
Column: 1
from fastapi.openapi.models import OpenIdConnect as OpenIdConnectModel
from fastapi.security.base import SecurityBase
from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.status import HTTP_403_FORBIDDEN
class OpenIdConnect(SecurityBase):
def __init__(
Reported by Pylint.
Line: 7
Column: 1
from fastapi.security.base import SecurityBase
from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.status import HTTP_403_FORBIDDEN
class OpenIdConnect(SecurityBase):
def __init__(
self,
Reported by Pylint.
Line: 1
Column: 1
from typing import Optional
from fastapi.openapi.models import OpenIdConnect as OpenIdConnectModel
from fastapi.security.base import SecurityBase
from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.status import HTTP_403_FORBIDDEN
Reported by Pylint.
Line: 10
Column: 1
from starlette.status import HTTP_403_FORBIDDEN
class OpenIdConnect(SecurityBase):
def __init__(
self,
*,
openIdConnectUrl: str,
scheme_name: Optional[str] = None,
Reported by Pylint.
Line: 10
Column: 1
from starlette.status import HTTP_403_FORBIDDEN
class OpenIdConnect(SecurityBase):
def __init__(
self,
*,
openIdConnectUrl: str,
scheme_name: Optional[str] = None,
Reported by Pylint.
Line: 14
Column: 9
def __init__(
self,
*,
openIdConnectUrl: str,
scheme_name: Optional[str] = None,
description: Optional[str] = None,
auto_error: bool = True
):
self.model = OpenIdConnectModel(
Reported by Pylint.
Line: 28
Column: 13
async def __call__(self, request: Request) -> Optional[str]:
authorization: str = request.headers.get("Authorization")
if not authorization:
if self.auto_error:
raise HTTPException(
status_code=HTTP_403_FORBIDDEN, detail="Not authenticated"
)
else:
return None
Reported by Pylint.
tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py
8 issues
Line: 1
Column: 1
from fastapi.testclient import TestClient
from docs_src.path_operation_advanced_configuration.tutorial004 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
Reported by Pylint.
Line: 34
Column: 1
},
},
"summary": "Create an item",
"description": "Create an item with all the information:\n\n- **name**: each item must have a name\n- **description**: a long description\n- **price**: required\n- **tax**: if the item doesn't have tax, you can omit this\n- **tags**: a set of unique tag strings for this item\n",
"operationId": "create_item_items__post",
"requestBody": {
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/Item"}
Reported by Pylint.
Line: 97
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 99
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
Reported by Bandit.
Line: 100
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
Reported by Bandit.
Line: 103
Column: 1
assert response.json() == openapi_schema
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
"name": "Foo",
"price": 42,
Reported by Pylint.
Line: 105
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
"name": "Foo",
"price": 42,
"description": None,
"tax": None,
Reported by Bandit.
Line: 106
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
"name": "Foo",
"price": 42,
"description": None,
"tax": None,
"tags": [],
Reported by Bandit.
tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py
8 issues
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.path_operation_configuration.tutorial006 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.path_operation_configuration.tutorial006 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 56
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 58
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
@pytest.mark.parametrize(
"path,expected_status,expected_response",
Reported by Bandit.
Line: 59
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
@pytest.mark.parametrize(
"path,expected_status,expected_response",
[
Reported by Bandit.
Line: 68
Column: 1
("/items/", 200, [{"name": "Foo", "price": 42}]),
("/users/", 200, [{"username": "johndoe"}]),
("/elements/", 200, [{"item_id": "Foo"}]),
],
)
def test_query_params_str_validations(path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Pylint.
Line: 72
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test_query_params_str_validations(path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
Line: 73
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_query_params_str_validations(path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.