[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/master] Reset sorted fingerprint blocks when setting fingerprint.
commit 54ef1a7e34659ab7941b7c2d769fd7a8d851d1a6
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Tue Jul 19 10:22:15 2016 +0200
Reset sorted fingerprint blocks when setting fingerprint.
Previously, we'd only have calculated sorted fingerprint blocks once,
but not after setting a new fingerprint. We never ran into this bug,
because we never called that setter outside of the constructor. But
future uses of that setter would have caused trouble.
Found while writing Javadoc comments for #19613.
---
.../torproject/onionoo/docs/SummaryDocument.java | 1 +
.../onionoo/docs/SummaryDocumentTest.java | 26 ++++++++++++++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java b/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java
index 6a520c8..c7d4774 100644
--- a/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java
@@ -44,6 +44,7 @@ public class SummaryDocument extends Document {
this.f = fingerprint;
this.hashedFingerprint = null;
this.base64Fingerprint = null;
+ this.fingerprintSortedHexBlocks = null;
}
public String getFingerprint() {
diff --git a/src/test/java/org/torproject/onionoo/docs/SummaryDocumentTest.java b/src/test/java/org/torproject/onionoo/docs/SummaryDocumentTest.java
index 3c097ae..99ae0c5 100644
--- a/src/test/java/org/torproject/onionoo/docs/SummaryDocumentTest.java
+++ b/src/test/java/org/torproject/onionoo/docs/SummaryDocumentTest.java
@@ -1,7 +1,8 @@
-/* Copyright 2015 The Tor Project
+/* Copyright 2015--2016 The Tor Project
* See LICENSE for licensing information */
package org.torproject.onionoo.docs;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@@ -11,9 +12,8 @@ import java.util.TreeSet;
public class SummaryDocumentTest {
- @Test()
- public void testFingerprintSortedHexBlocksAreSorted() {
- SummaryDocument relayTorkaZ = new SummaryDocument(true, "TorkaZ",
+ private SummaryDocument createSummaryDocumentRelayTorkaZ() {
+ return new SummaryDocument(true, "TorkaZ",
"000C5F55BD4814B917CC474BD537F1A3B33CCE2A", Arrays.asList(
new String[] { "62.216.201.221", "62.216.201.222",
"62.216.201.223" }), DateTimeHelper.parse("2013-04-19 05:00:00"),
@@ -26,6 +26,11 @@ public class SummaryDocumentTest {
"0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B" })),
new TreeSet<String>(Arrays.asList(
new String[] { "001C13B3A55A71B977CA65EC85539D79C653A3FC" })));
+ }
+
+ @Test()
+ public void testFingerprintSortedHexBlocksAreSorted() {
+ SummaryDocument relayTorkaZ = this.createSummaryDocumentRelayTorkaZ();
String[] fingerprintSortedHexBlocks =
relayTorkaZ.getFingerprintSortedHexBlocks();
for (int i = 0; i < fingerprintSortedHexBlocks.length - 1; i++) {
@@ -34,5 +39,18 @@ public class SummaryDocumentTest {
fingerprintSortedHexBlocks[i + 1]) <= 0);
}
}
+
+ @Test()
+ public void testFingerprintSortedHexBlocksReset() {
+ SummaryDocument relayTorkaZ = this.createSummaryDocumentRelayTorkaZ();
+ assertArrayEquals("Hex blocks differ", new String[] { "000C", "14B9",
+ "17CC", "474B", "5F55", "B33C", "BD48", "CE2A", "D537", "F1A3" },
+ relayTorkaZ.getFingerprintSortedHexBlocks());
+ relayTorkaZ.setFingerprint(
+ "A2ECC33B3A1F735D8474CC719B4184DB55F5C000");
+ assertArrayEquals("Hex blocks differ", new String[] { "3A1F", "55F5",
+ "735D", "8474", "84DB", "9B41", "A2EC", "C000", "C33B", "CC71" },
+ relayTorkaZ.getFingerprintSortedHexBlocks());
+ }
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits