[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Slight wording fixes regarding payload/cell size



commit 1f4ae95d7acf4171cd6da8abbb858e31cccb3cd9
Author: Dave Rolek <dmr-x@xxxxxxxxxx>
Date:   Wed May 30 20:04:34 2018 +0000

    Slight wording fixes regarding payload/cell size
    
    This ValueError also didn't have a test to it, so add one.
---
 stem/client/cell.py      |  4 ++--
 test/unit/client/cell.py | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/stem/client/cell.py b/stem/client/cell.py
index a679968e..b90fb7a6 100644
--- a/stem/client/cell.py
+++ b/stem/client/cell.py
@@ -186,7 +186,7 @@ class Cell(object):
 
     :return: **bytes** with the encoded payload
 
-    :raise: **ValueError** if cell type invalid or payload is too large
+    :raise: **ValueError** if cell type invalid or payload makes cell too large
     """
 
     if isinstance(cls, CircuitCell) and circ_id is None:
@@ -204,7 +204,7 @@ class Cell(object):
 
     if cls.IS_FIXED_SIZE:
       if len(cell) > link_protocol.fixed_cell_len:
-        raise ValueError('Payload of %s is too large (%i bytes), must be less than %i' % (cls.NAME, len(cell), link_protocol.fixed_cell_len))
+        raise ValueError('Cell of type %s is too large (%i bytes), must not be more than %i. Check payload size (was %i bytes)' % (cls.NAME, len(cell), link_protocol.fixed_cell_len, len(payload)))
 
       cell += ZERO * (link_protocol.fixed_cell_len - len(cell))
 
diff --git a/test/unit/client/cell.py b/test/unit/client/cell.py
index 2fe05369..d36500cc 100644
--- a/test/unit/client/cell.py
+++ b/test/unit/client/cell.py
@@ -114,6 +114,20 @@ class TestCell(unittest.TestCase):
     # that's probably not worth it; instead we'll use the instance method _unpack()
     self.assertRaisesRegexp(NotImplementedError, '^%s$' % re.escape('Unpacking not yet implemented for UNIMPLEMENTED cells'), instance._unpack, b'dummy', 0, 2)
 
+  def test_payload_too_large(self):
+    class OversizedCell(Cell):
+      NAME = 'OVERSIZED'
+      VALUE = 127  # currently nonsense, but potentially will be allocated in the distant future
+      IS_FIXED_SIZE = True
+
+      def pack(self, link_protocol):
+        return OversizedCell._pack(link_protocol, ZERO * (FIXED_PAYLOAD_LEN + 1))
+
+    instance = OversizedCell()
+
+    expected_message = 'Cell of type OVERSIZED is too large (%i bytes), must not be more than %i. Check payload size (was %i bytes)' % (FIXED_PAYLOAD_LEN + 4, FIXED_PAYLOAD_LEN + 3, FIXED_PAYLOAD_LEN + 1)
+    self.assertRaisesRegexp(ValueError, '^%s$' % re.escape(expected_message), instance.pack, 2)
+
   def test_unpack_for_new_link(self):
     expected_certs = (
       (CertType.LINK, 1, b'0\x82\x02F0\x82\x01\xaf'),



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits