CollectCampaignRecipients

Collect the recipients from all campaign incidents. This automation runs using the default Limited User role, unless you explicitly change the permissions. For more information, see the section about permissions here: - For Cortex XSOAR 6 see https://docs-cortex.paloaltonetworks.com/r/Cortex-XSOAR/6.x/Cortex-XSOAR-Playbook-Design-Guide/Automations - For Cortex XSOAR 8 Cloud see https://docs-cortex.paloaltonetworks.com/r/Cortex-XSOAR/8/Cortex-XSOAR-Cloud-Documentation/Create-a-script - For Cortex XSOAR 8.7 On-prem see https://docs-cortex.paloaltonetworks.com/r/Cortex-XSOAR/8.7/Cortex-XSOAR-On-prem-Documentation/Create-a-script

python · Phishing Campaign

Details

IDCollectCampaignRecipients
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10116658
Tagsfield-change-triggered

README

Collect the recipients from all campaign incidents.

This automation runs using the default Limited User role, unless you explicitly change the permissions.
For more information, see the section about permissions here:
https://docs.paloaltonetworks.com/cortex/cortex-xsoar/6-2/cortex-xsoar-admin/playbooks/automations.html

Script Data


Name Description
Script Type python3
Tags field-change-triggered
Cortex XSOAR Version 5.0.0

Inputs


There are no inputs for this script.

Outputs


There are no outputs for this script.

import pytest
from CollectCampaignRecipients import *
from CommonServerPython import *

KEYS = ["id", "name", "recipients", "severity", "status", "created"]
NUM_OF_INCIDENTS = 5
MOCKED_INCIDENTS = [
    {key: f"test_{key}_{i}" if key != "recipients" else [f"recip_{i}@test_1.com", f"recip_{i}@test_2.com"] for key in KEYS}
    for i in range(NUM_OF_INCIDENTS)
]

SOME_ERROR = "Raised by mock of demisto.context"


def prepare(mocker):
    mocker.patch.object(demisto, "executeCommand")


SELECTED_IDS = (([], 0), (["test_id_0", "test_id_1", "test_id_2"], 3), ("All", NUM_OF_INCIDENTS))


@pytest.mark.parametrize("selected_ids, num_of_selected_ids", SELECTED_IDS)
def test_collect_campaign_recipients(mocker, selected_ids, num_of_selected_ids):
    """

    Given:
        - Campaign incidents selected in the campaign section

    When:
        - Collect campaign recipients from the incidents

    Then:
        - Validate the recipients was returned

    """

    # prepare
    prepare(mocker)
    mocker.patch.object(demisto, "args", return_value={"new": selected_ids})
    mocker.patch.object(demisto, "incidents", return_value=[MOCKED_INCIDENTS[0]])
    mocker.patch("CollectCampaignRecipients.get_campaign_incidents", return_value=MOCKED_INCIDENTS)

    # run
    main()

    # validate
    command_args = demisto.executeCommand.call_args[0][1]
    recipients = demisto.get(command_args, "customFields.campaignemailto")
    len(recipients.split(",")) == 2 * num_of_selected_ids  # noqa: B015  # 2 recipients for each incident
    assert all(f"recip_{i}@test_1.com" in recipients for i in range(num_of_selected_ids))
    assert all(f"recip_{i}@test_2.com" in recipients for i in range(num_of_selected_ids))


def test_collect_campaign_recipients_no_demisto_args(mocker):
    """

    Given:
        - Campaign incident selected but no "new" param was pass

    When:
        - Collect campaign recipients

    Then:
        - Validate the return_error was called and SystemExit was occurred

    """

    # prepare
    prepare(mocker)
    mocker.patch.object(demisto, "args", return_value={})  # without the required arg 'new'

    # run
    with pytest.raises(SystemExit) as exc_info:
        main()

    assert exc_info.type is SystemExit, "SystemExit should occurred as return_error was called"