CustomPackInstaller

Custom Packs Installer for the Content Management pack.

python · XSOAR CI/CD

Details

IDCustomPackInstaller
Languagepython
From Version6.0.0
Docker Imagedemisto/xsoar-tools:1.0.0.11807991
Tagsconfiguration Content Management

README

Custom Packs Installer for the Content Management pack.

Script Data


Name Description
Script Type python3
Tags configuration, Content Management
Cortex XSOAR Version 6.0.0

Used In


This script is used in the following playbooks and scripts.

  • Configuration Setup

Inputs


Argument Name Description
pack_id The ID of the pack to install.
skip_verify if true will skip pack signature validation, Available from 6.5.0 server version.
skip_validation if true will skip all pack validations, use this flag just to migrate from custom content entities to custom content packs, Available from 6.6.0 server version.

Outputs


Path Description Type
ConfigurationSetup.CustomPacks.installationstatus The installtion status of the required pack. Unknown
import pytest
from CommonServerPython import *


@pytest.mark.parametrize(
    argnames="pack_id, context, err_massage, res",
    argvalues=[
        ("Pack1", {"File": [{"Name": "Pack1.zip", "EntryID": ""}]}, "Could not find file entry ID.", False),
        (
            "Pack1",
            {"File": [{"Name": "Pack1.zip", "EntryID": "1234"}]},
            "Issue occurred while installing the pack on the machine.\n",
            False,
        ),
    ],
)
def test_install_custom_pack_failed(mocker, pack_id, context, err_massage, res):
    from CustomPackInstaller import install_custom_pack

    mocker.patch.object(demisto, "context", return_value=context)
    mocker.patch("CustomPackInstaller.execute_command", return_value=("", ""))

    result, error_message = install_custom_pack(pack_id, "true", "true")
    assert result == res
    assert error_message == err_massage


@pytest.mark.parametrize(
    argnames="pack_id, context",
    argvalues=[
        ("Pack1", {"File": [{"Name": "Pack1.zip", "EntryID": "1234"}]}),
        ("Pack2", {"File": [{"Name": "Pack2.zip", "EntryID": "abcd"}]}),
        ("Pack1", {"File": [{"Name": "content/packs/Pack1/0.0.1/Pack1.zip", "EntryID": "1234"}]}),
        ("Pack2", {"File": [{"Name": "content/packs/Pack2/0.1.0/Pack2.zip", "EntryID": "abcd"}]}),
    ],
)
def test_install_custom_pack_success(
    mocker,
    pack_id,
    context,
):
    """
    Given  pack_id and context mock.
    - Case 1: given a pack with just a filename and numerical EntryID.
    - Case 2: given a pack with just a filename and alphabetical EntryID.
    - Case 3: given a pack with a full path name and numerical EntryID,
    - Case 4: given a pack with a full path name and alphabetical EntryID,

    When
    - Running install_custom_pack function.

    Then
    - Ensure the pack id is recognized and the function succeed.
    """
    from CustomPackInstaller import install_custom_pack

    mocker.patch.object(demisto, "context", return_value=context)
    mocker.patch("CustomPackInstaller.execute_command", return_value=("Ok", ""))

    result, error_message = install_custom_pack(pack_id, "true", "true")
    assert result
    assert error_message == ""


def test_install_custom_pack_specify_instance(mocker):
    from CustomPackInstaller import install_custom_pack

    context = {"File": [{"Name": "Pack1.zip", "EntryID": "1234"}]}

    mocker.patch.object(demisto, "context", return_value=context)
    execute_command_mock = mocker.patch("CustomPackInstaller.execute_command", return_value=("Ok", ""))

    _, _ = install_custom_pack("Pack1", "true", "true", "instance1")
    execute_command_args = execute_command_mock.call_args_list[0][0]
    assert execute_command_args[1]["using"] == "instance1"


def test_install_custom_pack_no_specify_instance(mocker):
    from CustomPackInstaller import install_custom_pack

    context = {"File": [{"Name": "Pack1.zip", "EntryID": "1234"}]}

    mocker.patch.object(demisto, "context", return_value=context)
    execute_command_mock = mocker.patch("CustomPackInstaller.execute_command", return_value=("Ok", ""))

    _, _ = install_custom_pack("Pack1", "true", "true")
    execute_command_args = execute_command_mock.call_args_list[0][0]
    assert "using" not in execute_command_args[1]