Skip to content

test : added unit tests for build_alert_payload in notification_service#1711

Open
tmdeveloper007 wants to merge 1 commit into
utksh1:mainfrom
tmdeveloper007:#1705
Open

test : added unit tests for build_alert_payload in notification_service#1711
tmdeveloper007 wants to merge 1 commit into
utksh1:mainfrom
tmdeveloper007:#1705

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Closes #1705.

Summary of What Has Been Done:
Added testing/backend/unit/test_notification_service_build_alert_payload.py with 8 unit tests covering build_alert_payload in backend/secuscan/notification_service.py.

Changes Made:

  • test_builds_payload_with_all_fields: verifies complete finding and rule dicts produce the correct payload structure with event, rule, and finding sections
  • test_missing_metadata_json_produces_empty_metadata: missing metadata_json key results in metadata={}
  • test_invalid_metadata_json_falls_back_to_raw_string: non-JSON metadata_json is caught by the try/except and stored as {"raw": "..."}
  • test_non_string_metadata_json_raises_type_error_and_falls_back: int metadata_json raises TypeError caught by the except clause
  • test_missing_finding_fields_produce_none_in_payload: optional finding fields that are missing appear as None in the payload
  • test_valid_dict_metadata_json_is_parsed_and_redacted: valid JSON dict in metadata_json is parsed and redact_inputs applied
  • test_rule_channel_type_is_included: rule.channel_type is present in the payload rule section
  • test_redact_dict_is_called_on_result: mocks redact_dict to verify it is called on the final payload

Impact it Made:

  • Brings build_alert_payload under test coverage for the first time
  • Tests all error paths: missing keys, invalid JSON, wrong types
  • Verifies the redaction pipeline is applied to outbound alert payloads

Note: This task is being handled by tmdeveloper007 — please assign to that account when picking it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test : add unit tests for build_alert_payload in notification_service

1 participant