Skip to content

Commit

Permalink
chore: check for version and unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanFl committed Nov 6, 2024
1 parent d79d244 commit 63dc750
Show file tree
Hide file tree
Showing 7 changed files with 556 additions and 138 deletions.
20 changes: 19 additions & 1 deletion backend/application/import_observations/parsers/ocsf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
StatusID,
)
from py_ocsf_models.events.findings.finding import ActivityID
from rest_framework.exceptions import ValidationError
from semver import Version

from application.core.models import Observation
from application.core.types import Severity
Expand Down Expand Up @@ -56,6 +58,22 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict | list]:
{},
)

tool_name = (
first_element.get("metadata", {}).get("product", {}).get("name", "")
)
tool_version = (
first_element.get("metadata", {}).get("product", {}).get("version", "")
)
if tool_name == "Prowler":
if not tool_version or Version.parse(tool_version) < Version.parse(
"4.5.0"
):
return (
False,
["Prowler is only supported with version 4.5.0 and above"],
{},
)

return True, [], data

def get_observations(self, data: list) -> list[Observation]:
Expand Down Expand Up @@ -108,7 +126,7 @@ def get_observations(self, data: list) -> list[Observation]:

observation.unsaved_references = get_references(finding)
except Exception as e:
logger.warning("Error parsing OCSF finding: %s", str(e))
raise ValidationError(f"Error parsing OCSF finding: {str(e)}")

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

return observations

Expand Down
19 changes: 15 additions & 4 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ jira = "3.8.0" # https://github.com/pycontribs/jira
inflect = "7.4.0" # https://github.com/jaraco/inflect
validators = "0.34.0" # https://github.com/python-validators/validators
cvss = "3.3" # https://github.com/RedHatProductSecurity/cvss
jsonpickle = "3.4.1" # https://github.com/jsonpickle/jsonpickle
py-ocsf-models="0.2.0" # https://github.com/prowler-cloud/py-ocsf-models
jsonpickle = "3.4.2" # https://github.com/jsonpickle/jsonpickle
py-ocsf-models = "0.2.0" # https://github.com/prowler-cloud/py-ocsf-models
semver = "3.0.2" # https://github.com/python-semver/python-semver

# Development dependencies
# ------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"product": {
"name": "Prowler",
"vendor_name": "Prowler",
"version": "4.3.5"
"version": "4.5.5"
},
"version": "1.2.0"
},
Expand Down
Loading

0 comments on commit 63dc750

Please sign in to comment.