mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 22:26:33 +00:00
40be55ac03
Made-with: Cursor
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import xxhash
|
|
|
|
|
|
def test_compute_media_content_hash_small_file():
|
|
# Arrange
|
|
from media_hash import compute_media_content_hash
|
|
|
|
data = b"x" * 100
|
|
expected = xxhash.xxh64(len(data).to_bytes(8, "little") + data).hexdigest()
|
|
# Act
|
|
out = compute_media_content_hash(data)
|
|
# Assert
|
|
assert out == expected
|
|
|
|
|
|
def test_compute_media_content_hash_large_file():
|
|
# Arrange
|
|
from media_hash import compute_media_content_hash
|
|
|
|
data = (bytes(range(256)) * 20)[:5000]
|
|
n = len(data)
|
|
mid = (n - 1024) // 2
|
|
blob = (
|
|
n.to_bytes(8, "little")
|
|
+ data[0:1024]
|
|
+ data[mid : mid + 1024]
|
|
+ data[-1024:]
|
|
)
|
|
expected = xxhash.xxh64(blob).hexdigest()
|
|
# Act
|
|
out = compute_media_content_hash(data)
|
|
# Assert
|
|
assert out == expected
|
|
|
|
|
|
def test_compute_media_content_hash_virtual_prefix():
|
|
# Arrange
|
|
from media_hash import compute_media_content_hash
|
|
|
|
# Act
|
|
v = compute_media_content_hash(b"abc", virtual=True)
|
|
n = compute_media_content_hash(b"abc", virtual=False)
|
|
# Assert
|
|
assert v.startswith("V")
|
|
assert not n.startswith("V")
|
|
assert v == "V" + n
|