Skip to content

Commit 07843fd

Browse files
committed
server setup unit test
1 parent 77cbd86 commit 07843fd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/rsocket/test_routing.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
from reactivestreams.subscriber import DefaultSubscriber
77
from rsocket.awaitable.awaitable_rsocket import AwaitableRSocket
8+
from rsocket.error_codes import ErrorCode
89
from rsocket.extensions.authentication import Authentication, AuthenticationSimple
910
from rsocket.extensions.composite_metadata import CompositeMetadata
1011
from rsocket.extensions.helpers import route, composite, authenticate_simple
1112
from rsocket.extensions.mimetypes import WellKnownMimeTypes
1213
from rsocket.helpers import create_response
1314
from rsocket.payload import Payload
15+
from rsocket.request_handler import BaseRequestHandler
1416
from rsocket.routing.request_router import RequestRouter
1517
from rsocket.routing.routing_request_handler import RoutingRequestHandler
1618
from rsocket.rx_support.rx_rsocket import RxRSocket
@@ -357,3 +359,33 @@ def handler_factory():
357359
'pass'))))
358360

359361
assert result.data == b'result'
362+
363+
364+
@pytest.mark.allow_error_log(regex_filter='(RSocket error REJECTED_SETUP|Setup error)')
365+
async def test_invalid_metadata_for_routing(lazy_pipe):
366+
router = RequestRouter()
367+
368+
async def authenticate(path: str, authentication: Authentication):
369+
if not isinstance(authentication, AuthenticationSimple) or authentication.password != b'pass':
370+
raise Exception('Invalid credentials')
371+
372+
error_wait = asyncio.Event()
373+
374+
def client_handler_factory():
375+
class ClientHandler(BaseRequestHandler):
376+
async def on_error(self, error_code: ErrorCode, payload: Payload):
377+
error_wait.set()
378+
379+
return ClientHandler()
380+
381+
@router.response('test.path')
382+
async def response():
383+
return create_response(b'result')
384+
385+
def handler_factory():
386+
return RoutingRequestHandler(router, authentication_verifier=authenticate)
387+
388+
async with lazy_pipe(
389+
client_arguments={'handler_factory': client_handler_factory},
390+
server_arguments={'handler_factory': handler_factory}) as (server, client):
391+
await error_wait.wait()

0 commit comments

Comments
 (0)