|
| 1 | +import pytest |
| 2 | +import struct |
| 3 | + |
| 4 | +from rsocket.exceptions import RSocketError |
1 | 5 | from rsocket.extensions.authentication import AuthenticationBearer, AuthenticationSimple |
| 6 | +from rsocket.extensions.mimetypes import WellKnownMimeTypes |
2 | 7 | from rsocket.extensions.routing import RoutingMetadata |
| 8 | +from rsocket.extensions.tagging import TaggingMetadata |
3 | 9 |
|
4 | 10 |
|
5 | 11 | def test_authentication_bearer(): |
@@ -39,3 +45,32 @@ def test_routing(): |
39 | 45 | parsed.parse(data) |
40 | 46 |
|
41 | 47 | assert parsed == routing |
| 48 | + |
| 49 | + |
| 50 | +def test_tagging_metadata_serialize_max_length(): |
| 51 | + tag = 's' * 255 |
| 52 | + meta = TaggingMetadata(WellKnownMimeTypes.MESSAGE_RSOCKET_ROUTING, [tag]) |
| 53 | + |
| 54 | + serialized = meta.serialize() |
| 55 | + |
| 56 | + length = struct.pack('>B', len(tag)) |
| 57 | + assert length + bytes(tag, 'utf-8') == serialized |
| 58 | + |
| 59 | + |
| 60 | +def test_tagging_metadata_serialize_exception_length(): |
| 61 | + tag = 's' * 256 |
| 62 | + meta = TaggingMetadata(WellKnownMimeTypes.MESSAGE_RSOCKET_ROUTING, [tag]) |
| 63 | + |
| 64 | + with pytest.raises(RSocketError) as e_info: |
| 65 | + meta.serialize() |
| 66 | + |
| 67 | + assert e_info.match(f'Tag length longer than 255 characters: "b\'{tag}\'"') |
| 68 | + |
| 69 | + |
| 70 | +def test_tagging_metadata_parse(): |
| 71 | + meta = TaggingMetadata(WellKnownMimeTypes.MESSAGE_RSOCKET_ROUTING) |
| 72 | + tag = 's' * 255 |
| 73 | + length = struct.pack('>B', len(tag)) |
| 74 | + |
| 75 | + meta.parse(length + bytes(tag, 'utf-8')) |
| 76 | + assert tag == meta.tags[0].decode() |
0 commit comments