Revision: 398
Author: bslatkin
Date: Mon Nov 15 14:49:03 2010
Log: hub: do not re-record feeds for subscription reconfirmation topics
http://code.google.com/p/pubsubhubbub/source/detail?r=398

Modified:
 /trunk/hub/main.py
 /trunk/hub/main_test.py

=======================================
--- /trunk/hub/main.py  Fri Nov  5 18:35:52 2010
+++ /trunk/hub/main.py  Mon Nov 15 14:49:03 2010
@@ -1915,7 +1915,7 @@
 # Subscription handlers and workers

 def confirm_subscription(mode, topic, callback, verify_token,
-                         secret, lease_seconds):
+                         secret, lease_seconds, record_topic=True):
   """Confirms a subscription request and updates a Subscription instance.

   Args:
@@ -1927,6 +1927,8 @@
     lease_seconds: Number of seconds the client would like the subscription
to last before expiring. If more than max_lease_seconds, will be capped
       to that value. Should be an integer number.
+    record_topic: When True, also cause the topic's feed ID to be recorded
+      if this is a new subscription.

   Returns:
True if the subscription was confirmed properly, False if the subscription
@@ -1971,8 +1973,9 @@
     if mode == 'subscribe':
       Subscription.insert(callback, topic, verify_token, secret,
                           lease_seconds=real_lease_seconds)
-      # Enqueue a task to record the feed and do discovery for it's ID.
-      KnownFeed.record(topic)
+      if record_topic:
+        # Enqueue a task to record the feed and do discovery for it's ID.
+        KnownFeed.record(topic)
     else:
       Subscription.remove(callback, topic)
     logging.info('Subscription action verified, '
@@ -2113,7 +2116,8 @@

     if not hooks.execute(confirm_subscription,
         mode, sub.topic, sub.callback,
-        verify_token, secret, sub.lease_seconds):
+        verify_token, secret, sub.lease_seconds,
+        record_topic=False):
# After repeated re-confirmation failures for a subscription, assume that # the callback is dead and archive it. End-user-initiated subscription
       # requests cannot possibly follow this code path, preventing attacks
=======================================
--- /trunk/hub/main_test.py     Fri Nov  5 18:35:52 2010
+++ /trunk/hub/main_test.py     Mon Nov 15 14:49:03 2010
@@ -3442,17 +3442,13 @@
     self.assertEquals(secret or self.secret, params['secret'])
     self.assertEquals(str(auto_reconfirm), params['auto_reconfirm'])

-  def verify_record_task(self, topic):
-    """Tests there is a valid KnownFeedIdentity task enqueued.
-
-    Args:
-      topic: The topic the task should be for.
+  def verify_no_record_task(self):
+    """Tests there is not KnownFeedIdentity task enqueued.

     Raises:
-      AssertionError if the task isn't there.
+      AssertionError if the task is there.
     """
- task = testutil.get_tasks(main.MAPPINGS_QUEUE, index=0, expected_count=1)
-    self.assertEquals(topic, task['params']['topic'])
+    task = testutil.get_tasks(main.MAPPINGS_QUEUE, expected_count=0)

   def testNoWork(self):
"""Tests when a task is enqueued for a Subscription that doesn't exist."""
@@ -3473,7 +3469,7 @@
                         ('secret', self.secret),
                         ('next_state', Subscription.STATE_VERIFIED))
     self.verify_task(Subscription.STATE_VERIFIED)
-    self.verify_record_task(self.topic)
+    self.verify_no_record_task()

     sub = Subscription.get_by_key_name(self.sub_key)
     self.assertEquals(Subscription.STATE_VERIFIED, sub.subscription_state)
@@ -3504,7 +3500,7 @@
                         ('secret', self.secret),
                         ('next_state', Subscription.STATE_VERIFIED))
     self.verify_task(Subscription.STATE_VERIFIED)
-    self.verify_record_task(self.topic)
+    self.verify_no_record_task()

     sub = Subscription.get_by_key_name(self.sub_key)
     self.assertEquals(Subscription.STATE_VERIFIED, sub.subscription_state)
@@ -3631,7 +3627,7 @@
     self.assertEquals(Subscription.STATE_VERIFIED, sub.subscription_state)
     self.assertEquals(second_token, sub.verify_token)
     self.assertEquals(second_secret, sub.secret)
-    self.verify_record_task(self.topic)
+    self.verify_no_record_task()

   def testConfirmError(self):
     """Tests when an exception is raised while confirming a subscription.
@@ -3643,7 +3639,7 @@
     Subscription.request_insert(
         self.callback, self.topic, self.verify_token, self.secret)
     # All exceptions should just fall through.
-    def new_confirm(*args):
+    def new_confirm(*args, **kwargs):
       called[0] = True
       raise db.Error()
     try:

Reply via email to