[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ASFF): create class #4368

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(asff): fix tests
  • Loading branch information
pedrooot committed Jul 4, 2024
commit b7451812604126de89dbafa28add868b877bcd36
2 changes: 1 addition & 1 deletion prowler/lib/outputs/asff/asff.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
Type=finding.resource_type,
Partition=finding.partition,
Region=finding.region,
Tads=resource_tags,
Tags=resource_tags,
)
],
Compliance=Compliance(
Expand All @@ -112,8 +112,8 @@
)
)

except Exception as error:
logger.error(

Check warning on line 116 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L115-L116

Added lines #L115 - L116 were not covered by tests
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)

Expand All @@ -126,33 +126,33 @@
Returns:
None
"""
try:
if self._file_descriptor and not self._file_descriptor.closed:

Check warning on line 130 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L129-L130

Added lines #L129 - L130 were not covered by tests
# Write JSON opening/header [
self._file_descriptor.write("[")

Check warning on line 132 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L132

Added line #L132 was not covered by tests

# Write findings
for finding in self._data:
dump(

Check warning on line 136 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L135-L136

Added lines #L135 - L136 were not covered by tests
finding.dict(exclude_none=True),
self._file_descriptor,
indent=4,
)
self._file_descriptor.write(",")

Check warning on line 141 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L141

Added line #L141 was not covered by tests

# Write footer/closing ]
if self._file_descriptor.tell() > 0:
if self._file_descriptor.tell() != 1:
self._file_descriptor.seek(

Check warning on line 146 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L144-L146

Added lines #L144 - L146 were not covered by tests
self._file_descriptor.tell() - 1, SEEK_SET
)
self._file_descriptor.truncate()
self._file_descriptor.write("]")

Check warning on line 150 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L149-L150

Added lines #L149 - L150 were not covered by tests

# Close file descriptor
self._file_descriptor.close()
except Exception as error:
logger.error(

Check warning on line 155 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L153-L155

Added lines #L153 - L155 were not covered by tests
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)

Expand Down Expand Up @@ -213,10 +213,10 @@
tags_dict[value[0]] = value[1]
return tags_dict
except IndexError as error:
logger.error(

Check warning on line 216 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L216

Added line #L216 was not covered by tests
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
return None

Check warning on line 219 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L219

Added line #L219 was not covered by tests
except AttributeError as error:
logger.error(
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
Expand Down Expand Up @@ -328,7 +328,7 @@
@validator("Status", pre=True, always=True)
def status(status):
if status not in ["PASSED", "WARNING", "FAILED", "NOT_AVAILABLE"]:
raise ValueError("must contain a space")

Check warning on line 331 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L331

Added line #L331 was not covered by tests
return status


Expand Down Expand Up @@ -422,5 +422,5 @@
def description_must_not_exceed_1024_chars(description):
description_validated = description
if len(description) > 1024:
description_validated = description[:1021] + "..."

Check warning on line 425 in prowler/lib/outputs/asff/asff.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/asff/asff.py#L425

Added line #L425 was not covered by tests
return description_validated
6 changes: 3 additions & 3 deletions tests/providers/aws/lib/security_hub/security_hub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_verify_security_hub_integration_enabled_per_region_security_hub_disable
(
"root",
WARNING,
f"ClientError -- [67]: An error occurred ({error_code}) when calling the {operation_name} operation: {error_message}",
f"ClientError -- [90]: An error occurred ({error_code}) when calling the {operation_name} operation: {error_message}",
)
]

Expand Down Expand Up @@ -153,7 +153,7 @@ def test_verify_security_hub_integration_enabled_per_region_another_ClientError(
(
"root",
ERROR,
f"ClientError -- [67]: An error occurred ({error_code}) when calling the {operation_name} operation: {error_message}",
f"ClientError -- [90]: An error occurred ({error_code}) when calling the {operation_name} operation: {error_message}",
)
]

Expand All @@ -179,7 +179,7 @@ def test_verify_security_hub_integration_enabled_per_region_another_Exception(
(
"root",
ERROR,
f"Exception -- [67]: {error_message}",
f"Exception -- [90]: {error_message}",
)
]

Expand Down
Loading