Clean architecture (core use cases + infra gateways), X25519/AES-GCM E2E encryption, tkinter GUI, and a pytest suite. 45 tests passing.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Tests for the presence/ring datagram builders."""
|
|
|
|
import base64
|
|
|
|
from neotalk.core.entities.constants import DatagramType
|
|
from neotalk.core.use_cases.presence.build_presence import (
|
|
build_farewell_use_case,
|
|
build_presence_use_case,
|
|
build_ring_use_case,
|
|
)
|
|
|
|
|
|
def test_build_presence_carries_the_identity(identity):
|
|
# When building a presence beacon
|
|
response = build_presence_use_case(identity)
|
|
|
|
# Then it advertises our fields with a base64 public key
|
|
datagram = response["data"]["datagram"]
|
|
assert datagram["type"] == DatagramType.HELLO
|
|
assert datagram["peer_id"] == identity.peer_id
|
|
assert datagram["alias"] == identity.alias
|
|
assert datagram["tcp_port"] == identity.tcp_port
|
|
assert base64.b64decode(datagram["pubkey"]) == identity.public_key
|
|
|
|
|
|
def test_build_ring_targets_a_peer(identity):
|
|
# When building a ring aimed at a peer
|
|
response = build_ring_use_case(identity, "bob-id")
|
|
|
|
# Then it is a ring datagram carrying our identity and the target
|
|
datagram = response["data"]["datagram"]
|
|
assert datagram["type"] == DatagramType.RING
|
|
assert datagram["peer_id"] == identity.peer_id
|
|
assert datagram["to"] == "bob-id"
|
|
|
|
|
|
def test_build_farewell_is_minimal(identity):
|
|
# When building a farewell
|
|
response = build_farewell_use_case(identity)
|
|
|
|
# Then it only carries the type and our id
|
|
datagram = response["data"]["datagram"]
|
|
assert datagram["type"] == DatagramType.BYE
|
|
assert datagram["peer_id"] == identity.peer_id
|
|
assert "pubkey" not in datagram
|