[metrics-bugs] #24580 [Metrics/ExoneraTor]: Let ExoneraTor only serve completed dates

Tor Bug Tracker & Wiki blackhole at torproject.org
Tue Dec 12 09:13:56 UTC 2017


#24580: Let ExoneraTor only serve completed dates
--------------------------------+------------------------------
 Reporter:  karsten             |          Owner:  metrics-team
     Type:  enhancement         |         Status:  needs_review
 Priority:  Medium              |      Milestone:
Component:  Metrics/ExoneraTor  |        Version:
 Severity:  Normal              |     Resolution:
 Keywords:                      |  Actual Points:
Parent ID:                      |         Points:
 Reviewer:  iwakeh              |        Sponsor:
--------------------------------+------------------------------

Comment (by iwakeh):

 As there are only dates used in the servlet the calculations should also
 only use date time objects. In addition, the calculation shouldn't rely on
 string comparison when actually comparing dates.

 For example:
 {{{
 #!diff
 diff --git
 a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
 b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
 index c26d08e..beea0d2 100644
 ---
 a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
 +++
 b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
 @@ -15,8 +15,9 @@ import java.io.StringWriter;
  import java.net.URL;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
 +import java.time.LocalDate;
  import java.time.ZoneOffset;
 -import java.time.ZonedDateTime;
 +import java.time.format.DateTimeFormatter;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
 @@ -321,8 +322,8 @@ public class ExoneraTorServlet extends HttpServlet {
     * it matches the day before the current system date (in UTC) or is
 even
     * younger. */
    static boolean checkTimestampTooRecent(String timestampParameter) {
 -    return timestampParameter.compareTo(ZonedDateTime.now(ZoneOffset.UTC)
 -        .toLocalDate().minusDays(1).toString()) >= 0;
 +    return LocalDate.parse(timestampParameter,
 DateTimeFormatter.ISO_LOCAL_DATE)
 +        .isAfter(LocalDate.now(ZoneOffset.UTC).minusDays(2));
    }

    /* Helper method for fetching a query response via URL. */
 }}}

 Actually, this would be a perfect time to introduce java 8 date time
 classes throughout this servlet; avoiding the mixture of parsing methods
 and most likely reducing the number of lines (' checkTimestampTooRecent'
 could actually be avoided with the use of `isAfter` etc.), and also making
 the code also more readable.

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


More information about the metrics-bugs mailing list