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

Commit

Permalink
Merge pull request #28 from vmware-labs/bump-version-starlette-0.27
Browse files Browse the repository at this point in the history
Bump starlette from 0.25.0 to 0.27.0
  • Loading branch information
loredous committed Jun 1, 2023
2 parents 37ecaf1 + cb0f7fc commit 8967be9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
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

0 comments on commit 8967be9

Please sign in to comment.