|
| 1 | +import sys |
1 | 2 | import time
|
2 | 3 | import zlib
|
3 | 4 |
|
4 | 5 | import unittest2
|
5 | 6 |
|
6 | 7 | import testlib
|
| 8 | +import mitogen.core |
7 | 9 | import mitogen.master
|
8 | 10 | import mitogen.parent
|
9 | 11 | import mitogen.utils
|
@@ -341,22 +343,42 @@ def test_previously_alive_context_returns_dead(self):
|
341 | 343 | ))
|
342 | 344 |
|
343 | 345 |
|
| 346 | +def test_siblings_cant_talk(router): |
| 347 | + l1 = router.local() |
| 348 | + l2 = router.local() |
| 349 | + logs = testlib.LogCapturer() |
| 350 | + logs.start() |
| 351 | + |
| 352 | + try: |
| 353 | + l2.call(ping_context, l1) |
| 354 | + except mitogen.core.CallError: |
| 355 | + e = sys.exc_info()[1] |
| 356 | + |
| 357 | + msg = mitogen.core.Router.unidirectional_msg % ( |
| 358 | + l2.context_id, |
| 359 | + l1.context_id, |
| 360 | + ) |
| 361 | + assert msg in str(e) |
| 362 | + assert 'routing mode prevents forward of ' in logs.stop() |
| 363 | + |
| 364 | + |
| 365 | +@mitogen.core.takes_econtext |
| 366 | +def test_siblings_cant_talk_remote(econtext): |
| 367 | + mitogen.parent.upgrade_router(econtext) |
| 368 | + test_siblings_cant_talk(econtext.router) |
| 369 | + |
| 370 | + |
344 | 371 | class UnidirectionalTest(testlib.RouterMixin, testlib.TestCase):
|
345 |
| - def test_siblings_cant_talk(self): |
| 372 | + def test_siblings_cant_talk_master(self): |
346 | 373 | self.router.unidirectional = True
|
347 |
| - l1 = self.router.local() |
348 |
| - l2 = self.router.local() |
349 |
| - logs = testlib.LogCapturer() |
350 |
| - logs.start() |
351 |
| - e = self.assertRaises(mitogen.core.CallError, |
352 |
| - lambda: l2.call(ping_context, l1)) |
| 374 | + test_siblings_cant_talk(self.router) |
353 | 375 |
|
354 |
| - msg = self.router.unidirectional_msg % ( |
355 |
| - l2.context_id, |
356 |
| - l1.context_id, |
357 |
| - ) |
358 |
| - self.assertTrue(msg in str(e)) |
359 |
| - self.assertTrue('routing mode prevents forward of ' in logs.stop()) |
| 376 | + def test_siblings_cant_talk_parent(self): |
| 377 | + # ensure 'unidirectional' attribute is respected for contexts started |
| 378 | + # by children. |
| 379 | + self.router.unidirectional = True |
| 380 | + parent = self.router.local() |
| 381 | + parent.call(test_siblings_cant_talk_remote) |
360 | 382 |
|
361 | 383 | def test_auth_id_can_talk(self):
|
362 | 384 | self.router.unidirectional = True
|
|
0 commit comments