fix(towercore): preserve context export
- Allow opcode 0x23 inventory requests used by EXPORT_CONTEXT. - Continue rejecting duplicate subscriber selectors on opcode 0x21 reads.
This commit is contained in:
1 parent
caf9b2fc39
commit
3b1bdc9739
2 files changed
+4
-10
No files matched your search
+1
-5
@@ -6,7 +6,6 @@ import os
|
|||||||
|
|
||||||
HEADER_SIZE = 16
|
HEADER_SIZE = 16
|
||||||
READ_OPCODE = 0x21
|
READ_OPCODE = 0x21
|
||||||
BULK_READ_OPCODE = 0x23
|
|
||||||
SUBSCRIBER_TAG = 0x0B
|
SUBSCRIBER_TAG = 0x0B
|
||||||
BACKEND_HOST = os.environ.get("BACKEND_HOST", "towercore")
|
BACKEND_HOST = os.environ.get("BACKEND_HOST", "towercore")
|
||||||
BACKEND_PORT = int(os.environ.get("BACKEND_PORT", "7250"))
|
BACKEND_PORT = int(os.environ.get("BACKEND_PORT", "7250"))
|
||||||
@@ -37,10 +36,7 @@ def should_block(frame: bytes) -> bool:
|
|||||||
raise ValueError("invalid frame length")
|
raise ValueError("invalid frame length")
|
||||||
tags = tlv_tags(frame[HEADER_SIZE:])
|
tags = tlv_tags(frame[HEADER_SIZE:])
|
||||||
opcode = frame[3]
|
opcode = frame[3]
|
||||||
return (
|
return opcode == READ_OPCODE and tags.count(SUBSCRIBER_TAG) > 1
|
||||||
opcode == BULK_READ_OPCODE and SUBSCRIBER_TAG in tags
|
|
||||||
or opcode == READ_OPCODE and tags.count(SUBSCRIBER_TAG) > 1
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def client_frames(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
|
async def client_frames(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
|
||||||
|
|||||||
@@ -12,12 +12,10 @@ def frame(opcode: int, fields: list[tuple[int, bytes]]) -> bytes:
|
|||||||
|
|
||||||
|
|
||||||
class GuardTests(unittest.TestCase):
|
class GuardTests(unittest.TestCase):
|
||||||
def test_blocks_cross_subscriber_bulk_read(self) -> None:
|
def test_allows_single_subscriber_inventory(self) -> None:
|
||||||
guard = importlib.util.find_spec("guard")
|
|
||||||
self.assertIsNotNone(guard, "Towercore guard is not implemented")
|
|
||||||
module = importlib.import_module("guard")
|
module = importlib.import_module("guard")
|
||||||
request = frame(0x23, [(0x0B, b"victim01"), (0x0B, b"victim02")])
|
request = frame(0x23, [(0x0B, b"victim01")])
|
||||||
self.assertTrue(module.should_block(request))
|
self.assertFalse(module.should_block(request))
|
||||||
|
|
||||||
def test_blocks_duplicate_subscriber_override_on_read(self) -> None:
|
def test_blocks_duplicate_subscriber_override_on_read(self) -> None:
|
||||||
module = importlib.import_module("guard")
|
module = importlib.import_module("guard")
|
||||||
|
|||||||
Reference in new issue
Block a user