[tor-commits] [stem/master] Don't try to test cell packing with non-blank, non-ZERO 'unused' content without specifying it in constructor

atagar at torproject.org atagar at torproject.org
Thu Jul 12 18:53:11 UTC 2018


commit dbb648f43fe8803637d1a66d988dd995ac3af2b8
Author: Dave Rolek <dmr-x at riseup.net>
Date:   Wed Jul 11 23:17:30 2018 +0000

    Don't try to test cell packing with non-blank,non-ZERO 'unused' content without specifying it in constructor
    
    The test for DestroyCell already did this, so apply this structure to
    tests of all other cell types that may have 'unused' content.
    
    And since this is now such a common pattern in the test file, having a
    comment for it is less necessary, so also removing that.
---
 test/unit/client/cell.py | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/test/unit/client/cell.py b/test/unit/client/cell.py
index d45886f8..ad9bb0f0 100644
--- a/test/unit/client/cell.py
+++ b/test/unit/client/cell.py
@@ -185,8 +185,9 @@ class TestCell(unittest.TestCase):
 
   def test_relay_cell(self):
     for cell_bytes, (command, command_int, circ_id, stream_id, data, digest, unused, link_protocol) in RELAY_CELLS.items():
-      self.assertEqual(cell_bytes, RelayCell(circ_id, command, data, digest, stream_id).pack(link_protocol))
-      self.assertEqual(cell_bytes, RelayCell(circ_id, command_int, data, digest, stream_id).pack(link_protocol))
+      if not unused.strip(ZERO):
+        self.assertEqual(cell_bytes, RelayCell(circ_id, command, data, digest, stream_id).pack(link_protocol))
+        self.assertEqual(cell_bytes, RelayCell(circ_id, command_int, data, digest, stream_id).pack(link_protocol))
 
       cell = Cell.pop(cell_bytes, link_protocol)[0]
       self.assertEqual(circ_id, cell.circ_id)
@@ -220,9 +221,6 @@ class TestCell(unittest.TestCase):
 
   def test_destroy_cell(self):
     for cell_bytes, (circ_id, reason, reason_int, unused, link_protocol) in DESTROY_CELLS.items():
-      # Packed cells always pad with zeros, so if we're testing something with
-      # non-zero padding then skip this check.
-
       if not unused.strip(ZERO):
         self.assertEqual(cell_bytes, DestroyCell(circ_id, reason).pack(link_protocol))
         self.assertEqual(cell_bytes, DestroyCell(circ_id, reason_int).pack(link_protocol))
@@ -236,7 +234,8 @@ class TestCell(unittest.TestCase):
 
   def test_create_fast_cell(self):
     for cell_bytes, (circ_id, key_material, unused, link_protocol) in CREATE_FAST_CELLS.items():
-      self.assertEqual(cell_bytes, CreateFastCell(circ_id, key_material).pack(link_protocol))
+      if not unused.strip(ZERO):
+        self.assertEqual(cell_bytes, CreateFastCell(circ_id, key_material).pack(link_protocol))
 
       cell = Cell.pop(cell_bytes, link_protocol)[0]
       self.assertEqual(circ_id, cell.circ_id)
@@ -248,7 +247,8 @@ class TestCell(unittest.TestCase):
 
   def test_created_fast_cell(self):
     for cell_bytes, (circ_id, key_material, derivative_key, unused, link_protocol) in CREATED_FAST_CELLS.items():
-      self.assertEqual(cell_bytes, CreatedFastCell(circ_id, derivative_key, key_material).pack(link_protocol))
+      if not unused.strip(ZERO):
+        self.assertEqual(cell_bytes, CreatedFastCell(circ_id, derivative_key, key_material).pack(link_protocol))
 
       cell = Cell.pop(cell_bytes, link_protocol)[0]
       self.assertEqual(circ_id, cell.circ_id)
@@ -270,7 +270,8 @@ class TestCell(unittest.TestCase):
 
   def test_netinfo_cell(self):
     for cell_bytes, (timestamp, receiver_address, sender_addresses, unused, link_protocol) in NETINFO_CELLS.items():
-      self.assertEqual(cell_bytes, NetinfoCell(receiver_address, sender_addresses, timestamp).pack(link_protocol))
+      if not unused.strip(ZERO):
+        self.assertEqual(cell_bytes, NetinfoCell(receiver_address, sender_addresses, timestamp).pack(link_protocol))
 
       cell = Cell.pop(cell_bytes, link_protocol)[0]
       self.assertEqual(timestamp, cell.timestamp)
@@ -298,7 +299,8 @@ class TestCell(unittest.TestCase):
 
   def test_certs_cell(self):
     for cell_bytes, (certs, unused, link_protocol) in CERTS_CELLS.items():
-      self.assertEqual(cell_bytes, CertsCell(certs).pack(link_protocol))
+      if not unused.strip(ZERO):
+        self.assertEqual(cell_bytes, CertsCell(certs).pack(link_protocol))
 
       cell = Cell.pop(cell_bytes, link_protocol)[0]
       self.assertEqual(certs, cell.certificates)
@@ -316,7 +318,8 @@ class TestCell(unittest.TestCase):
 
   def test_auth_challenge_cell(self):
     for cell_bytes, (challenge, methods, unused, link_protocol) in AUTH_CHALLENGE_CELLS.items():
-      self.assertEqual(cell_bytes, AuthChallengeCell(methods, challenge).pack(link_protocol))
+      if not unused.strip(ZERO):
+        self.assertEqual(cell_bytes, AuthChallengeCell(methods, challenge).pack(link_protocol))
 
       cell = Cell.pop(cell_bytes, link_protocol)[0]
       self.assertEqual(challenge, cell.challenge)





More information about the tor-commits mailing list