mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 11:16:31 +00:00
[AZ-175] Media table integration with XxHash64 content hashing and status lifecycle
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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
|
||||
Reference in New Issue
Block a user