Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Bump starlette from 0.25.0 to 0.27.0 #28

Merged
merged 3 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 10 additions & 20 deletions code/microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import Any, List, Optional
from fastapi import FastAPI, Response, HTTPException
from fastapi.params import Body
from starlette.requests import Request
from parsers import ALL_PARSERS
from utils import timeout, TimeoutExpiredError
from settings import Settings
Expand Down Expand Up @@ -106,17 +105,14 @@ def list_rules():

@microservice_api.post(
"/v1/findings"
) ### TODO: Change to have proper documentation in Swagger once https://github.com/tiangolo/fastapi/issues/1018 is fixed
)
async def generate_findings(
type: Optional[str] = "buildlog",
format: Optional[str] = "json",
request: Request = Body(None, media_type="text/plain"),
request_body: str = Body('', media_type="text/plain"),
):
request_body = (
await request.body()
) # Have to get the request body directly to allow non-JSON body until TODO is fixed ^^^
if type == "buildlog":
findings, errors = generate_buildlog_findings(request_body.decode())
findings, errors = generate_buildlog_findings(request_body)
formatter = AVAILABLE_FORMATTERS.get(format, None)
if not formatter:
raise HTTPException(
Expand All @@ -136,17 +132,14 @@ async def generate_findings(

@microservice_api.post(
"/v1/dependencies"
) ### TODO: Change to have proper documentation in Swagger once https://github.com/tiangolo/fastapi/issues/1018 is fixed
)
async def generate_dependencies(
type: Optional[str] = "buildlog",
format: Optional[str] = "json",
request: Request = Body(None, media_type="text/plain"),
request_body: str = Body('', media_type="text/plain"),
):
request_body = (
await request.body()
) # Have to get the request body directly to allow non-JSON body until TODO is fixed ^^^
if type == "buildlog":
dependencies, errors = generate_buildlog_dependencies(request_body.decode())
dependencies, errors = generate_buildlog_dependencies(request_body)
formatter = AVAILABLE_FORMATTERS.get(format, None)
if not formatter:
raise HTTPException(
Expand All @@ -167,18 +160,15 @@ async def generate_dependencies(

@microservice_api.post(
"/v1/report"
) ### TODO: Change to have proper documentation in Swagger once https://github.com/tiangolo/fastapi/issues/1018 is fixed
)
async def generate_report(
type: Optional[str] = "buildlog",
format: Optional[str] = "json",
request: Request = Body(None, media_type="text/plain"),
request_body: str = Body('', media_type="text/plain"),
):
request_body = (
await request.body()
) # Have to get the request body directly to allow non-JSON body until TODO is fixed ^^^
if type == "buildlog":
dependencies, dep_errors = generate_buildlog_dependencies(request_body.decode())
findings, fin_errors = generate_buildlog_findings(request_body.decode())
dependencies, dep_errors = generate_buildlog_dependencies(request_body)
findings, fin_errors = generate_buildlog_findings(request_body)
report = DocumentReport(
dependencies=dependencies,
findings=findings,
Expand Down
4 changes: 2 additions & 2 deletions code/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
click==7.1.2
fastapi>=0.65.2
h11==0.12.0
h11>=0.13.0
pydantic==1.8.2
starlette==0.25.0
starlette==0.27.0
typing-extensions>=3.10.0
uvicorn==0.13.4
yara-python==4.0.5
Expand Down
2 changes: 1 addition & 1 deletion tests/automated_functional_test/functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def send_test_to_API(self, test_config):
body = test_config.config.input_data
url = self.API_REPORT_PATH
try:
response = self.api_client.post(url=url,data=body.encode('utf-8'))
response = self.api_client.post(url=url, data=body.encode('utf-8'), headers={'Content-Type': 'text/plain'})
if response.status_code == 200:
return response.json()
else:
Expand Down
12 changes: 6 additions & 6 deletions tests/unit_tests/test_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_generate_findings_buildlog(
EXPECTED_RETURN = {'errors': [], 'findings': []}

# Act
response = test_client.post(url=f"/v1/findings?type={TYPE}", content=POST_DATA)
response = test_client.post(url=f"/v1/findings?type={TYPE}", content=POST_DATA, headers={'Content-Type': 'text/plain'})

# Assert
assert response.status_code == 200
Expand All @@ -148,7 +148,7 @@ def test_generate_findings_nonimplemented(test_client: TestClient):
TYPE = "anotimplementedtypeofgenerator"

# Act
response = test_client.post(url=f"/v1/findings?type={TYPE}", content=POST_DATA)
response = test_client.post(url=f"/v1/findings?type={TYPE}", content=POST_DATA, headers={'Content-Type': 'text/plain'})

# Assert
assert response.status_code == http.client.BAD_REQUEST
Expand All @@ -166,7 +166,7 @@ def test_generate_deps_buildlog(
mock_generate_deps.return_value = DEPS_RETURN

# Act
response = test_client.post(url=f"/v1/dependencies?type={TYPE}", content=POST_DATA)
response = test_client.post(url=f"/v1/dependencies?type={TYPE}", content=POST_DATA, headers={'Content-Type': 'text/plain'})

# Assert
assert response.status_code == 200
Expand All @@ -180,7 +180,7 @@ def test_generate_deps_nonimplemented(test_client: TestClient):
TYPE = "anotimplementedtypeofgenerator"

# Act
response = test_client.post(url=f"/v1/dependencies?type={TYPE}", content=POST_DATA)
response = test_client.post(url=f"/v1/dependencies?type={TYPE}", content=POST_DATA, headers={'Content-Type': 'text/plain'})

# Assert
assert response.status_code == http.client.BAD_REQUEST
Expand All @@ -206,7 +206,7 @@ def test_generate_report_buildlog(
}

# Act
response = test_client.post(url=f"/v1/report?type={TYPE}", content=POST_DATA)
response = test_client.post(url=f"/v1/report?type={TYPE}", content=POST_DATA, headers={'Content-Type': 'text/plain'})

# Assert
assert response.status_code == 200
Expand All @@ -221,7 +221,7 @@ def test_generate_report_nonimplemented(test_client: TestClient):
TYPE = "anotimplementedtypeofgenerator"

# Act
response = test_client.post(url=f"/v1/report?type={TYPE}", content=POST_DATA)
response = test_client.post(url=f"/v1/report?type={TYPE}", content=POST_DATA, headers={'Content-Type': 'text/plain'})

# Assert
assert response.status_code == http.client.BAD_REQUEST
Expand Down