Esempio n. 1
0
def test_cli_output():
    """Run CLI output option."""
    log_file = "log.asserts"
    os.environ['FA_STRICT'] = 'false'
    testargs = ["asserts", "-q", "-O", log_file, EXPLOIT_OPEN]
    with patch.object(sys, 'argv', testargs):
        with pytest.raises(SystemExit):
            cli.main()
            assert os.path.exists(log_file)
            os.unlink(log_file)
Esempio n. 2
0
def test_cli_color():
    """Run CLI in without colors."""
    os.environ['FA_STRICT'] = 'false'
    testargs = ["asserts", "-n", EXPLOIT_OPEN]
    with patch.object(sys, 'argv', testargs):
        with pytest.raises(SystemExit):
            assert not cli.main()
Esempio n. 3
0
def test_cli_strict_bad():
    """Run CLI with a bad FA_STRICT value."""
    os.environ['FA_STRICT'] = 'badvalue'
    testargs = ["asserts", EXPLOIT_OPEN]
    with patch.object(sys, 'argv', testargs):
        with pytest.raises(SystemExit):
            assert cli.main()
Esempio n. 4
0
def test_cli_noargs():
    """Run CLI with no args."""
    os.environ['FA_STRICT'] = 'false'
    testargs = ["asserts"]
    with patch.object(sys, 'argv', testargs):
        with pytest.raises(SystemExit):
            assert cli.main()
Esempio n. 5
0
def test_cli_method_stats():
    """Run CLI with method stats flag."""
    os.environ['FA_STRICT'] = 'false'
    testargs = ["asserts", "-ms", EXPLOIT_OPEN]
    with patch.object(sys, 'argv', testargs):
        with pytest.raises(SystemExit):
            assert not cli.main()
Esempio n. 6
0
def test_cli_strict_with_rich_exit_codes():
    """Run CLI in strict mode."""
    os.environ['FA_STRICT'] = 'true'
    testargs = ["asserts", "--enrich-exit-codes", EXPLOIT_OPEN]
    with patch.object(sys, 'argv', testargs):
        with pytest.raises(SystemExit):
            assert cli.main()
Esempio n. 7
0
def test_cli_filtered():
    """Run CLI with filtered results."""
    os.environ['FA_STRICT'] = 'false'
    testargs = ["asserts", "-cou", EXPLOIT_OPEN]
    with patch.object(sys, 'argv', testargs):
        with pytest.raises(SystemExit):
            assert not cli.main()
Esempio n. 8
0
def test_cli_lang():
    """Run CLI lang option."""
    os.environ['FA_STRICT'] = 'false'
    testargs = ["asserts", "-L", 'test/static/lang/csharp/']
    with patch.object(sys, 'argv', testargs):
        with pytest.raises(SystemExit):
            assert not cli.main()
Esempio n. 9
0
def test_cli_dns():
    """Run CLI dns option."""
    os.environ['FA_STRICT'] = 'false'
    testargs = ["asserts", "-D", '127.0.0.1']
    with patch.object(sys, 'argv', testargs):
        with pytest.raises(SystemExit):
            assert not cli.main()
Esempio n. 10
0
def test_rich_exit_codes_non_strict():
    """Test the rich exit codes running in non strict mode."""
    os.environ['FA_STRICT'] = 'false'
    with patch.object(sys, 'argv', ["asserts", "-eec"]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == 0
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_OPEN]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == 0
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_CLOSED]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == 0
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_UNKNOWN]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == 0
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_WITH_ERRORS]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == 0
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_BAD_PATH]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == 0
Esempio n. 11
0
def test_rich_exit_codes_strict():
    """Test the rich exit codes running in strict mode."""
    os.environ['FA_STRICT'] = 'true'
    with patch.object(sys, 'argv', ["asserts", "-eec"]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == cli.RICH_EXIT_CODES['config-error']
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_OPEN]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == cli.RICH_EXIT_CODES['open']
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_CLOSED]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == cli.RICH_EXIT_CODES['closed']
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_UNKNOWN]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == cli.RICH_EXIT_CODES['unknown']
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_WITH_ERRORS]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == cli.RICH_EXIT_CODES['exploit-error']
    with patch.object(sys, 'argv', ["asserts", "-eec", EXPLOIT_BAD_PATH]):
        with pytest.raises(SystemExit) as exc:
            cli.main()
        assert exc.value.code == cli.RICH_EXIT_CODES['exploit-not-found']