Skip to content

Commit

Permalink
feat: Added Exit codes and updated unit tests #547 (#548)
Browse files Browse the repository at this point in the history
secureli-375
#375

<!-- Include general description here -->
Added Additional Exit Codes based on error types as discussed. Passing
exitCode to the ScanFailure class

## Changes
<!-- A detailed list of changes -->
* Added Exit Codes
* Updated ScanFailure
* Updated Unit Tests
* Verified no additional errors

## Testing
<!--
Mention updated tests and any manual testing performed.
Are aspects not yet tested or not easily testable?
Feel free to include screenshots if appropriate.
 -->
*

## Clean Code Checklist
<!-- This is here to support you. Some/most checkboxes may not apply to
your change -->
- [x] Meets acceptance criteria for issue
- [x] New logic is covered with automated tests
- [ ] Appropriate exception handling added
- [ ] Thoughtful logging included
- [ ] Documentation is updated
- [ ] Follow-up work is documented in TODOs
- [ ] TODOs have a ticket associated with them
- [x] No commented-out code included


<!--
Github-flavored markdown reference:
https://docs.github.com/en/get-started/writing-on-github
-->

---------

Co-authored-by: Ian Bowden <ian.bowden@slalom>
  • Loading branch information
LaKeishaTurnerSlalom and Ian Bowden authored Jun 27, 2024
1 parent 88b3d99 commit c1b55b3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
.python-version

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
4 changes: 3 additions & 1 deletion secureli/modules/core/core_services/hook_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def _parse_scan_ouput(self, folder_path: Path, output: str = "") -> scan.ScanOut
files = self._find_file_names(failure_output_list=failure_output_list)

for file in files:
failures.append(scan.ScanFailure(id=id, file=file, repo=repo))
failures.append(
scan.ScanFailure(id=id, file=file, repo=repo, exitCode=id)
)

return scan.ScanOutput(failures=failures)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path
import pydantic

from secureli.modules.shared.models.exit_codes import ExitCode
import secureli.modules.shared.models.scan as scan
from secureli.modules.shared.abstractions.echo import EchoAbstraction
from secureli.modules.shared.abstractions.version_control_repo import (
Expand Down Expand Up @@ -140,7 +141,10 @@ def _generate_scan_failures(
for file in custom_regex_found_files:
failures.append(
scan.ScanFailure(
id="custom_regex_scan", file=file, repo=SECURELI_GITHUB
id="custom_regex_scan",
file=file,
repo=SECURELI_GITHUB,
exitCode=ExitCode.CUSTOM_REGEX_SCAN_ISSUES_DETECTED.name,
)
)
return failures
Expand Down
6 changes: 5 additions & 1 deletion secureli/modules/custom_scanners/pii_scanner/pii_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pathlib import Path
import pydantic

from secureli.modules.shared.models.exit_codes import ExitCode
import secureli.modules.shared.models.scan as scan
from secureli.modules.shared.abstractions.echo import EchoAbstraction
from secureli.modules.shared.abstractions.version_control_repo import (
Expand Down Expand Up @@ -151,7 +152,10 @@ def _generate_scan_failures(
for pii_found_file in pii_found_files:
failures.append(
scan.ScanFailure(
id="pii_scan", file=pii_found_file, repo=SECURELI_GITHUB
id="pii_scan",
file=pii_found_file,
repo=SECURELI_GITHUB,
exitCode=ExitCode.PII_SCAN_ISSUES_DETECTED.name,
)
)
return failures
Expand Down
8 changes: 8 additions & 0 deletions secureli/modules/shared/models/exit_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@

class ExitCode(Enum):
SCAN_ISSUES_DETECTED = 3
PII_SCAN_ISSUES_DETECTED = 4
TYPE_ERROR = 5
NAME_ERROR = 6
VALIDATION_ERROR = 7
CONFIG_ERROR = 8
DICT_ERROR = 9
MISSING_ERROR = 10
CUSTOM_REGEX_SCAN_ISSUES_DETECTED = 11
1 change: 1 addition & 0 deletions secureli/modules/shared/models/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ScanFailure(pydantic.BaseModel):
repo: str
id: str
file: str
exitCode: str


class ScanOutput(pydantic.BaseModel):
Expand Down
6 changes: 5 additions & 1 deletion tests/actions/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ def test_that_initialize_repo_install_flow_displays_security_analysis_results(
mock_hooks_scanner.scan_repo.return_value = ScanResult(
successful=False,
output="Detect secrets...Failed",
failures=[ScanFailure(repo="repo", id="id", file="file")],
failures=[
ScanFailure(
repo="repo", id="id", file="file", exitCode="PII_SCAN_ISSUES_DETECTED"
)
],
)
action.verify_install(
test_folder_path,
Expand Down
21 changes: 18 additions & 3 deletions tests/modules/shared/utilities/test_usage_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@

def test_that_convert_failures_to_failure_count_returns_correct_count():
list_of_failure = [
ScanFailure(id="testfailid1", file="testfile1", repo="testrepo1"),
ScanFailure(id="testfailid1", file="testfile2", repo="testrepo1"),
ScanFailure(id="testfailid2", file="testfile1", repo="testrepo1"),
ScanFailure(
id="testfailid1",
file="testfile1",
repo="testrepo1",
exitCode="SCAN_ISSUES_DETECTED",
),
ScanFailure(
id="testfailid1",
file="testfile2",
repo="testrepo1",
exitCode="PII_SCAN_ISSUES_DETECTED",
),
ScanFailure(
id="testfailid2",
file="testfile1",
repo="testrepo1",
exitCode="VALIDATION_ERROR",
),
]

result = utilities.convert_failures_to_failure_count(list_of_failure)
Expand Down

0 comments on commit c1b55b3

Please sign in to comment.