def test_config_validation_when_configuration_tab_table_has_no_name_field():
    config = helpers.get_testdata_file(
        "invalid_config_no_name_field_in_configuration_tab_table.json")
    config = json.loads(config)
    validator = GlobalConfigValidator(_path_to_source_dir(), config)
    with pytest.raises(GlobalConfigValidatorException):
        validator.validate()
def test_handle_dropping_api_version_update():
    config = helpers.get_testdata_file("config_with_biased_terms.json")
    config = json.loads(config)
    updated_config = handle_dropping_api_version_update(config)
    expected_schema_version = "0.0.3"
    assert expected_schema_version == updated_config["meta"]["schemaVersion"]
    assert "apiVersion" not in updated_config["meta"]
def test_handle_biased_terms_update():
    config = helpers.get_testdata_file("config_with_biased_terms.json")
    config = json.loads(config)
    updated_config = handle_biased_terms_update(config)
    expected_schema_version = "0.0.1"
    assert expected_schema_version == updated_config["meta"]["schemaVersion"]
    input_entity_1_options_keys = updated_config["pages"]["inputs"]["services"][0][
        "entity"
    ][0]["options"].keys()
    assert "denyList" in input_entity_1_options_keys
    assert "blackList" not in input_entity_1_options_keys
    input_entity_2_options_keys = updated_config["pages"]["inputs"]["services"][0][
        "entity"
    ][1]["options"].keys()
    assert "allowList" in input_entity_2_options_keys
    assert "whileList" not in input_entity_2_options_keys
    configuration_entity_1_options_keys = updated_config["pages"]["configuration"][
        "tabs"
    ][0]["entity"][0]["options"].keys()
    assert "denyList" in configuration_entity_1_options_keys
    assert "blackList" not in configuration_entity_1_options_keys
    configuration_entity_2_options_keys = updated_config["pages"]["configuration"][
        "tabs"
    ][0]["entity"][1]["options"].keys()
    assert "allowList" in configuration_entity_2_options_keys
    assert "whileList" not in configuration_entity_2_options_keys
def test_update_when_minimal_app_conf():
    app_config = app_conf.AppConf()
    app_config.read(get_testdata_file_path("app.conf.minimal"))
    app_config.update(
        "1.0.0",
        "Splunk_TA_UCCExample",
        "Description for Splunk_TA_UCCExample",
        "Title for Splunk_TA_UCCExample",
    )
    app_conf_output = io.StringIO()
    app_config.write(app_conf_output)
    app_conf_expected = get_testdata_file("app.conf.minimal.updated")
    assert app_conf_expected == app_conf_output.getvalue()
def test_config_validation_when_valid_config_then_no_exception():
    config = helpers.get_testdata_file("valid_config.json")
    config = json.loads(config)
    validator = GlobalConfigValidator(_path_to_source_dir(), config)
    validator.validate()
def test_generate_alert_action(tmp_path):
    generated = alert_actions_html_gen.generate_alert_actions_html_files(
        input_setting={
            "product_id":
            "Splunk_TA_UCCExample",
            "short_name":
            "splunk_ta_uccexample",
            "modular_alerts": [{
                "label":
                "Test Alert",
                "description":
                "Description for test Alert Action",
                "short_name":
                "test_alert",
                "active_response": {
                    "task": ["Create", "Update"],
                    "subject": ["endpoint"],
                    "category": [
                        "Information Conveyance",
                        "Information Portrayal",
                    ],
                    "technology": [{
                        "version": ["1.0.0"],
                        "product": "Test Incident Update",
                        "vendor": "Splunk",
                    }],
                    "sourcetype":
                    "test:incident",
                    "supports_adhoc":
                    True,
                    "drilldown_uri":
                    'search?q=search%20index%3D"_internal"&earliest=0&latest=',
                },
                "parameters": [
                    {
                        "label": "Name",
                        "required": True,
                        "format_type": "text",
                        "name": "name",
                        "default_value": "xyz",
                        "help_string": "Please enter your name",
                    },
                    {
                        "label":
                        "All Incidents",
                        "required":
                        False,
                        "format_type":
                        "checkbox",
                        "name":
                        "all_incidents",
                        "default_value":
                        0,
                        "help_string":
                        "Tick if you want to update all incidents/problems",
                    },
                    {
                        "label": "Table List",
                        "required": False,
                        "format_type": "dropdownlist",
                        "name": "table_list",
                        "help_string": "Please select the table",
                        "default_value": "problem",
                        "possible_values": {
                            "incident": "Incident",
                            "problem": "Problem",
                        },
                    },
                    {
                        "label":
                        "Scripted Endpoint",
                        "required":
                        False,
                        "format_type":
                        "text",
                        "name":
                        "scripted_endpoint",
                        "help_string":
                        "Scripted REST endpoint to create incident at. Format: /api/<API namespace>/<API ID>/<Relative path>. Default: /api/now/incident",  # noqa: E501
                    },
                    {
                        "label": "Action:",
                        "required": True,
                        "format_type": "radio",
                        "name": "action",
                        "help_string": "Select the action you want to perform",
                        "default_value": "two",
                        "possible_values": {
                            "update": "Update",
                            "delete": "Delete",
                        },
                    },
                    {
                        "label": "Select Account",
                        "required": True,
                        "format_type": "dropdownlist_splunk_search",
                        "name": "account",
                        "help_string": "Select the account from the dropdown",
                        "ctrl_props": {
                            "value-field":
                            "title",
                            "label-field":
                            "title",
                            "search":
                            "| rest /servicesNS/nobody/TA-SNOW/admin/TA_SNOW_account | dedup title",  # noqa: E501
                        },
                    },
                ],
            }],
        },
        logger=mock.MagicMock(),
        package_path=tmp_path,
    )
    expected_alert_html = get_testdata_file("alert.html.generated")
    assert expected_alert_html == generated["test_alert"]
def test_str_with_comments():
    manifest = get_manifest("app.manifest_with_comments")
    expected_content = get_testdata_file("app.manifest_with_comments_written")
    assert expected_content == str(manifest)
def get_manifest(file_name: str) -> app_manifest.AppManifest:
    content = get_testdata_file(file_name)
    manifest = app_manifest.AppManifest()
    manifest.read(content)
    return manifest