33 lines
795 B
Python
33 lines
795 B
Python
# pylint: disable=redefined-outer-name
|
|
import pytest
|
|
|
|
from tfw.internals.crypto import sign_message, KeyManager
|
|
|
|
from .util import DummyConnector, simulate_event
|
|
from ..signed_event_handler import SignedEventHandler
|
|
|
|
|
|
@pytest.fixture
|
|
def key():
|
|
yield KeyManager().auth_key
|
|
|
|
|
|
def test_ignores_unauthenticated():
|
|
eh = SignedEventHandler(DummyConnector())
|
|
messages = []
|
|
eh.handle_event = lambda msg, _: messages.append(msg)
|
|
|
|
simulate_event(eh, {"key": "cica"})
|
|
assert not messages
|
|
|
|
|
|
def test_accepts_authenticated(key):
|
|
eh = SignedEventHandler(DummyConnector())
|
|
messages = []
|
|
eh.handle_event = lambda msg, _: messages.append(msg)
|
|
|
|
test_msg = {"key": "cica"}
|
|
sign_message(key, test_msg)
|
|
simulate_event(eh, test_msg)
|
|
assert messages[0] == test_msg
|