RCSScan

This script starts an RCS scan and sets the scan ID in context.

python · Cortex Attack Surface Management

Details

IDRCSScan
Languagepython
From Version6.10.0
Docker Imagedemisto/python3:3.12.13.10116658

README

This script starts an RCS scan and sets the scan ID in context.

Script Data


Name Description
Script Type python3
Cortex XSOAR Version 6.10.0

Inputs


Argument Name Description
service_id This is the ASM Service ID.
attack_surface_rule_id This is the ASM attack surface rule ID.
alert_internal_id This is the ASM alert ID.

Outputs


There are no outputs for this script.

import unittest
from unittest.mock import MagicMock
from RCSScan import rcs_scan_set_context, rcs_scan_start, main


class TestRCSScan(unittest.TestCase):
    def test_rcs_scan_set_context_new_key(self):
        """
        Test the behavior of rcs_scan_set_context when no existing RCSScanId key is present in the context.
        """
        demisto = MagicMock()
        demisto.context.return_value = {}
        demisto.executeCommand.return_value = None
        result = rcs_scan_set_context("12345", demisto)
        assert result == "RCSScanId Key Value set"

    def test_rcs_scan_set_context_update_key(self):
        """
        Test the behavior of rcs_scan_set_context when an existing RCSScanId key is present in the context,
        and a new scan_id is provided.
        """
        demisto = MagicMock()
        demisto.context.return_value = {"RCSScanId": "12345"}
        demisto.executeCommand.return_value = None
        result = rcs_scan_set_context("67890", demisto)
        assert result == "Updated RCSScanId Key Value"

    def test_rcs_scan_set_context_same_key(self):
        """
        Test the behavior of rcs_scan_set_context when an existing RCSScanId key is present in the context,
        and the same scan_id is provided.
        """
        demisto = MagicMock()
        demisto.context.return_value = {"RCSScanId": "12345"}
        demisto.executeCommand.return_value = None
        result = rcs_scan_set_context("12345", demisto)
        assert result == "RCSScanId remains unchanged"

    def test_rcs_scan_start(self):
        """
        Test the behavior of rcs_scan_start with provided arguments and a mocked demisto object.
        """
        demisto = MagicMock()
        demisto.executeCommand.return_value = [{"Type": None, "Contents": {"reply": {"scanId": "12345"}}}]
        service_id = "1"
        attack_surface_rule_id = "2"
        alert_internal_id = "3"
        result = rcs_scan_start(service_id, attack_surface_rule_id, alert_internal_id, demisto)
        assert result == "RCSScanId Key Value set"

    def test_rcs_scan_start_error_response(self):
        """
        Test the behavior of rcs_scan_start when the asm-start-remediation-confirmation-scan command returns an error response.
        """
        demisto = MagicMock()
        demisto.executeCommand.return_value = [
            {
                "Type": 4,
                "Contents": "Failed to execute RCSScanStatus. Check input values.",
            }
        ]
        service_id = "8"
        attack_surface_rule_id = "5"
        alert_internal_id = "7"
        demisto.executeCommand.side_effect = Exception("An error occurred.")

        exception_raised = False

        try:
            rcs_scan_start(service_id, attack_surface_rule_id, alert_internal_id, demisto)
        except Exception:
            exception_raised = True
        assert exception_raised

    def test_main_exception_handling(self):
        """
        Test the exception handling in the main function.
        """
        demisto = MagicMock()
        demisto.args.return_value = {
            "service_id": "1",
            "attack_surface_rule_id": "2",
            "alert_internal_id": "3",
        }
        demisto.executeCommand.side_effect = Exception("An error occurred.")

        exception_raised = False

        try:
            main()
        except Exception:
            exception_raised = True

        assert exception_raised


if __name__ == "__main__":
    unittest.main()