[tor-bugs] #12147 [BridgeDB]: BridgeDB distributors do not handle time intervals correctly

Tor Bug Tracker & Wiki blackhole at torproject.org
Mon Aug 4 01:36:31 UTC 2014


#12147: BridgeDB distributors do not handle time intervals correctly
-------------------------+-------------------------------------------------
     Reporter:  isis     |      Owner:  isis
         Type:  defect   |     Status:  closed
     Priority:           |  Milestone:
  critical               |    Version:
    Component:           |   Keywords:  bridgedb-0.2.2, security, bridgedb-
  BridgeDB               |  https
   Resolution:  fixed    |  Parent ID:
Actual Points:           |
       Points:           |
-------------------------+-------------------------------------------------
Changes (by isis):

 * status:  reopened => closed
 * resolution:   => fixed


Comment:

 Robert Ransom supplied a patch, adding the following unittest to check for
 this issue:

 {{{
 commit a9e65a0c9c3e40359731b6fe3408e068f9c1501a
 Author:     Robert Ransom <rransom.8774 at gmail.com>
 AuthorDate: Tue Jul 15 04:04:46 2014 -0400
 Commit:     Isis Lovecruft <isis at torproject.org>
 CommitDate: Wed Jul 16 01:55:32 2014 +0000

     Fix test suite for bridgedb.scheduled.Unscheduled

     Previously, the test suite checked only that Unscheduled.getInterval
 would
     return a particular value when invoked with no argument.  Now, the
 test
     suite checks the only property of Unscheduled.getInterval that its
 callers
     rely on: that it returns the same string regardless of which time is
 passed
     in to it.

 diff --git a/lib/bridgedb/test/test_schedule.py
 b/lib/bridgedb/test/test_schedule.py
 index 24c45ef..178e3e4 100644
 --- a/lib/bridgedb/test/test_schedule.py
 +++ b/lib/bridgedb/test/test_schedule.py
 @@ -36,10 +36,21 @@ class UnscheduledTests(unittest.TestCase):
          self.assertIsInstance(time, int)
          self.assertEquals(time, -62135596800)

 -    def test_Unscheduled_getInterval_noargs(self):
 -        time = self.sched.getInterval()
 -        self.assertIsInstance(time, str)
 -        self.assertEquals(time, "1970-01-01 00:00:00")
 +    def test_Unscheduled_getInterval_is_constant(self):
 +        import time
 +        now = time.time()
 +
 +        interval_default = self.sched.getInterval()
 +        self.assertIsInstance(interval_default, str)
 +
 +        interval_zero = self.sched.getInterval(0)
 +        self.assertIsInstance(interval_zero, str)
 +
 +        interval_now = self.sched.getInterval(now)
 +        self.assertIsInstance(interval_now, str)
 +
 +        self.assertEquals(interval_default, interval_zero)
 +        self.assertEquals(interval_default, interval_now)

      def test_Unscheduled_nextIntervalStarts_noargs(self):
          time = self.sched.nextIntervalStarts()
 }}}

 I subsequently committed the following trivial fix to effectively ignore
 the `when` parameter in `bridgedb.schedule.Unscheduled.getInterval()`:

 {{{
 commit a7551e22cc141d48bd7498afcc07d4378c0c0fcc (tpo-
 isis/rransom/fix/12147-schedule-unittest, isislovecruft/rransom/fix/12147
 -schedule-unittest, greyarea/rransom/fix/12147-schedule-unittest,
 rransom/fix/12147-sc
 Author:     Isis Lovecruft <isis at torproject.org>
 AuthorDate: Wed Jul 16 04:13:30 2014 +0000
 Commit:     Isis Lovecruft <isis at torproject.org>
 CommitDate: Wed Jul 16 04:13:30 2014 +0000

     Fix bug shown in test_Unscheduled_getInterval_is_constant() unittest.

      * FIXES an additional problem for #12147 pointed out by Robert
 Ransom's
        `bridgedb.test.test_Unscheduled_getInterval_is_constant()`
 unittest.

 diff --git a/lib/bridgedb/schedule.py b/lib/bridgedb/schedule.py
 index 6cef1a6..930f2e7 100644
 --- a/lib/bridgedb/schedule.py
 +++ b/lib/bridgedb/schedule.py
 @@ -91,6 +91,10 @@ class Unscheduled(object):
      def getInterval(self, when=0):
          """Get the interval that contains the time **when**.

 +        .. note: We explicitly ignore the ``when`` parameter in this
 +            implementation because if something is Unscheduled then
 +            all timestamps should reside within the same period.
 +
          :param int when: The time which we're trying to find the
 corresponding
              interval for.
          :rtype: str
 @@ -98,8 +102,9 @@ class Unscheduled(object):
              specificity depends on what type of interval we're using. For
              example, if using ``"month"``, the return value would be
 something
              like ``"2013-12"``.
          """
 -        return fromUnixSeconds(when).strftime('%04Y-%02m-%02d
 %02H:%02M:%02S')
 +        return fromUnixSeconds(0).strftime('%04Y-%02m-%02d
 %02H:%02M:%02S')

      def nextIntervalStarts(self, when=0):
          """Return the start time of the interval starting _after_ when.
 }}}

 This should be fixed. For good.

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/12147#comment:5>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list