mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-09 21:14:22 +00:00
fix(OCSF): fix OCSF output when timestamp is UNIX format (#6627)
Co-authored-by: Rubén De la Torre Vico <rubendltv22@gmail.com>
This commit is contained in:
co-authored by
Rubén De la Torre Vico
parent
1140c29384
commit
7f33ea76a4
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from typing import Union
|
||||
|
||||
from prowler.config.config import prowler_version
|
||||
from prowler.lib.check.models import CheckMetadata, Code, Recommendation, Remediation
|
||||
@@ -19,7 +20,7 @@ def generate_finding_output(
|
||||
resource_name: str = "",
|
||||
resource_tags: dict = {},
|
||||
compliance: dict = {"test-compliance": "test-compliance"},
|
||||
timestamp: datetime = None,
|
||||
timestamp: Union[int, datetime] = None,
|
||||
provider: str = "aws",
|
||||
partition: str = "aws",
|
||||
description: str = "check description",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from io import StringIO
|
||||
|
||||
import requests
|
||||
@@ -36,7 +36,15 @@ class TestOCSF:
|
||||
muted=False,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
resource_tags={"Name": "test", "Environment": "dev"},
|
||||
)
|
||||
),
|
||||
# Test with int timestamp (UNIX timestamp)
|
||||
generate_finding_output(
|
||||
status="FAIL",
|
||||
severity="medium",
|
||||
muted=False,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
timestamp=1619600000,
|
||||
),
|
||||
]
|
||||
|
||||
ocsf = OCSF(findings)
|
||||
@@ -101,6 +109,14 @@ class TestOCSF:
|
||||
"compliance": findings[0].compliance,
|
||||
}
|
||||
|
||||
# Test with int timestamp (UNIX timestamp)
|
||||
output_data = ocsf.data[1]
|
||||
|
||||
assert output_data.time == 1619600000
|
||||
assert output_data.time_dt == datetime.fromtimestamp(
|
||||
1619600000, tz=timezone.utc
|
||||
)
|
||||
|
||||
def test_validate_ocsf(self):
|
||||
mock_file = StringIO()
|
||||
findings = [
|
||||
|
||||
Reference in New Issue
Block a user