Ejemplo n.º 1
0
def test_fail_validate_selftest_py_file(fx_get_sub_parser,
                                        fx_cmd_line_args_validate,
                                        fx_copy_fn_main_mock_integration):

    cmd_validate = CmdValidate(fx_get_sub_parser)
    mock_package_path = fx_copy_fn_main_mock_integration[1]
    mock_data = [{
        "func":
        lambda **x: (True,
                     SDKValidateIssue("pass", "pass", SDKValidateIssue.
                                      SEVERITY_LEVEL_DEBUG))
    }, {
        "func": lambda **x: (False, SDKValidateIssue("fail", "fail"))
    }]

    with patch(
            "resilient_sdk.cmds.validate.validation_configurations.selftest_attributes",
            new=mock_data):
        results = CmdValidate._validate_selftest(mock_package_path)

        assert not results[0]
        assert len(results) == 2
        assert len(results[1]) == 2
        assert results[1][
            0].severity == SDKValidateIssue.SEVERITY_LEVEL_CRITICAL
        assert results[1][1].severity == SDKValidateIssue.SEVERITY_LEVEL_DEBUG
Ejemplo n.º 2
0
def test_pass_validate_package_files(fx_copy_fn_main_mock_integration):

    mock_path_package = fx_copy_fn_main_mock_integration[1]
    mock_data = {
        "mock_valid_file": {
            "func":
            lambda **_: [
                SDKValidateIssue("pass", "pass", SDKValidateIssue.
                                 SEVERITY_LEVEL_DEBUG)
            ]
        }
    }

    # the file isn't actually real so we need to mock the validate_file_paths call to not raise and error
    with patch("resilient_sdk.cmds.validate.sdk_helpers.validate_file_paths"
               ) as mock_validate_file:
        mock_validate_file.return_value = None

        # mock the package_file data to mock_data
        with patch(
                "resilient_sdk.cmds.validate.validation_configurations.package_files",
                new=mock_data):

            results = CmdValidate._validate_package_files(mock_path_package)

            assert len(results) == 2
            assert results[0]
            assert len(results[1]) == 1
            assert results[1][
                0].severity == SDKValidateIssue.SEVERITY_LEVEL_DEBUG
Ejemplo n.º 3
0
def test_info_validate_tox_tests(fx_copy_fn_main_mock_integration):

    mock_path_package = fx_copy_fn_main_mock_integration[1]
    mock_data = [{
        "func":
        lambda **_: (-1,
                     SDKValidateIssue("skip", "info: skip", SDKValidateIssue.
                                      SEVERITY_LEVEL_INFO))
    }]

    # mock the package_file data to mock_data
    with patch(
            "resilient_sdk.cmds.validate.validation_configurations.tests_attributes",
            new=mock_data):

        results = CmdValidate._validate_tox_tests(mock_path_package)

        assert len(results) == 2
        assert results[0] == -1
        assert len(results[1]) == 1
        assert results[1][0].severity == SDKValidateIssue.SEVERITY_LEVEL_INFO
Ejemplo n.º 4
0
def test_print_summary(fx_get_sub_parser, caplog):
    mock_data = [
        SDKValidateIssue("default", "severity is used"),
        SDKValidateIssue("default", "severity is used"),
        SDKValidateIssue("default", "severity is used"),
        SDKValidateIssue("warning", "severity",
                         SDKValidateIssue.SEVERITY_LEVEL_WARN),
        SDKValidateIssue("warning", "severity",
                         SDKValidateIssue.SEVERITY_LEVEL_WARN),
        SDKValidateIssue("debug", "pass",
                         SDKValidateIssue.SEVERITY_LEVEL_DEBUG)
    ]
    cmd_validate = CmdValidate(fx_get_sub_parser)
    cmd_validate._print_summary(mock_data)

    assert "Validation Results" in caplog.text
    assert "Critical Issues:     3" in caplog.text
    assert "Warnings:            2" in caplog.text
    assert "Validations Passed:  1" in caplog.text
Ejemplo n.º 5
0
def mock_debug_issue():
    return SDKValidateIssue("bugged", "descr",
                            SDKValidateIssue.SEVERITY_LEVEL_DEBUG, "can't fix")
Ejemplo n.º 6
0
def mock_issue_with_defaults():
    return SDKValidateIssue("name is name", "a simple description")
Ejemplo n.º 7
0
def mock_warning_issue():
    return SDKValidateIssue("this issue failed", "description of failed issue",
                            SDKValidateIssue.SEVERITY_LEVEL_WARN,
                            "here's a solution")