1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#!/usr/bin/env python
import pytest
import ssdeep
class TestFunctionsFail(object):
def test_compare(self):
with pytest.raises(TypeError):
ssdeep.compare(
"3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C",
None
)
with pytest.raises(TypeError):
ssdeep.compare(
None,
"3:AXGBicFlIHBGcL6wCrFQEv:AXGH6xLsr2C"
)
with pytest.raises(ssdeep.InternalError):
ssdeep.compare(
"3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C",
""
)
def test_hash(self):
with pytest.raises(TypeError):
ssdeep.hash(None)
with pytest.raises(TypeError):
ssdeep.hash(1234)
class TestFunctions(object):
def test_compare(self):
res = ssdeep.compare(
"3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C",
"3:AXGBicFlIHBGcL6wCrFQEv:AXGH6xLsr2C"
)
assert res == 22
res = ssdeep.compare(
b"3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C",
b"3:AXGBicFlIHBGcL6wCrFQEv:AXGH6xLsr2C"
)
assert res == 22
def test_hash_1(self):
res = ssdeep.hash("Also called fuzzy hashes, Ctph can match inputs that have homologies.")
assert res == "3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C"
def test_hash_2(self):
res = ssdeep.hash("Also called fuzzy hashes, CTPH can match inputs that have homologies.")
assert res == "3:AXGBicFlIHBGcL6wCrFQEv:AXGH6xLsr2C"
def test_hash_3(self):
res = ssdeep.hash(b"Also called fuzzy hashes, CTPH can match inputs that have homologies.")
assert res == "3:AXGBicFlIHBGcL6wCrFQEv:AXGH6xLsr2C"
def test_hash_from_file(self):
with pytest.raises(IOError):
ssdeep.hash_from_file("tests/files/")
with pytest.raises(IOError):
ssdeep.hash_from_file("tests/files/file-does-not-exist.txt")
res = ssdeep.hash_from_file("tests/files/file.txt")
assert res == "3:AXGBicFlgVNhBGcL6wCrFQE3:AXGHsNhxLsr2s"
class TestHashClass(object):
def test_update(self):
obj = ssdeep.Hash()
obj.update("Also called fuzzy hashes, Ctph can match inputs that have homologies.")
res = obj.digest()
assert res == "3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C"
class TestPseudoHashClass(object):
def test_update(self):
obj = ssdeep.PseudoHash()
obj.update("Also called fuzzy hashes, ")
obj.update("Ctph can match inputs that have homologies.")
res = obj.digest()
assert res == "3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C"
class TestHashClassFail(object):
def test_update_01(self):
obj = ssdeep.Hash()
with pytest.raises(TypeError):
obj.update(None)
def test_update_02(self):
obj = ssdeep.Hash()
with pytest.raises(TypeError):
obj.update(1234)
|