示例#1
0
def test_run_no_reporting_plugins(init_statick):
    """
    Test that no reporting plugins returns unsuccessful.

    Expected results: issues is None and success is False
    """
    args = Args("Statick tool")
    args.parser.add_argument("--path", help="Path of package to scan")

    statick = Statick(args.get_user_paths())
    statick.gather_args(args.parser)
    sys.argv = [
        "--path",
        os.path.dirname(__file__),
        "--config",
        os.path.join(os.path.dirname(__file__), "rsc",
                     "config-no-reporting-plugins.yaml"),
    ]
    args.output_directory = os.path.dirname(__file__)
    parsed_args = args.get_args(sys.argv)
    path = parsed_args.path
    statick.get_config(parsed_args)
    statick.get_exceptions(parsed_args)
    issues, success = statick.run(path, parsed_args)
    for tool in issues:
        assert not issues[tool]
    assert success
    try:
        shutil.rmtree(
            os.path.join(os.path.dirname(__file__), "statick-sei_cert"))
    except OSError as ex:
        print("Error: {}".format(ex))
示例#2
0
def test_run_invalid_level(init_statick):
    """
    Test that invalid profile results in invalid level.

    Expected results: issues is None and success is False
    """
    args = Args("Statick tool")
    args.parser.add_argument("--path", help="Path of package to scan")

    statick = Statick(args.get_user_paths())
    statick.gather_args(args.parser)
    sys.argv = [
        "--path",
        os.path.dirname(__file__),
        "--profile",
        os.path.join(os.path.dirname(__file__), "rsc", "nonexistent.yaml"),
    ]
    args.output_directory = os.path.dirname(__file__)
    parsed_args = args.get_args(sys.argv)
    path = parsed_args.path
    statick.get_config(parsed_args)
    statick.get_exceptions(parsed_args)
    issues, success = statick.run(path, parsed_args)
    assert issues is None
    assert not success
    try:
        shutil.rmtree(
            os.path.join(os.path.dirname(__file__), "statick-sei_cert"))
    except OSError as ex:
        print("Error: {}".format(ex))
示例#3
0
def test_run_force_tool_list(init_statick):
    """Test running Statick against a missing directory."""
    args = Args("Statick tool")
    args.parser.add_argument("--path", help="Path of package to scan")

    statick = Statick(args.get_user_paths())
    statick.gather_args(args.parser)
    sys.argv = [
        "--path",
        os.path.dirname(__file__), "--force-tool-list", "bandit"
    ]
    args.output_directory = os.path.dirname(__file__)
    parsed_args = args.get_args(sys.argv)
    path = parsed_args.path
    statick.get_config(parsed_args)
    statick.get_exceptions(parsed_args)
    issues, success = statick.run(path, parsed_args)
    for tool in issues:
        assert not issues[tool]
    assert success
    try:
        shutil.rmtree(
            os.path.join(os.path.dirname(__file__), "statick-sei_cert"))
    except OSError as ex:
        print("Error: {}".format(ex))
示例#4
0
def test_run_discovery_dependency(init_statick):
    """
    Test that a discovery plugin can run its dependencies.

    Expected results: issues is None and success is False
    """
    args = Args("Statick tool")
    args.parser.add_argument("--path", help="Path of package to scan")

    statick = Statick(args.get_user_paths())
    statick.gather_args(args.parser)
    sys.argv = [
        "--path",
        os.path.dirname(__file__),
        "--config",
        os.path.join(os.path.dirname(__file__), "rsc",
                     "config-discovery-dependency.yaml"),
    ]
    args.output_directory = os.path.dirname(__file__)
    parsed_args = args.get_args(sys.argv)
    path = parsed_args.path
    statick.get_config(parsed_args)
    statick.get_exceptions(parsed_args)
    _, success = statick.run(path, parsed_args)
    assert success
    try:
        shutil.rmtree(
            os.path.join(os.path.dirname(__file__), "statick-sei_cert"))
    except OSError as ex:
        print("Error: {}".format(ex))
示例#5
0
def test_print_logging_level_invalid():
    """Test that log level is set to a valid level given garbage input."""
    args = Args("Statick tool")
    args.parser.add_argument("--path", help="Path of package to scan")

    statick = Statick(args.get_user_paths())
    statick.gather_args(args.parser)
    sys.argv = [
        "--path",
        os.path.dirname(__file__),
        "--log",
        "NOT_A_VALID_LEVEL",
    ]
    args.output_directory = os.path.dirname(__file__)
    parsed_args = args.get_args(sys.argv)
    statick.set_logging_level(parsed_args)

    logger = logging.getLogger()
    assert logger.getEffectiveLevel() == logging.WARNING
示例#6
0
def test_print_logging_level():
    """Test that log level is set as expected."""
    args = Args("Statick tool")
    args.parser.add_argument("--path", help="Path of package to scan")

    statick = Statick(args.get_user_paths())
    statick.gather_args(args.parser)
    sys.argv = [
        "--path",
        os.path.dirname(__file__),
        "--log",
        "ERROR",
    ]
    args.output_directory = os.path.dirname(__file__)
    parsed_args = args.get_args(sys.argv)
    statick.set_logging_level(parsed_args)

    logger = logging.getLogger()
    assert logger.getEffectiveLevel() == logging.ERROR
示例#7
0
def test_show_tool_output_deprecated(caplog):
    """Test that the deprecation warning is shown for --show-tool-output flag."""
    args = Args("Statick tool")
    args.parser.add_argument("--path", help="Path of package to scan")

    statick = Statick(args.get_user_paths())
    statick.gather_args(args.parser)
    sys.argv = [
        "--path",
        os.path.dirname(__file__),
        "--log",
        "INFO",
        "--show-tool-output",
    ]
    args.output_directory = os.path.dirname(__file__)
    parsed_args = args.get_args(sys.argv)
    statick.set_logging_level(parsed_args)

    print("caplog: {}".format(caplog.text))
    output = caplog.text.splitlines()[1]
    assert "The --show-tool-output argument has been deprecated since v0.5.0." in output
示例#8
0
def test_run_tool_dependency(init_statick):
    """
    Test that a tool plugin can run its dependencies.

    Expected results: issues is None and success is False
    """
    cttp = ClangTidyToolPlugin()
    if not cttp.command_exists("clang-tidy"):
        pytest.skip("Can't find clang-tidy, unable to test clang-tidy plugin")
    args = Args("Statick tool")
    args.parser.add_argument("--path", help="Path of package to scan")

    statick = Statick(args.get_user_paths())
    statick.gather_args(args.parser)
    sys.argv = [
        "--path",
        os.path.dirname(__file__),
        "--profile",
        os.path.join(os.path.dirname(__file__), "rsc", "profile-custom.yaml"),
        "--config",
        os.path.join(
            os.path.dirname(__file__), "rsc", "config-enabled-dependency.yaml"
        ),
        "--force-tool-list",
        "clang-tidy",
    ]
    args.output_directory = os.path.dirname(__file__)
    parsed_args = args.get_args(sys.argv)
    path = parsed_args.path
    statick.get_config(parsed_args)
    statick.get_exceptions(parsed_args)
    issues, success = statick.run(path, parsed_args)
    for tool in issues:
        assert not issues[tool]
    assert success
    try:
        shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-custom"))
    except OSError as ex:
        print(f"Error: {ex}")
示例#9
0
def test_run_missing_tool_dependency(init_statick):
    """
    Test that a tool plugin results in failure when its dependency is not configured to run.

    Expected results: issues is None and success is False
    """
    cttp = ClangTidyToolPlugin()
    if not cttp.command_exists("clang-tidy"):
        pytest.skip("Can't find clang-tidy, unable to test clang-tidy plugin")
    args = Args("Statick tool")
    args.parser.add_argument("--path", help="Path of package to scan")

    statick = Statick(args.get_user_paths())
    statick.gather_args(args.parser)
    sys.argv = [
        "--path",
        os.path.dirname(__file__),
        "--force-tool-list",
        "clang-tidy",
        "--config",
        os.path.join(os.path.dirname(__file__), "rsc",
                     "config-missing-tool-dependency.yaml"),
    ]
    args.output_directory = os.path.dirname(__file__)
    parsed_args = args.get_args(sys.argv)
    path = parsed_args.path
    statick.get_config(parsed_args)
    statick.get_exceptions(parsed_args)
    issues, success = statick.run(path, parsed_args)
    assert issues is None
    assert not success
    try:
        shutil.rmtree(
            os.path.join(os.path.dirname(__file__), "statick-sei_cert"))
    except OSError as ex:
        print("Error: {}".format(ex))