Example #1
0
def test_scan_patch(client, name, input_patch, expected):
    c = Commit()
    c._patch = input_patch

    with my_vcr.use_cassette(name):
        results = c.scan(client=client,
                         matches_ignore={},
                         all_policies=True,
                         verbose=False)
        assert (process_results(results, verbose=True,
                                show_secrets=True) == expected.exit_code)
        for result in results:
            if result.scan.policy_breaks:
                assert len(
                    result.scan.policy_breaks[0].matches) == expected.matches
                if expected.first_match:
                    assert (result.scan.policy_breaks[0].matches[0].match ==
                            expected.first_match)
            else:
                assert result.scan.policy_breaks == []

            if expected.want:
                assert result.content == expected.want["content"]
                assert result.filename == expected.want["filename"]
                assert result.filemode == expected.want["filemode"]
Example #2
0
def test_patch_separation_ignore():
    c = Commit()
    c._patch = PATCH_SEPARATION
    file_to_ignore = ".env"
    c.filter_set = [os.path.join(os.getcwd(), file_to_ignore)]
    files = list(c.get_files())

    assert len(files) == 3
    assert not (any(entry.filename == file_to_ignore for entry in files))
Example #3
0
def test_patch_separation():
    c = Commit()
    c._patch = PATCH_SEPARATION
    files = list(c.get_files())

    assert len(files) == 4

    assert c.info.author == "Testificate Jose"
    assert c.info.email == "*****@*****.**"
    assert c.info.date == "Fri Oct 18 13:20:00 2012 +0100"
Example #4
0
def test_patch_max_size():
    c = Commit()
    c._patch = """
diff --git a/tests/test_scannable.py b/.env
new file mode 100644
index 0000000..0000000
--- /dev/null
+++ b/.env
@@ -0,0 +1,112 @@
CHECK_ENVIRONMENT=true
    """
    c._patch += "a" * MAX_FILE_SIZE
    files = list(c.get_files())

    assert len(files) == 0
Example #5
0
def test_patch_separation():
    c = Commit()
    c._patch = PATCH_SEPARATION
    files = list(c.get_files())

    assert len(files) == 4
Example #6
0
def test_get_filemode_new():
    line = "new file mode 100644\n"
    assert Commit().get_filemode(line) == Filemode.NEW
Example #7
0
def test_get_filename():
    line = "a/test.txt b/test.txt"
    assert Commit().get_filename(line) == "test.txt"
Example #8
0
def test_get_filemode_rename():
    line = "similarity index 99%\n"
    assert Commit().get_filemode(line) == Filemode.RENAME
Example #9
0
def test_get_filemode_modify():
    line = "index 3d47bfe..ee93988 100644\n"
    assert Commit().get_filemode(line) == Filemode.MODIFY
Example #10
0
def test_get_filemode_delete():
    line = "deleted file mode 100644\n"
    assert Commit().get_filemode(line) == Filemode.DELETE