MobileIronCLOUD

MobileIron Cloud Integration.

Endpoint · MobileIron-UEM

Details

IDMobileIronCLOUD
ProviderIvanti
CategoryEndpoint
From Version6.0.0
Docker Imagedemisto/python3:3.12.13.10116658
Supported ModulesAgentix XSIAM

README

MobileIron CLOUD Integration

MobileIron Cloud - Getting Started

  1. Log in to the MobileIron Cloud Admin console.
  2. Open the users section.
  3. Click the create user button and select the option to create a new API user. It is recommended to create a new user for the Cortex XSOAR integration specifically and not reuse
    an existing one.
  4. Fill in all the required details (i.e., use core-api-user as the username) and make sure you enter a strong password.
  5. When setting up the Cortex XSOAR integration, use the auto-generated email address as the username and the password you
    defined as the MobileIron tenant credentials.
  6. Click the Test button and ensure the connection can be established.

Refer to the API documentation at the MobileIron community for more details on setting up the API user.

MobileIron Cloud - Spaces

If you are dividing the devices into different spaces, it is important to make sure the integration
points to the correct Partition ID (Device Space ID).

You should leave this value blank if you are not using spaces or if you want the integration to automatically resolve the
default space ID.

Setting up pre-processing rules

If you are using the fetch incidents option, we recommend to set-up a pre-processing rule in order
to filter out any duplicates that might show up as part of the command.

  • In the Cortex XSOAR admin go to Settings -> Integrations -> Pre-Processing Rules
  • In Step 1 add a rule for Type equals MobileIron Cloud Device Incident.
  • In Step 2 select Drop and Update.
  • In Step 3 select Link to oldest incident created within the last 15 days and check the checkbox next to
    Search closed incidents .
  • Add an AND statement and enter MobileIron Device ID of existing incident is identical to the one of the incoming incident.
  • Save the rule.

Here is an example image of the rule

Pre-Processing Rules Example

Configure MobileIronCLOUD on Cortex XSOAR

  1. Navigate to Settings > Integrations > Servers & Services.
  2. Search for MobileIronCLOUD.
  3. Click Add instance to create and configure a new integration instance.

    Parameter Description Required
    url Server URL (i.e., https://eu1.mobileiron.com ) True
    credentials User Name True
    incidentType Incident type False
    partition_id Partition ID (leave empty to resolve default) False
    insecure Trust any certificate (not secure) False
    proxy Use system proxy settings False
    fetch_interval Fetch Interval (in minutes) True
    max_fetch Maximum number of incidents per fetch False
    isFetch Fetch incidents False
  4. Click Test to validate the URLs, token, and connection.

Commands

You can execute these commands from the Cortex XSOAR CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

mobileiron-cloud-get-devices-data


Gets all the devices based on a particular filter query. The command might execute multiple API calls depending on the amount of devices that would be returned.

Base Command

mobileiron-cloud-get-devices-data

Input

Argument Name Description Required
query Filter query for fetching the device data. Default is registrationState=ACTIVE. Optional
max_fetch The maximum number of items returned in the list. Optional

Context Output

Path Type Description
MobileIronCloud.Device.id Number ID of the device that is fetched.
MobileIronCloud.Device.guid String GUID of the device that is fetched.
MobileIronCloud.Device.deviceModel String Model of the device that is fetched.
MobileIronCloud.Device.deviceName String Name of the device that is fetched.
MobileIronCloud.Device.platformType String Platform type of the device that is fetched.
MobileIronCloud.Device.platformVersion String Platform version of the device that is fetched.
MobileIronCloud.Device.osBuildVersion String Operating system build version of the device that is fetched.
MobileIronCloud.Device.lastCheckin Date Last check in time of the device that is fetched.
MobileIronCloud.Device.registrationState String Registration state of the device that is fetched.
MobileIronCloud.Device.displayName String Display name of the device that is fetched.
MobileIronCloud.Device.firstName String First name of the device that is fetched.
MobileIronCloud.Device.lastName String Last name of the device that is fetched.
MobileIronCloud.Device.uid String UID of the device that is fetched.
MobileIronCloud.Device.emailAddress String Email address of the device that is fetched.
MobileIronCloud.Device.manufacturer String Manufacturer of the device that is fetched.
MobileIronCloud.Device.imei Unknown International Mobile Equipment Identity (IMEI) of the device that is fetched.
MobileIronCloud.Device.imei2 Unknown International Mobile Equipment Identity 2 (IME2) of the device that is fetched.
MobileIronCloud.Device.imsi String International Mobile Subscriber Identity (IMSI) of the device that is fetched.
MobileIronCloud.Device.wifiMacAddress String WiFi MAC address of the device that is fetched.
MobileIronCloud.Device.serialNumber Unknown Serial number of the device that is fetched.
MobileIronCloud.Device.altSerialNumber Unknown Alternative serial number of the device that is fetched.
MobileIronCloud.Device.ownershipType String Ownership type of the device that is fetched.
MobileIronCloud.Device.complianceState Boolean Compliance state of the device that is fetched.
MobileIronCloud.Device.roaming Boolean Roaming status of the device that is fetched.
MobileIronCloud.Device.supervised Unknown Device supervised.
MobileIronCloud.Device.udid String UDID of the device that is fetched.
MobileIronCloud.Device.policyViolationCount Number Policy violation count of the device that is fetched.
MobileIronCloud.Device.lastRegistrationTime Date Last registration time of the device that is fetched.
MobileIronCloud.Device.quarantined Boolean Whether the device is quarantined.
MobileIronCloud.Device.jailbroken Boolean Whether the device is jailbroken.

Command Example


#### Context Example

```json
{
  "MobileIronCloud": {
    "Device": [
      {
        "id": 123,
        "guid": "",
        "deviceModel": "VirtualBox",
        "deviceName": "DESKTOP-B76IV6U",
        "platformType": "WINDOWS_PHONE",
        "platformVersion": "10.0",
        "osBuildVersion": "",
        "lastCheckin": 1596026443798,
        "registrationState": "ACTIVE",
        "displayName": "Windows User",
        "firstName": "Windows",
        "lastName": "User",
        "uid": "userid",
        "emailAddress": "email",
        "manufacturer": "GmbH",
        "imei": null,
        "imei2": null,
        "imsi": "Not Present",
        "wifiMacAddress": "",
        "serialNumber": null,
        "altSerialNumber": null,
        "ownershipType": "UNKNOWN",
        "complianceState": false,
        "roaming": false,
        "supervised": null,
        "udid": "UIDVALUE",
        "clientLastCheckin": null,
        "prettyModel": "VirtualBox",
        "policyViolationCount": 1,
        "lastRegistrationTime": 1596022502880,
        "quarantined": false,
        "jailbroken": false,
        "windowsDeviceType": "WINDOWS_DESKTOP",
        "entityName": "DESKTOP-B76IV6U"
      }
    ]
  }
}

mobileiron-cloud-get-device-by-mac


Gets a single device matching the provided mac address.

Base Command

mobileiron-cloud-get-device-by-mac

Input

Argument Name Description Required
device_mac THe MAC address of the device to fetch. Required

Context Output

Path Type Description
MobileIronCloud.Device.id Number The ID of the device that is fetched.
MobileIronCloud.Device.guid String GUID of the device that is fetched.
MobileIronCloud.Device.deviceModel String Model of the device that is fetched.
MobileIronCloud.Device.deviceName String Name of the device that is fetched.
MobileIronCloud.Device.platformType String Platform type of the device that is fetched.
MobileIronCloud.Device.platformVersion String Platform version of the device that is fetched.
MobileIronCloud.Device.osBuildVersion String Operating system build version of the device that is fetched.
MobileIronCloud.Device.lastCheckin Date Last check in time of the device that is fetched.
MobileIronCloud.Device.registrationState String Registration state of the device that is fetched.
MobileIronCloud.Device.displayName String Display name of the device that is fetched.
MobileIronCloud.Device.firstName String First name of the device that is fetched.
MobileIronCloud.Device.lastName String Last name of the device that is fetched.
MobileIronCloud.Device.uid String UID of the device that is fetched.
MobileIronCloud.Device.emailAddress String Email address of the device that is fetched.
MobileIronCloud.Device.manufacturer String Manufacturer of the device that is fetched.
MobileIronCloud.Device.imei Unknown International Mobile Equipment Identity (IMEI) of the device that is fetched.
MobileIronCloud.Device.imei2 Unknown International Mobile Equipment Identity 2 (IME2) of the device that is fetched.
MobileIronCloud.Device.imsi String International mobile subscriber identity (IMSI) of the device that is fetched.
MobileIronCloud.Device.wifiMacAddress String WiFi MAC address of the device that is fetched.
MobileIronCloud.Device.serialNumber Unknown Serial number of the device that is fetched.
MobileIronCloud.Device.altSerialNumber Unknown Alternative serial number of the device that is fetched.
MobileIronCloud.Device.ownershipType String Ownership type of the device that is fetched.
MobileIronCloud.Device.complianceState Boolean Compliance state of the device that is fetched.
MobileIronCloud.Device.roaming Boolean Roaming status of the device that is fetched.
MobileIronCloud.Device.supervised Unknown Device Supervised
MobileIronCloud.Device.udid String Device UDID of the device that is fetched.
MobileIronCloud.Device.policyViolationCount Number Policy violation count of the device that is fetched.
MobileIronCloud.Device.lastRegistrationTime Date Last registration time of the device that is fetched.
MobileIronCloud.Device.quarantined Boolean Whether the device is quarantined.
MobileIronCloud.Device.jailbroken Boolean Whether the device is jailbroken.

Command Example

!mobileiron-cloud-get-device-by-mac device_mac=MAC_HERE

Context Example

{
  "MobileIronCloud": {
    "Device": {
      "id": 123,
      "guid": "",
      "deviceModel": "VirtualBox",
      "deviceName": "DESKTOP-B76IV6U",
      "platformType": "WINDOWS_PHONE",
      "platformVersion": "10.0",
      "osBuildVersion": "",
      "lastCheckin": 1596026443798,
      "registrationState": "ACTIVE",
      "displayName": "Windows User",
      "firstName": "Windows",
      "lastName": "User",
      "uid": "userid",
      "emailAddress": "email",
      "manufacturer": "GmbH",
      "imei": null,
      "imei2": null,
      "imsi": "Not Present",
      "wifiMacAddress": "",
      "serialNumber": null,
      "altSerialNumber": null,
      "ownershipType": "UNKNOWN",
      "complianceState": false,
      "roaming": false,
      "supervised": null,
      "udid": "UIDVALUE",
      "clientLastCheckin": null,
      "prettyModel": "VirtualBox",
      "policyViolationCount": 1,
      "lastRegistrationTime": 1596022502880,
      "quarantined": false,
      "jailbroken": false,
      "windowsDeviceType": "WINDOWS_DESKTOP",
      "entityName": "DESKTOP-B76IV6U"
    }
  }
}

mobileiron-cloud-get-device-by-serial


Gets a single device matching the provided value for the device serial number.

Base Command

mobileiron-cloud-get-device-by-serial

Input

Argument Name Description Required
device_serial Serial number of the device to fetch. Optional

Context Output

Path Type Description
MobileIronCloud.Device.id Number The ID of the device that is fetched.
MobileIronCloud.Device.guid String GUID of the device that is fetched.
MobileIronCloud.Device.deviceModel String Model of the device that is fetched.
MobileIronCloud.Device.deviceName String Name of the device that is fetched.
MobileIronCloud.Device.platformType String Platform type of the device that is fetched.
MobileIronCloud.Device.platformVersion String Platform version of the device that is fetched.
MobileIronCloud.Device.osBuildVersion String Operating system build version of the device that is fetched.
MobileIronCloud.Device.lastCheckin Date Last check in time of the device that is fetched.
MobileIronCloud.Device.registrationState String Registration state of the device that is fetched.
MobileIronCloud.Device.displayName String Display name of the device that is fetched.
MobileIronCloud.Device.firstName String First name of the device that is fetched.
MobileIronCloud.Device.lastName String Last name of the device that is fetched.
MobileIronCloud.Device.uid String UID of the device that is fetched.
MobileIronCloud.Device.emailAddress String Email address of the device that is fetched.
MobileIronCloud.Device.manufacturer String Manufacturer of the device that is fetched.
MobileIronCloud.Device.imei Unknown International Mobile Equipment Identity (IMEI) of the device that is fetched.
MobileIronCloud.Device.imei2 Unknown International Mobile Equipment Identity 2 (IME2) of the device that is fetched.
MobileIronCloud.Device.imsi String International mobile subscriber identity (IMSI) of the device that is fetched.
MobileIronCloud.Device.wifiMacAddress String WiFi MAC address of the device that is fetched.
MobileIronCloud.Device.serialNumber Unknown Serial number of the device that is fetched.
MobileIronCloud.Device.altSerialNumber Unknown Alternative serial number of the device that is fetched.
MobileIronCloud.Device.ownershipType String Ownership type of the device that is fetched.
MobileIronCloud.Device.complianceState Boolean Compliance state of the device that is fetched.
MobileIronCloud.Device.roaming Boolean Roaming status of the device that is fetched.
MobileIronCloud.Device.supervised Unknown Device Supervised
MobileIronCloud.Device.udid String Device UDID of the device that is fetched.
MobileIronCloud.Device.policyViolationCount Number Policy violation count of the device that is fetched.
MobileIronCloud.Device.lastRegistrationTime Date Last registration time of the device that is fetched.
MobileIronCloud.Device.quarantined Boolean Whether the device is quarantined.
MobileIronCloud.Device.jailbroken Boolean Whether the device is jailbroken.

Command Example

!mobileiron-cloud-get-device-by-serial device_serial=SERIAL_HERE

Context Example

{
  "MobileIronCloud": {
    "Device": {
      "id": 123,
      "guid": "",
      "deviceModel": "VirtualBox",
      "deviceName": "DESKTOP-B76IV6U",
      "platformType": "WINDOWS_PHONE",
      "platformVersion": "10.0",
      "osBuildVersion": "",
      "lastCheckin": 1596026443798,
      "registrationState": "ACTIVE",
      "displayName": "Windows User",
      "firstName": "Windows",
      "lastName": "User",
      "uid": "userid",
      "emailAddress": "email",
      "manufacturer": "GmbH",
      "imei": null,
      "imei2": null,
      "imsi": "Not Present",
      "wifiMacAddress": "",
      "serialNumber": null,
      "altSerialNumber": null,
      "ownershipType": "UNKNOWN",
      "complianceState": false,
      "roaming": false,
      "supervised": null,
      "udid": "UIDVALUE",
      "clientLastCheckin": null,
      "prettyModel": "VirtualBox",
      "policyViolationCount": 1,
      "lastRegistrationTime": 1596022502880,
      "quarantined": false,
      "jailbroken": false,
      "windowsDeviceType": "WINDOWS_DESKTOP",
      "entityName": "DESKTOP-B76IV6U"
    }
  }
}

mobileiron-cloud-unlock-device


Sends an unlock action to the device.

Base Command

mobileiron-cloud-unlock-device

Input

Argument Name Description Required
device_id The ID of the MobileIron device to fetch. Optional

Command Example

!mobileiron-cloud-unlock-device device_id=1100646

Human Readable Output

Action was performed successfully

mobileiron-cloud-retire-device


Sends a retire action to the device.

Base Command

mobileiron-cloud-retire-device

Input

Argument Name Description Required
device_id The ID of the MobileIron device to fetch. Optional

Human Readable Output

Action was performed successfully

mobileiron-cloud-wipe-device


Sends a wipe action to the device. This is a potentially destructive action as it will completely wipe the device.

Base Command

mobileiron-cloud-wipe-device

Input

Argument Name Description Required
device_id The ID of the MobileIron device to fetch. Optional

Human Readable Output

Action was performed successfully

mobileiron-cloud-force-check-in


Forces a check in to the particular device based on the device ID.

Base Command

mobileiron-cloud-force-check-in

Input

Argument Name Description Required
device_id The ID of the MobileIron device to fetch. Optional

Human Readable Output

Action was performed successfully

mobileiron-cloud-send-message


Sends a message to the device.

Base Command

mobileiron-cloud-send-message

Input

Argument Name Description Required
device_id The ID of the MobileIron device to fetch. Optional
message_type The type of notification to send. Possible values are: email, push. Default is push. Required
subject The subject of the email. (Only used if an email should be sent). Optional
message The message to be sent. Required

Human Readable Output

Action was performed successfully

mobileiron-cloud-get-device-by-id


Returns the data for a particular device based on the device ID.

Base Command

mobileiron-cloud-get-device-by-id

Input

Argument Name Description Required
device_id The ID of the MobileIron device to fetch. Required

Context Output

Path Type Description
MobileIronCloud.Device.id Number The ID of the device that is fetched.
MobileIronCloud.Device.guid String GUID of the device that is fetched.
MobileIronCloud.Device.deviceModel String Model of the device that is fetched.
MobileIronCloud.Device.deviceName String Name of the device that is fetched.
MobileIronCloud.Device.platformType String Platform type of the device that is fetched.
MobileIronCloud.Device.platformVersion String Platform version of the device that is fetched.
MobileIronCloud.Device.osBuildVersion String Operating system build version of the device that is fetched.
MobileIronCloud.Device.lastCheckin Date Last check in time of the device that is fetched.
MobileIronCloud.Device.registrationState String Registration state of the device that is fetched.
MobileIronCloud.Device.displayName String Display name of the device that is fetched.
MobileIronCloud.Device.firstName String First name of the device that is fetched.
MobileIronCloud.Device.lastName String Last name of the device that is fetched.
MobileIronCloud.Device.uid String UID of the device that is fetched.
MobileIronCloud.Device.emailAddress String Email address of the device that is fetched.
MobileIronCloud.Device.manufacturer String Manufacturer of the device that is fetched.
MobileIronCloud.Device.imei Unknown International Mobile Equipment Identity (IMEI) of the device that is fetched.
MobileIronCloud.Device.imei2 Unknown International Mobile Equipment Identity 2 (IME2) of the device that is fetched.
MobileIronCloud.Device.imsi String International mobile subscriber identity (IMSI) of the device that is fetched.
MobileIronCloud.Device.wifiMacAddress String WiFi MAC address of the device that is fetched.
MobileIronCloud.Device.serialNumber Unknown Serial number of the device that is fetched.
MobileIronCloud.Device.altSerialNumber Unknown Alternative serial number of the device that is fetched.
MobileIronCloud.Device.ownershipType String Ownership type of the device that is fetched.
MobileIronCloud.Device.complianceState Boolean Compliance state of the device that is fetched.
MobileIronCloud.Device.roaming Boolean Roaming status of the device that is fetched.
MobileIronCloud.Device.supervised Unknown Device Supervised
MobileIronCloud.Device.udid String Device UDID of the device that is fetched.
MobileIronCloud.Device.policyViolationCount Number Policy violation count of the device that is fetched.
MobileIronCloud.Device.lastRegistrationTime Date Last registration time of the device that is fetched.
MobileIronCloud.Device.quarantined Boolean Whether the device is quarantined.
MobileIronCloud.Device.jailbroken Boolean Whether the device is jailbroken.

Command Example

!mobileiron-cloud-get-device-by-id device_id=1100646

Context Example

{
  "MobileIronCloud": {
    "Device": {
      "id": 123,
      "guid": "",
      "deviceModel": "VirtualBox",
      "deviceName": "DESKTOP-B76IV6U",
      "platformType": "WINDOWS_PHONE",
      "platformVersion": "10.0",
      "osBuildVersion": "",
      "lastCheckin": 1596026443798,
      "registrationState": "ACTIVE",
      "displayName": "Windows User",
      "firstName": "Windows",
      "lastName": "User",
      "uid": "userid",
      "emailAddress": "email",
      "manufacturer": "GmbH",
      "imei": null,
      "imei2": null,
      "imsi": "Not Present",
      "wifiMacAddress": "",
      "serialNumber": null,
      "altSerialNumber": null,
      "ownershipType": "UNKNOWN",
      "complianceState": false,
      "roaming": false,
      "supervised": null,
      "udid": "UIDVALUE",
      "clientLastCheckin": null,
      "prettyModel": "VirtualBox",
      "policyViolationCount": 1,
      "lastRegistrationTime": 1596022502880,
      "quarantined": false,
      "jailbroken": false,
      "windowsDeviceType": "WINDOWS_DESKTOP",
      "entityName": "DESKTOP-B76IV6U"
    }
  }
}

Configuration parameters

  • isFetch — Fetch incidents
  • incidentType — Incident type
  • incidentFetchInterval — Incidents Fetch Interval
  • url — Server URL (i.e., https://eu1.mobileiron.com ) (required)
  • credentials — User Name (required)
  • partition_id — Partition ID (leave empty to resolve default)
  • max_fetch — Maximum number of incidents per fetch
  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings

Commands (9)

  • mobileiron-cloud-force-check-in

    Forces a check in to the particular device based on the device ID.

  • mobileiron-cloud-get-device-by-id

    Returns the data for a particular device based on the device id.

  • mobileiron-cloud-get-device-by-mac

    Gets a single device matching the provided MAC address.

  • mobileiron-cloud-get-device-by-serial

    Gets a single device matching the provided value for the device serial number.

  • mobileiron-cloud-get-devices-data

    Gets all the devices based on a particular filter query. The command might execute multiple API calls depending on the amount of devices that are returned.

  • mobileiron-cloud-retire-device

    Sends a retire action to the device.

  • mobileiron-cloud-send-message

    Sends a message to the device.

  • mobileiron-cloud-unlock-device

    Sends an unlock action to the device.

  • mobileiron-cloud-wipe-device

    Sends a wipe action to the device. This is a potentially destructive action as it will completely wipe the device.

import pytest
from CommonServerPython import *
from MobileIronCLOUD import get_partition_id

MOCK_URL = "https://eu1.mobileiron.com"
MOCK_PARAMS = {"partition_id": "12345"}


@pytest.fixture
def client():
    from MobileIronCLOUD import MobileIronCloudClient

    return MobileIronCloudClient(base_url=MOCK_URL, verify=False, auth=("test", "p"))


def util_load_json(path):
    with open(path, encoding="utf-8") as f:
        return json.loads(f.read())


class TestGetPartitionId:
    @staticmethod
    def test_get_partition_id_return_param(mocker, client):
        """It returns the value of partition id from params"""

        mocker.patch.object(demisto, "params", return_value=MOCK_PARAMS)
        result = get_partition_id(client)

        assert result == "12345"

    @staticmethod
    def test_get_partition_id_return_api(mocker, requests_mock, client):
        """It returns the value from API, in case param is not defined"""

        mocker.patch.object(demisto, "params", return_value={"credentials": {"identifier": "useremail"}})
        mocker.patch.object(demisto, "getIntegrationContext", return_value={})

        mock_response = util_load_json("test_data/tenant_spaces.json")
        requests_mock.get("/api/v1/tenant/partition/device", json=mock_response)

        result = get_partition_id(client)

        assert result == "100001"

    @staticmethod
    def test_get_partition_id_return_stored(mocker, client):
        """
        It returns the value from storage, in case param is not defined but the value was already fetched.
        """
        mocker.patch.object(demisto, "params", return_value={"credentials": {"identifier": "useremail"}})
        mocker.patch.object(
            demisto, "getIntegrationContext", return_value={"for_user": "useremail", "default_partition_id": "10101"}
        )
        result = get_partition_id(client)
        assert result == "10101"

    @staticmethod
    def test_get_partition_id_change_user(mocker, client, requests_mock):
        """
        It will call the api again to fetch the partition id value if the api user was changed
        """
        mocker.patch.object(demisto, "params", return_value={"credentials": {"identifier": "useremail"}})
        mocker.patch.object(
            demisto,
            "getIntegrationContext",
            return_value={
                "for_user": "otheremail",
            },
        )
        mock_response = util_load_json("test_data/tenant_spaces.json")
        requests_mock.get("/api/v1/tenant/partition/device", json=mock_response)

        result = get_partition_id(client)

        assert result == "100001"


class TestClientGetDevicesData:
    @pytest.fixture
    def prepare_mock(self, requests_mock):
        mock_response_page_one = util_load_json("test_data/get_devices_response_page.json")
        mock_response_page_two = util_load_json("test_data/get_devices_response_page2.json")
        requests_mock.register_uri(
            "GET",
            f"{MOCK_URL}/api/v1/device",
            [{"json": mock_response_page_one, "status_code": 200}, {"json": mock_response_page_two, "status_code": 200}],
        )

    def test_client_get_devices_data(self, client, prepare_mock):
        """ "Making sure we can page through all the results if there are multiple pages of data"""
        results = client.get_devices_data(partition_id="123", query="any")
        assert len(results) == 3

    def test_client_get_devices_data_max_fetch(self, client, prepare_mock):
        """ "Making sure we can page through all the results if there are multiple pages of data"""
        results = client.get_devices_data(partition_id="123", query="any", max_fetch=2)
        assert len(results) == 2


def test_get_devices_data_command(mocker):
    from MobileIronCLOUD import execute_get_devices_data_command

    mocker.patch.object(demisto, "params", return_value=MOCK_PARAMS)
    mocker.patch.object(demisto, "args", return_value={"query": "mock query", "max_fetch": "5"})

    client = mocker.Mock(name="client")
    client.get_devices_data.return_value = []
    result = execute_get_devices_data_command(client)
    client.get_devices_data.assert_called_once_with(query="mock query", max_fetch=5, partition_id="12345")

    assert result.outputs_prefix == "MobileIronCloud.Device"
    assert result.outputs_key_field == "id"
    assert len(result.outputs) == 0


def test_execute_get_device_by_field_command(mocker):
    from MobileIronCLOUD import execute_get_device_by_field_command

    mocker.patch.object(demisto, "params", return_value=MOCK_PARAMS)
    client = mocker.Mock(name="client")
    client.get_devices_data.return_value = []
    result = execute_get_device_by_field_command(client, field_name="name_of_field", field_value="value_of_field")
    client.get_devices_data.assert_called_once_with(query="name_of_field=value_of_field", partition_id="12345")

    assert result.outputs_prefix == "MobileIronCloud.Device"
    assert result.outputs_key_field == "id"
    assert result.outputs is None


def test_get_device_by_id_command(client, mocker, requests_mock):
    from MobileIronCLOUD import execute_get_device_by_id_command

    mocker.patch.object(demisto, "params", return_value=MOCK_PARAMS)
    mocker.patch.object(demisto, "args", return_value={"device_id": "1"})

    mock_response = util_load_json("test_data/device_response.json")

    requests_mock.get(f"{MOCK_URL}/api/v1/device/1", json=mock_response)

    result = execute_get_device_by_id_command(client)
    assert result.outputs_prefix == "MobileIronCloud.Device"
    assert result.outputs_key_field == "id"
    assert result.outputs is not None


def test_execute_device_action_command(client, requests_mock, mocker):
    from MobileIronCLOUD import execute_device_action_command

    mocker.patch.object(demisto, "params", return_value=MOCK_PARAMS)
    mocker.patch.object(demisto, "args", return_value={"device_id": "device_id_value"})

    requests_mock.put("/api/v1/device/unlock", json={"errors": None, "result": 1})

    result = execute_device_action_command(client, "unlock")
    assert result == "Action was performed successfully"

    requests_mock.put("/api/v1/device/unlock", json={"errors": None, "result": 0})

    with pytest.raises(ValueError):
        execute_device_action_command(client, "unlock")


def test_execute_send_message_command(client, requests_mock, mocker):
    from MobileIronCLOUD import execute_send_message_command

    mocker.patch.object(demisto, "params", return_value=MOCK_PARAMS)
    mocker.patch.object(
        demisto,
        "args",
        return_value={
            "device_id": "device_id_value",
            "message_type": "push",
            "message": "message_value",
            "subject": "subject_value",
        },
    )

    requests_mock.put("/api/v1/device/message", json={"errors": None, "result": 1})

    result = execute_send_message_command(client)
    assert result == "Message was sent successfully"

    requests_mock.put("/api/v1/device/message", json={"errors": None, "result": 0})

    with pytest.raises(ValueError):
        execute_send_message_command(client)


def test_execute_test_module_command(client, requests_mock):
    from MobileIronCLOUD import execute_test_module_command

    mock_response = util_load_json("test_data/tenant_spaces.json")
    requests_mock.get("/api/v1/tenant/partition/device", json=mock_response)
    result = execute_test_module_command(client)
    assert result == "ok"


def test_fetch_incidents(client, requests_mock):
    from MobileIronCLOUD import SEVERITY_HIGH, fetch_incidents

    mock_response = util_load_json("test_data/get_devices_response_page2.json")
    requests_mock.get(f"{MOCK_URL}/api/v1/device", json=mock_response)

    result = fetch_incidents(client, "partition_id_value", "MobileIron Cloud Device Incident", 1000)
    incident = result[0]
    assert incident["name"] == "MobileIron Device Alert - Non Compliant Device - Out of Contact"
    assert incident["severity"] == SEVERITY_HIGH
    assert incident["type"] == "MobileIron Cloud Device Incident"
    assert incident["rawJSON"] is not None


def test_compose_non_compliance_message():
    from MobileIronCLOUD import compose_non_compliance_message

    mock_device = {"complianceState": False, "violatedPolicies": ["Out of Contact", "Compromised"]}
    message = compose_non_compliance_message(mock_device)
    assert message == "Non Compliant Device - Out of Contact, Compromised"

    mock_device = {"complianceState": False, "violatedPolicies": None}
    message = compose_non_compliance_message(mock_device)
    assert message == "Non Compliant Device"