mirror of
https://github.com/kc1awv/rrcd.git
synced 2026-07-20 14:58:10 -07:00
fix JOINED/PARTED messages, enhance code quality with type checks and new dependencies, update changelog for version 0.2.1
This commit is contained in:
+12
-11
@@ -1,4 +1,5 @@
|
||||
"""Tests for resource transfer functionality."""
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
@@ -24,7 +25,7 @@ def test_resource_envelope_serialization():
|
||||
rid = os.urandom(8)
|
||||
payload = b"This is a test payload that is larger than typical MDU"
|
||||
sha256 = hashlib.sha256(payload).digest()
|
||||
|
||||
|
||||
body = {
|
||||
B_RES_ID: rid,
|
||||
B_RES_KIND: RES_KIND_NOTICE,
|
||||
@@ -32,21 +33,21 @@ def test_resource_envelope_serialization():
|
||||
B_RES_SHA256: sha256,
|
||||
B_RES_ENCODING: "utf-8",
|
||||
}
|
||||
|
||||
|
||||
envelope = make_envelope(
|
||||
T_RESOURCE_ENVELOPE,
|
||||
src=src,
|
||||
room="test",
|
||||
body=body,
|
||||
)
|
||||
|
||||
|
||||
# Serialize and deserialize
|
||||
encoded = encode(envelope)
|
||||
decoded = decode(encoded)
|
||||
|
||||
|
||||
assert decoded[K_T] == T_RESOURCE_ENVELOPE
|
||||
assert decoded[K_SRC] == src
|
||||
|
||||
|
||||
decoded_body = decoded[K_BODY]
|
||||
assert decoded_body[B_RES_ID] == rid
|
||||
assert decoded_body[B_RES_KIND] == RES_KIND_NOTICE
|
||||
@@ -59,22 +60,22 @@ def test_resource_envelope_minimal():
|
||||
"""Test resource envelope with minimal required fields."""
|
||||
src = os.urandom(16)
|
||||
rid = os.urandom(8)
|
||||
|
||||
|
||||
body = {
|
||||
B_RES_ID: rid,
|
||||
B_RES_KIND: "blob",
|
||||
B_RES_SIZE: 1024,
|
||||
}
|
||||
|
||||
|
||||
envelope = make_envelope(
|
||||
T_RESOURCE_ENVELOPE,
|
||||
src=src,
|
||||
body=body,
|
||||
)
|
||||
|
||||
|
||||
encoded = encode(envelope)
|
||||
decoded = decode(encoded)
|
||||
|
||||
|
||||
decoded_body = decoded[K_BODY]
|
||||
assert B_RES_SHA256 not in decoded_body
|
||||
assert B_RES_ENCODING not in decoded_body
|
||||
@@ -85,12 +86,12 @@ def test_sha256_verification():
|
||||
"""Test SHA256 hash computation for payload verification."""
|
||||
payload = b"Test payload for SHA256 verification"
|
||||
expected = hashlib.sha256(payload).digest()
|
||||
|
||||
|
||||
# Verify we can compute and compare hashes correctly
|
||||
computed = hashlib.sha256(payload).digest()
|
||||
assert computed == expected
|
||||
assert len(computed) == 32
|
||||
|
||||
|
||||
# Verify mismatch detection
|
||||
wrong_payload = b"Different payload"
|
||||
wrong_hash = hashlib.sha256(wrong_payload).digest()
|
||||
|
||||
Reference in New Issue
Block a user