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

[tor-commits] [stem/master] Fix handling for HS_DESC_CONTENT without descriptors



commit da4550ddf5b4d29d05876c15dbda52713817984e
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Apr 25 18:38:07 2015 -0700

    Fix handling for HS_DESC_CONTENT without descriptors
    
    When you issue a HSFETCH for something that doesn't exist tor provides a
    HS_DESC_CONTENT without a descriptor. This is great, but we didn't properly
    handle it. Also, we didn't strip the 'OK' at the end before attempting to parse
    the descriptor content.
---
 stem/response/events.py      |   10 +++++++---
 test/unit/response/events.py |   17 +++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/stem/response/events.py b/stem/response/events.py
index 47d6a0f..438d1e5 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -691,9 +691,13 @@ class HSDescContentEvent(Event):
     except stem.ProtocolError:
       raise stem.ProtocolError("HS_DESC_CONTENT's directory doesn't match a ServerSpec: %s" % self)
 
-    self.descriptor = list(stem.descriptor.hidden_service_descriptor._parse_file(
-      io.BytesIO(str_tools._to_bytes('\n'.join(str(self).splitlines()[1:]))),
-    ))[0]
+    # skip the first line (our positional arguments) and last ('OK')
+
+    desc_content = str_tools._to_bytes('\n'.join(str(self).splitlines()[1:-1]))
+    self.descriptor = None
+
+    if desc_content:
+      self.descriptor = list(stem.descriptor.hidden_service_descriptor._parse_file(io.BytesIO(desc_content)))[0]
 
 
 class LogEvent(Event):
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index 2797a02..756e531 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -274,6 +274,13 @@ nHIs1lSrV7Ux2WQ3qSVj505fTGSCmaQRBX726ZlTPW0=
 650 OK
 """
 
+HS_DESC_CONTENT_EMPTY_EVENT = """\
+650+HS_DESC_CONTENT 3g2upl4pq6kufc4n 255tjwttk3wi7r2df57nuprs72j2daa3 $D7A0C3262724F2BC9646F6836E967A2777A3AF83~tsunaminitor
+
+.
+650 OK
+"""
+
 # NEWCONSENSUS event from v0.2.1.30.
 
 NEWCONSENSUS_EVENT = """650+NEWCONSENSUS
@@ -886,6 +893,16 @@ class TestEvents(unittest.TestCase):
     self.assertEqual(3, len(desc.introduction_points()))
     self.assertTrue('s9Z0zWHsoPu' in desc.signature)
 
+    event = _get_event(HS_DESC_CONTENT_EMPTY_EVENT)
+
+    self.assertTrue(isinstance(event, stem.response.events.HSDescContentEvent))
+    self.assertEqual('3g2upl4pq6kufc4n', event.address)
+    self.assertEqual('255tjwttk3wi7r2df57nuprs72j2daa3', event.descriptor_id)
+    self.assertEqual('$D7A0C3262724F2BC9646F6836E967A2777A3AF83~tsunaminitor', event.directory)
+    self.assertEqual('D7A0C3262724F2BC9646F6836E967A2777A3AF83', event.directory_fingerprint)
+    self.assertEqual('tsunaminitor', event.directory_nickname)
+    self.assertEqual(None, event.descriptor)
+
   def test_newdesc_event(self):
     event = _get_event(NEWDESC_SINGLE)
     expected_relays = (('B3FA3110CC6F42443F039220C134CBD2FC4F0493', 'Sakura'),)



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