GetDataCollectionLink

Generates the URL for a Data Collection Task into Context. Can be used to get the url for tasks send via Email, Slack, or even if you select "By Task Only". To generate links for specific users, add an array of users in the users argument.

python · Common Scripts

Details

IDGetDataCollectionLink
Languagepython
From Version6.5.0
Docker Imagedemisto/python3:3.12.13.10404775
TagsUtility

README

Generates the URL for a Data Collection Task into Context. Can be used to get the url for tasks send via Email, Slack, or even if you select “By Task Only”.

To generate links for specific users, add an array of users in the users argument.

Script Data


Name Description
Script Type python3
Tags Utility

Inputs


Argument Name Description
task_id The data collection task ID.
users The array of users the data collection task was sent to, or that you want to send to (If using by task only)

Outputs


Path Description Type
DataCollectionURL.url The data collection URL String
DataCollectionURL.task The task ID for the generated URL Unknown
DataCollectionURL.user The user for which the data collection link was generated Unknown
import demistomock as demisto
import pytest
from GetDataCollectionLink import (
    encode_string,
    generate_url,
    get_data_collection_url,
)


def test_main(mocker):
    mocker.patch.object(
        demisto,
        "demistoVersion",
        return_value={"platform": "xsoar", "version": "6.12.0"},
    )
    assert encode_string("abcde") == "59574a6a5a47553d"
    assert get_data_collection_url("1", ["t"]) == [
        {
            "task": "1@1",
            "url": "https://test-address:8443/#/external/form/4d554178/64413d3d",
            "user": "t",
        }
    ]


@pytest.mark.parametrize(
    "is_saas, expected",
    [
        (True, "https://server/external/form/abc/xyz?otp=123"),
        (False, "https://server/#/external/form/abc/xyz"),
    ],
)
def test_generate_url(mocker, is_saas, expected):
    """
    Given:
        - server url, encoded task and user
    When:
        - `generate_url` is called
    Then:
        - it returns the expected url
    """
    mocker.patch("GetDataCollectionLink.is_xsiam_or_xsoar_saas", return_value=is_saas)
    mocker.patch("GetDataCollectionLink.execute_command", return_value="123")

    url = generate_url("https://server", "abc", "xyz")

    assert url == expected


def test_generate_url_generateOTP_unsupported(mocker):
    """
    Given:
        - server url, encoded task and user
    When:
        - `generate_url` is called and `execute_command` raises `Unsupported Command` exception
    Then:
        - it returns the expected url without OTP
    """

    mocker.patch("GetDataCollectionLink.is_xsiam_or_xsoar_saas", return_value=True)
    mocker.patch("GetDataCollectionLink.execute_command", side_effect=Exception("Unsupported Command"))

    url = generate_url("https://server", "abc", "xyz")

    assert url == "https://server/#/external/form/abc/xyz"


def test_generate_url_failure(mocker):
    """
    Given:
        - server url, encoded task and user
    When:
        - `generate_url` is called and `execute_command` raises an exception
    Then:
        - Ensure the exception is raised
    """

    mocker.patch("GetDataCollectionLink.is_xsiam_or_xsoar_saas", return_value=True)
    mocker.patch("GetDataCollectionLink.execute_command", side_effect=Exception("test"))

    with pytest.raises(Exception):
        generate_url("https://server", "abc", "xyz")