[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/release] Remove 604 checkstyle complaints.
commit c3079ae2ecbed0994273b7986e3cf19160f55153
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Wed Jan 25 11:27:09 2017 +0100
Remove 604 checkstyle complaints.
Resolves #21144.
---
.../descriptor/DescriptorSourceFactory.java | 3 +-
.../descriptor/impl/DescriptorReaderImpl.java | 3 +-
.../descriptor/DescriptorSourceFactoryTest.java | 82 ++---
.../descriptor/DummyCollectorImplementation.java | 15 +
.../descriptor/DummyDownloaderImplementation.java | 15 +
.../descriptor/DummyParserImplementation.java | 15 +
.../descriptor/DummyReaderImplementation.java | 15 +
.../descriptor/benchmark/MeasurePerformance.java | 22 +-
.../descriptor/impl/BridgeNetworkStatusTest.java | 24 +-
.../descriptor/impl/ConsensusBuilder.java | 55 +++-
.../impl/DescriptorCollectorImplTest.java | 5 +-
.../descriptor/impl/DescriptorReaderImplTest.java | 1 +
.../descriptor/impl/ExitListImplTest.java | 10 +-
.../impl/ExtraInfoDescriptorImplTest.java | 231 ++++++++++----
.../descriptor/impl/MicrodescriptorImplTest.java | 16 +-
.../impl/RelayNetworkStatusConsensusImplTest.java | 97 ++++--
.../impl/RelayNetworkStatusImplTest.java | 47 ++-
.../impl/RelayNetworkStatusVoteImplTest.java | 111 +++++--
.../descriptor/impl/ServerDescriptorImplTest.java | 338 ++++++++++++---------
.../descriptor/impl/TorperfResultImplTest.java | 10 +-
20 files changed, 772 insertions(+), 343 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
index efdc5cf..77d8740 100644
--- a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
+++ b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
@@ -34,7 +34,8 @@ import org.slf4j.LoggerFactory;
* descriptor downloader:</p>
*
* <p><code>
- * java -Ddescriptor.downloader=my.special.descriptorimpl.Downloader my.app.Mainclass
+ * java -Ddescriptor.downloader=my.special.descriptorimpl.Downloader \
+ * my.app.Mainclass
* </code></p>
*
* @since 1.0.0
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java
index 2cbb6c8..cb14588 100644
--- a/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java
@@ -36,7 +36,8 @@ import java.util.TreeMap;
public class DescriptorReaderImpl implements DescriptorReader {
- private static Logger log = LoggerFactory.getLogger(DescriptorReaderImpl.class);
+ private static Logger log = LoggerFactory.getLogger(
+ DescriptorReaderImpl.class);
private boolean hasStartedReading = false;
private List<File> directories = new ArrayList<>();
diff --git a/src/test/java/org/torproject/descriptor/DescriptorSourceFactoryTest.java b/src/test/java/org/torproject/descriptor/DescriptorSourceFactoryTest.java
index d8990ac..9e0b5ff 100644
--- a/src/test/java/org/torproject/descriptor/DescriptorSourceFactoryTest.java
+++ b/src/test/java/org/torproject/descriptor/DescriptorSourceFactoryTest.java
@@ -1,42 +1,46 @@
/* Copyright 2016--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor;
-import static org.torproject.descriptor.DescriptorSourceFactory.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.torproject.descriptor.DescriptorSourceFactory.COLLECTOR_DEFAULT;
+import static org.torproject.descriptor.DescriptorSourceFactory.COLLECTOR_PROPERTY;
+import static org.torproject.descriptor.DescriptorSourceFactory.DOWNLOADER_DEFAULT;
+import static org.torproject.descriptor.DescriptorSourceFactory.DOWNLOADER_PROPERTY;
+import static org.torproject.descriptor.DescriptorSourceFactory.PARSER_DEFAULT;
+import static org.torproject.descriptor.DescriptorSourceFactory.PARSER_PROPERTY;
+import static org.torproject.descriptor.DescriptorSourceFactory.READER_DEFAULT;
+import static org.torproject.descriptor.DescriptorSourceFactory.READER_PROPERTY;
-import org.torproject.descriptor.DescriptorCollector;
-import org.torproject.descriptor.DescriptorDownloader;
-import org.torproject.descriptor.DescriptorParser;
-import org.torproject.descriptor.DescriptorReader;
-import org.torproject.descriptor.ImplementationNotAccessibleException;
import org.torproject.descriptor.impl.DescriptorDownloaderImpl;
import org.torproject.descriptor.impl.DescriptorParserImpl;
import org.torproject.descriptor.impl.DescriptorReaderImpl;
import org.torproject.descriptor.index.DescriptorIndexCollector;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import org.junit.Test;
-import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
public class DescriptorSourceFactoryTest {
- private final static String[] properties = new String[]{
- COLLECTOR_PROPERTY, DOWNLOADER_PROPERTY, PARSER_PROPERTY, READER_PROPERTY};
- private final static String[] defaults = new String[]{
- COLLECTOR_DEFAULT, DOWNLOADER_DEFAULT, PARSER_DEFAULT, READER_DEFAULT};
+ private static final String[] properties = new String[] { COLLECTOR_PROPERTY,
+ DOWNLOADER_PROPERTY, PARSER_PROPERTY, READER_PROPERTY };
+
+ private static final String[] defaults = new String[] { COLLECTOR_DEFAULT,
+ DOWNLOADER_DEFAULT, PARSER_DEFAULT, READER_DEFAULT };
@Test()
public void testDefaults() {
setProperties(defaults);
- DescriptorCollector dc = DescriptorSourceFactory.createDescriptorCollector();
+ DescriptorCollector dc =
+ DescriptorSourceFactory.createDescriptorCollector();
assertTrue(dc instanceof DescriptorIndexCollector);
- DescriptorDownloader dd = DescriptorSourceFactory.createDescriptorDownloader();
+ DescriptorDownloader dd =
+ DescriptorSourceFactory.createDescriptorDownloader();
assertTrue(dd instanceof DescriptorDownloaderImpl);
DescriptorParser dp = DescriptorSourceFactory.createDescriptorParser();
assertTrue(dp instanceof DescriptorParserImpl);
@@ -66,7 +70,7 @@ public class DescriptorSourceFactoryTest {
retrieve.setAccessible(true);
retrieve.invoke(null, "unknown.property");
} catch (InvocationTargetException ite) {
- if(ite.getCause() instanceof ImplementationNotAccessibleException) {
+ if (ite.getCause() instanceof ImplementationNotAccessibleException) {
return;
} else {
fail("Cause was " + ite.getCause()
@@ -79,16 +83,17 @@ public class DescriptorSourceFactoryTest {
@Test()
public void testProperties() {
- setProperties(new String[]{
+ setProperties(new String[] {
"org.torproject.descriptor.DummyCollectorImplementation",
"org.torproject.descriptor.DummyDownloaderImplementation",
"org.torproject.descriptor.DummyParserImplementation",
- "org.torproject.descriptor.DummyReaderImplementation",
- });
- DescriptorCollector dc = DescriptorSourceFactory.createDescriptorCollector();
+ "org.torproject.descriptor.DummyReaderImplementation" });
+ DescriptorCollector dc =
+ DescriptorSourceFactory.createDescriptorCollector();
assertTrue(dc instanceof DummyCollectorImplementation);
assertEquals(1, DummyCollectorImplementation.count);
- DescriptorDownloader dd = DescriptorSourceFactory.createDescriptorDownloader();
+ DescriptorDownloader dd =
+ DescriptorSourceFactory.createDescriptorDownloader();
assertTrue(dd instanceof DummyDownloaderImplementation);
assertEquals(1, DummyDownloaderImplementation.count);
DescriptorParser dp = DescriptorSourceFactory.createDescriptorParser();
@@ -98,33 +103,4 @@ public class DescriptorSourceFactoryTest {
assertTrue(dr instanceof DummyReaderImplementation);
assertEquals(1, DummyReaderImplementation.count);
}
-
-}
-
-class DummyCollectorImplementation extends DescriptorIndexCollector {
- static int count;
- public DummyCollectorImplementation() {
- count++;
- }
-}
-
-class DummyDownloaderImplementation extends DescriptorDownloaderImpl {
- static int count;
- public DummyDownloaderImplementation() {
- count++;
- }
-}
-
-class DummyParserImplementation extends DescriptorParserImpl {
- static int count;
- public DummyParserImplementation() {
- count++;
- }
-}
-
-class DummyReaderImplementation extends DescriptorReaderImpl {
- static int count;
- public DummyReaderImplementation() {
- count++;
- }
}
diff --git a/src/test/java/org/torproject/descriptor/DummyCollectorImplementation.java b/src/test/java/org/torproject/descriptor/DummyCollectorImplementation.java
new file mode 100644
index 0000000..130a718
--- /dev/null
+++ b/src/test/java/org/torproject/descriptor/DummyCollectorImplementation.java
@@ -0,0 +1,15 @@
+/* Copyright 2016--2017 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.descriptor;
+
+import org.torproject.descriptor.index.DescriptorIndexCollector;
+
+class DummyCollectorImplementation extends DescriptorIndexCollector {
+
+ static int count;
+
+ public DummyCollectorImplementation() {
+ count++;
+ }
+}
diff --git a/src/test/java/org/torproject/descriptor/DummyDownloaderImplementation.java b/src/test/java/org/torproject/descriptor/DummyDownloaderImplementation.java
new file mode 100644
index 0000000..dce3372
--- /dev/null
+++ b/src/test/java/org/torproject/descriptor/DummyDownloaderImplementation.java
@@ -0,0 +1,15 @@
+/* Copyright 2016--2017 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.descriptor;
+
+import org.torproject.descriptor.impl.DescriptorDownloaderImpl;
+
+class DummyDownloaderImplementation extends DescriptorDownloaderImpl {
+
+ static int count;
+
+ public DummyDownloaderImplementation() {
+ count++;
+ }
+}
diff --git a/src/test/java/org/torproject/descriptor/DummyParserImplementation.java b/src/test/java/org/torproject/descriptor/DummyParserImplementation.java
new file mode 100644
index 0000000..42e67c9
--- /dev/null
+++ b/src/test/java/org/torproject/descriptor/DummyParserImplementation.java
@@ -0,0 +1,15 @@
+/* Copyright 2016--2017 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.descriptor;
+
+import org.torproject.descriptor.impl.DescriptorParserImpl;
+
+class DummyParserImplementation extends DescriptorParserImpl {
+
+ static int count;
+
+ public DummyParserImplementation() {
+ count++;
+ }
+}
diff --git a/src/test/java/org/torproject/descriptor/DummyReaderImplementation.java b/src/test/java/org/torproject/descriptor/DummyReaderImplementation.java
new file mode 100644
index 0000000..8f74337
--- /dev/null
+++ b/src/test/java/org/torproject/descriptor/DummyReaderImplementation.java
@@ -0,0 +1,15 @@
+/* Copyright 2016--2017 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.descriptor;
+
+import org.torproject.descriptor.impl.DescriptorReaderImpl;
+
+class DummyReaderImplementation extends DescriptorReaderImpl {
+
+ static int count;
+
+ public DummyReaderImplementation() {
+ count++;
+ }
+}
diff --git a/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java b/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java
index 4c36ae4..a0c923c 100644
--- a/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java
+++ b/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java
@@ -1,5 +1,6 @@
/* Copyright 2016--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.benchmark;
import org.torproject.descriptor.Descriptor;
@@ -20,7 +21,7 @@ import java.util.SortedMap;
public class MeasurePerformance {
- /* Check if all necessary files are available and then measure
+ /** Check if all necessary files are available and then measure
* performance of some more or less common use cases. */
public static void main(String[] args) {
if (!filesAvailable()) {
@@ -88,8 +89,9 @@ public class MeasurePerformance {
private static void measureAverageAdvertisedBandwidth(
File tarballFileOrDirectory) {
System.out.println("Starting measureAverageAdvertisedBandwidth");
- long startedMillis = System.currentTimeMillis();
- long sumAdvertisedBandwidth = 0, countedServerDescriptors = 0;
+ final long startedMillis = System.currentTimeMillis();
+ long sumAdvertisedBandwidth = 0;
+ long countedServerDescriptors = 0;
DescriptorReader descriptorReader =
DescriptorSourceFactory.createDescriptorReader();
descriptorReader.addTarball(tarballFileOrDirectory);
@@ -125,7 +127,7 @@ public class MeasurePerformance {
private static void measureCountriesV3Requests(File tarballFile) {
System.out.println("Starting measureCountriesV3Requests");
- long startedMillis = System.currentTimeMillis();
+ final long startedMillis = System.currentTimeMillis();
Set<String> countries = new HashSet<>();
long countedExtraInfoDescriptors = 0;
DescriptorReader descriptorReader =
@@ -165,9 +167,10 @@ public class MeasurePerformance {
private static void measureAverageRelaysExit(
File tarballFileOrDirectory) {
System.out.println("Starting measureAverageRelaysExit");
- long startedMillis = System.currentTimeMillis();
- long totalRelaysWithExitFlag = 0L, totalRelays = 0L,
- countedConsensuses = 0L;
+ final long startedMillis = System.currentTimeMillis();
+ long totalRelaysWithExitFlag = 0L;
+ long totalRelays = 0L;
+ long countedConsensuses = 0L;
DescriptorReader descriptorReader =
DescriptorSourceFactory.createDescriptorReader();
descriptorReader.addTarball(tarballFileOrDirectory);
@@ -212,8 +215,9 @@ public class MeasurePerformance {
File tarballFile) {
System.out.println("Starting "
+ "measureFractionRelaysExit80Microdescriptors");
- long startedMillis = System.currentTimeMillis();
- long totalRelaysWithExitFlag = 0L, countedMicrodescriptors = 0L;
+ final long startedMillis = System.currentTimeMillis();
+ long totalRelaysWithExitFlag = 0L;
+ long countedMicrodescriptors = 0L;
DescriptorReader descriptorReader =
DescriptorSourceFactory.createDescriptorReader();
descriptorReader.addTarball(tarballFile);
diff --git a/src/test/java/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java b/src/test/java/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
index d1a083e..8720d7b 100644
--- a/src/test/java/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
@@ -1,17 +1,19 @@
/* Copyright 2015--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
import org.torproject.descriptor.BridgeNetworkStatus;
import org.torproject.descriptor.DescriptorParseException;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
/* Test parsing of bridge network statuses. Some of the parsing code is
* already tested in the consensus/vote-parsing tests. */
public class BridgeNetworkStatusTest {
@@ -19,8 +21,10 @@ public class BridgeNetworkStatusTest {
/* Helper class to build a bridge network status based on default data
* and modifications requested by test methods. */
private static class StatusBuilder {
+
private String fileName = "20151121-173936-"
+ "4A0CCD2DDC7995083D73F5D667100C8A5831F16D";
+
private static BridgeNetworkStatus
createWithFileName(String fileName)
throws DescriptorParseException {
@@ -29,7 +33,9 @@ public class BridgeNetworkStatusTest {
return new BridgeNetworkStatusImpl(sb.buildStatus(), sb.fileName,
true);
}
+
private String publishedLine = "published 2015-11-21 17:39:36";
+
private static BridgeNetworkStatus
createWithPublishedLine(String line)
throws DescriptorParseException {
@@ -38,11 +44,13 @@ public class BridgeNetworkStatusTest {
return new BridgeNetworkStatusImpl(sb.buildStatus(), sb.fileName,
true);
}
+
private String flagThresholdsLine = "flag-thresholds "
+ "stable-uptime=3105080 stable-mtbf=2450615 fast-speed=55000 "
+ "guard-wfu=98.000% guard-tk=691200 guard-bw-inc-exits=337000 "
+ "guard-bw-exc-exits=339000 enough-mtbf=1 "
+ "ignoring-advertised-bws=0";
+
private static BridgeNetworkStatus
createWithFlagThresholdsLine(String line)
throws DescriptorParseException {
@@ -51,8 +59,11 @@ public class BridgeNetworkStatusTest {
return new BridgeNetworkStatusImpl(sb.buildStatus(), sb.fileName,
true);
}
+
private List<String> statusEntries = new ArrayList<>();
+
private String unrecognizedHeaderLine = null;
+
protected static BridgeNetworkStatus
createWithUnrecognizedHeaderLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -62,7 +73,9 @@ public class BridgeNetworkStatusTest {
return new BridgeNetworkStatusImpl(sb.buildStatus(), sb.fileName,
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedStatusEntryLine = null;
+
protected static BridgeNetworkStatus
createWithUnrecognizedStatusEntryLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -79,12 +92,14 @@ public class BridgeNetworkStatusTest {
+ "10.153.163.200 443 0\ns Fast Running Stable Valid\n"
+ "w Bandwidth=264\np reject 1-65535");
}
+
private byte[] buildStatus() {
StringBuilder sb = new StringBuilder();
this.appendHeader(sb);
this.appendStatusEntries(sb);
return sb.toString().getBytes();
}
+
private void appendHeader(StringBuilder sb) {
if (this.publishedLine != null) {
sb.append(this.publishedLine).append("\n");
@@ -96,6 +111,7 @@ public class BridgeNetworkStatusTest {
sb.append(this.unrecognizedHeaderLine).append("\n");
}
}
+
private void appendStatusEntries(StringBuilder sb) {
for (String statusEntry : this.statusEntries) {
sb.append(statusEntry).append("\n");
diff --git a/src/test/java/org/torproject/descriptor/impl/ConsensusBuilder.java b/src/test/java/org/torproject/descriptor/impl/ConsensusBuilder.java
index fccd33b..b765be6 100644
--- a/src/test/java/org/torproject/descriptor/impl/ConsensusBuilder.java
+++ b/src/test/java/org/torproject/descriptor/impl/ConsensusBuilder.java
@@ -1,17 +1,20 @@
/* Copyright 2012--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.RelayNetworkStatusConsensus;
+
import java.util.ArrayList;
import java.util.List;
-import org.torproject.descriptor.RelayNetworkStatusConsensus;
-
/* Helper class to build a consensus based on default data and
* modifications requested by test methods. */
public class ConsensusBuilder {
+
String networkStatusVersionLine = "network-status-version 3";
+
protected static RelayNetworkStatusConsensus
createWithNetworkStatusVersionLine(String line)
throws DescriptorParseException {
@@ -19,7 +22,9 @@ public class ConsensusBuilder {
cb.networkStatusVersionLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String voteStatusLine = "vote-status consensus";
+
protected static RelayNetworkStatusConsensus
createWithVoteStatusLine(String line)
throws DescriptorParseException {
@@ -27,7 +32,9 @@ public class ConsensusBuilder {
cb.voteStatusLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String consensusMethodLine = "consensus-method 11";
+
protected static RelayNetworkStatusConsensus
createWithConsensusMethodLine(String line)
throws DescriptorParseException {
@@ -35,7 +42,9 @@ public class ConsensusBuilder {
cb.consensusMethodLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String validAfterLine = "valid-after 2011-11-30 09:00:00";
+
protected static RelayNetworkStatusConsensus
createWithValidAfterLine(String line)
throws DescriptorParseException {
@@ -43,7 +52,9 @@ public class ConsensusBuilder {
cb.validAfterLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String freshUntilLine = "fresh-until 2011-11-30 10:00:00";
+
protected static RelayNetworkStatusConsensus
createWithFreshUntilLine(String line)
throws DescriptorParseException {
@@ -51,7 +62,9 @@ public class ConsensusBuilder {
cb.freshUntilLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String validUntilLine = "valid-until 2011-11-30 12:00:00";
+
protected static RelayNetworkStatusConsensus
createWithValidUntilLine(String line)
throws DescriptorParseException {
@@ -59,7 +72,9 @@ public class ConsensusBuilder {
cb.validUntilLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String votingDelayLine = "voting-delay 300 300";
+
protected static RelayNetworkStatusConsensus
createWithVotingDelayLine(String line)
throws DescriptorParseException {
@@ -67,8 +82,10 @@ public class ConsensusBuilder {
cb.votingDelayLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
String clientVersionsLine = "client-versions 0.2.1.31,"
+ "0.2.2.34,0.2.3.6-alpha,0.2.3.7-alpha,0.2.3.8-alpha";
+
protected static RelayNetworkStatusConsensus
createWithClientVersionsLine(String line)
throws DescriptorParseException {
@@ -76,8 +93,10 @@ public class ConsensusBuilder {
cb.clientVersionsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
String serverVersionsLine = "server-versions 0.2.1.31,"
+ "0.2.2.34,0.2.3.6-alpha,0.2.3.7-alpha,0.2.3.8-alpha";
+
protected static RelayNetworkStatusConsensus
createWithServerVersionsLine(String line)
throws DescriptorParseException {
@@ -85,7 +104,9 @@ public class ConsensusBuilder {
cb.serverVersionsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String packageLines = null;
+
protected static RelayNetworkStatusConsensus
createWithPackageLines(String lines)
throws DescriptorParseException {
@@ -93,8 +114,10 @@ public class ConsensusBuilder {
cb.packageLines = lines;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String knownFlagsLine = "known-flags Authority BadExit Exit "
+ "Fast Guard HSDir Named Running Stable Unnamed V2Dir Valid";
+
protected static RelayNetworkStatusConsensus
createWithKnownFlagsLine(String line)
throws DescriptorParseException {
@@ -102,11 +125,13 @@ public class ConsensusBuilder {
cb.knownFlagsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String paramsLine = "params "
+ "CircuitPriorityHalflifeMsec=30000 bwauthbestratio=1 "
+ "bwauthcircs=1 bwauthdescbw=0 bwauthkp=10000 bwauthpid=1 "
+ "bwauthtd=5000 bwauthti=50000 bwauthtidecay=5000 cbtnummodes=3 "
+ "cbtquantile=80 circwindow=1000 refuseunknownexits=1";
+
protected static RelayNetworkStatusConsensus
createWithParamsLine(String line)
throws DescriptorParseException {
@@ -114,12 +139,17 @@ public class ConsensusBuilder {
cb.paramsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
List<String> dirSources = new ArrayList<>();
+
List<String> statusEntries = new ArrayList<>();
+
private String directoryFooterLine = "directory-footer";
+
protected void setDirectoryFooterLine(String line) {
this.directoryFooterLine = line;
}
+
protected static RelayNetworkStatusConsensus
createWithDirectoryFooterLine(String line)
throws DescriptorParseException {
@@ -127,13 +157,16 @@ public class ConsensusBuilder {
cb.directoryFooterLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String bandwidthWeightsLine = "bandwidth-weights Wbd=285 "
+ "Wbe=0 Wbg=0 Wbm=10000 Wdb=10000 Web=10000 Wed=1021 Wee=10000 "
+ "Weg=1021 Wem=10000 Wgb=10000 Wgd=8694 Wgg=10000 Wgm=10000 "
+ "Wmb=10000 Wmd=285 Wme=0 Wmg=0 Wmm=10000";
+
protected void setBandwidthWeightsLine(String line) {
this.bandwidthWeightsLine = line;
}
+
protected static RelayNetworkStatusConsensus
createWithBandwidthWeightsLine(String line)
throws DescriptorParseException {
@@ -141,11 +174,15 @@ public class ConsensusBuilder {
cb.bandwidthWeightsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private List<String> directorySignatures = new ArrayList<>();
+
protected void addDirectorySignature(String directorySignatureString) {
this.directorySignatures.add(directorySignatureString);
}
+
private String unrecognizedHeaderLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedHeaderLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -155,7 +192,9 @@ public class ConsensusBuilder {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedDirSourceLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedDirSourceLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -165,7 +204,9 @@ public class ConsensusBuilder {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedStatusEntryLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedStatusEntryLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -175,7 +216,9 @@ public class ConsensusBuilder {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedFooterLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedFooterLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -185,7 +228,9 @@ public class ConsensusBuilder {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedDirectorySignatureLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedDirectorySignatureLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -232,6 +277,7 @@ public class ConsensusBuilder {
+ "oQA/qeby7E\n5374pPPL6WwCLJHkKtk21S9oHDmFBdlZq7JWQelWlVM=\n"
+ "-----END SIGNATURE-----");
}
+
protected byte[] buildConsensus() {
StringBuilder sb = new StringBuilder();
this.appendHeader(sb);
@@ -241,6 +287,7 @@ public class ConsensusBuilder {
this.appendDirectorySignatures(sb);
return sb.toString().getBytes();
}
+
private void appendHeader(StringBuilder sb) {
if (this.networkStatusVersionLine != null) {
sb.append(this.networkStatusVersionLine).append("\n");
@@ -282,6 +329,7 @@ public class ConsensusBuilder {
sb.append(this.unrecognizedHeaderLine).append("\n");
}
}
+
private void appendDirSources(StringBuilder sb) {
for (String dirSource : this.dirSources) {
sb.append(dirSource).append("\n");
@@ -290,6 +338,7 @@ public class ConsensusBuilder {
sb.append(this.unrecognizedDirSourceLine).append("\n");
}
}
+
private void appendStatusEntries(StringBuilder sb) {
for (String statusEntry : this.statusEntries) {
sb.append(statusEntry).append("\n");
@@ -298,6 +347,7 @@ public class ConsensusBuilder {
sb.append(this.unrecognizedStatusEntryLine).append("\n");
}
}
+
private void appendFooter(StringBuilder sb) {
if (this.directoryFooterLine != null) {
sb.append(this.directoryFooterLine).append("\n");
@@ -309,6 +359,7 @@ public class ConsensusBuilder {
sb.append(this.unrecognizedFooterLine).append("\n");
}
}
+
private void appendDirectorySignatures(StringBuilder sb) {
for (String directorySignature : this.directorySignatures) {
sb.append(directorySignature).append("\n");
diff --git a/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java b/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java
index ad34528..45752b2 100644
--- a/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java
@@ -1,5 +1,6 @@
/* Copyright 2015--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
@@ -8,10 +9,10 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import java.util.SortedMap;
-
import org.junit.Test;
+import java.util.SortedMap;
+
public class DescriptorCollectorImplTest {
private static final String REMOTE_DIRECTORY_CONSENSUSES =
diff --git a/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java b/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java
index 5a418b9..0d3bdcf 100644
--- a/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java
@@ -1,5 +1,6 @@
/* Copyright 2016--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
diff --git a/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java b/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java
index 8bc81f9..916c4df 100644
--- a/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java
@@ -1,17 +1,19 @@
/* Copyright 2015--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.ExitListEntry;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
public class ExitListImplTest {
@Test()
diff --git a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
index fb38c86..096314e 100644
--- a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
@@ -1,5 +1,6 @@
/* Copyright 2012--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
@@ -7,6 +8,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import org.torproject.descriptor.BridgeExtraInfoDescriptor;
+import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.ExtraInfoDescriptor;
+import org.torproject.descriptor.RelayExtraInfoDescriptor;
+
+import org.junit.Test;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -14,138 +22,166 @@ import java.util.List;
import java.util.Map;
import java.util.SortedMap;
-import org.junit.Test;
-import org.torproject.descriptor.BridgeExtraInfoDescriptor;
-import org.torproject.descriptor.DescriptorParseException;
-import org.torproject.descriptor.ExtraInfoDescriptor;
-import org.torproject.descriptor.RelayExtraInfoDescriptor;
-
/* Test parsing of extra-info descriptors. */
public class ExtraInfoDescriptorImplTest {
/* Helper class to build a descriptor based on default data and
* modifications requested by test methods. */
private static class DescriptorBuilder {
+
private String extraInfoLine = "extra-info chaoscomputerclub5 "
+ "A9C039A5FD02FCA06303DCFAABE25C5912C63B26";
+
private static ExtraInfoDescriptor createWithExtraInfoLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.extraInfoLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String publishedLine = "published 2012-02-11 09:08:36";
+
private static ExtraInfoDescriptor createWithPublishedLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.publishedLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String writeHistoryLine = "write-history 2012-02-11 09:03:39 "
+ "(900 s) 4713350144,4723824640,4710717440,4572675072";
+
private static ExtraInfoDescriptor createWithWriteHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.writeHistoryLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String readHistoryLine = "read-history 2012-02-11 09:03:39 "
+ "(900 s) 4707695616,4699666432,4650004480,4489718784";
+
private static ExtraInfoDescriptor createWithReadHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.readHistoryLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String dirreqWriteHistoryLine = "dirreq-write-history "
+ "2012-02-11 09:03:39 (900 s) 81281024,64996352,60625920,"
+ "67922944";
+
private static ExtraInfoDescriptor createWithDirreqWriteHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.dirreqWriteHistoryLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String dirreqReadHistoryLine = "dirreq-read-history "
+ "2012-02-11 09:03:39 (900 s) 17074176,16235520,16005120,"
+ "16209920";
+
private static ExtraInfoDescriptor createWithDirreqReadHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.dirreqReadHistoryLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String geoipDbDigestLine = null;
+
private static ExtraInfoDescriptor createWithGeoipDbDigestLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.geoipDbDigestLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String geoip6DbDigestLine = null;
+
private static ExtraInfoDescriptor createWithGeoip6DbDigestLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.geoip6DbDigestLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String geoipStatsLines = null;
+
private static ExtraInfoDescriptor createWithGeoipStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.geoipStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String dirreqStatsLines = null;
+
private static ExtraInfoDescriptor createWithDirreqStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.dirreqStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String entryStatsLines = null;
+
private static ExtraInfoDescriptor createWithEntryStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.entryStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String cellStatsLines = null;
+
private static ExtraInfoDescriptor createWithCellStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.cellStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String connBiDirectLine = null;
+
private static ExtraInfoDescriptor createWithConnBiDirectLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.connBiDirectLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String exitStatsLines = null;
+
private static ExtraInfoDescriptor createWithExitStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.exitStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String bridgeStatsLines = null;
+
private static ExtraInfoDescriptor createWithBridgeStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.bridgeStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String hidservStatsLines = null;
+
private static ExtraInfoDescriptor createWithHidservStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.hidservStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String unrecognizedLine = null;
+
private static ExtraInfoDescriptor createWithUnrecognizedLine(
String line, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
@@ -154,7 +190,9 @@ public class ExtraInfoDescriptorImplTest {
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(),
failUnrecognizedDescriptorLines);
}
+
private byte[] nonAsciiLineBytes = null;
+
private static ExtraInfoDescriptor createWithNonAsciiLineBytes(
byte[] lineBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
@@ -163,20 +201,27 @@ public class ExtraInfoDescriptorImplTest {
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(),
failUnrecognizedDescriptorLines);
}
+
private String routerSignatureLines = "router-signature\n"
+ "-----BEGIN SIGNATURE-----\n"
+ "o4j+kH8UQfjBwepUnr99v0ebN8RpzHJ/lqYsTojXHy9kMr1RNI9IDeSzA7PSqT"
+ "uV\n4PL8QsGtlfwthtIoZpB2srZeyN/mcpA9fa1JXUrt/UN9K/+32Cyaad7h0n"
+ "HE6Xfb\njqpXDpnBpvk4zjmzjjKYnIsUWTnADmu0fo3xTRqXi7g=\n"
+ "-----END SIGNATURE-----";
+
private static ExtraInfoDescriptor createWithRouterSignatureLines(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.routerSignatureLines = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
- private String identityEd25519Lines = null,
- masterKeyEd25519Line = null, routerSigEd25519Line = null;
+
+ private String identityEd25519Lines = null;
+
+ private String masterKeyEd25519Line = null;
+
+ private String routerSigEd25519Line = null;
+
private static ExtraInfoDescriptor createWithEd25519Lines(
String identityEd25519Lines, String masterKeyEd25519Line,
String routerSigEd25519Line) throws DescriptorParseException {
@@ -186,6 +231,7 @@ public class ExtraInfoDescriptorImplTest {
db.routerSigEd25519Line = routerSigEd25519Line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private byte[] buildDescriptor() {
StringBuilder sb = new StringBuilder();
if (this.extraInfoLine != null) {
@@ -272,8 +318,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of geoip-stats lines based on default
* data and modifications requested by test methods. */
private static class GeoipStatsBuilder {
+
private String geoipStartTimeLine = "geoip-start-time 2012-02-10 "
+ "18:32:51";
+
private static ExtraInfoDescriptor createWithGeoipStartTimeLine(
String line) throws DescriptorParseException {
GeoipStatsBuilder gsb = new GeoipStatsBuilder();
@@ -281,8 +329,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithGeoipStatsLines(
gsb.buildGeoipStatsLines());
}
+
private String geoipClientOriginsLine = "geoip-client-origins "
+ "de=1152,cn=896,us=712,it=504,ru=352,fr=208,gb=208,ir=200";
+
private static ExtraInfoDescriptor createWithGeoipClientOriginsLine(
String line) throws DescriptorParseException {
GeoipStatsBuilder gsb = new GeoipStatsBuilder();
@@ -290,11 +340,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithGeoipStatsLines(
gsb.buildGeoipStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithGeoipStatsLines(
new GeoipStatsBuilder().buildGeoipStatsLines());
}
+
private String buildGeoipStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.geoipStartTimeLine != null) {
@@ -314,8 +366,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of dirreq-stats lines based on default
* data and modifications requested by test methods. */
private static class DirreqStatsBuilder {
+
private String dirreqStatsEndLine = "dirreq-stats-end 2012-02-11 "
+ "00:59:53 (86400 s)";
+
private static ExtraInfoDescriptor createWithDirreqStatsEndLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -323,8 +377,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3IpsLine = "dirreq-v3-ips us=1544,de=1056,"
+ "it=1032,fr=784,es=640,ru=440,br=312,gb=272,kr=224,sy=192";
+
private static ExtraInfoDescriptor createWithDirreqV3IpsLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -332,7 +388,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2IpsLine = "dirreq-v2-ips ";
+
private static ExtraInfoDescriptor createWithDirreqV2IpsLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -340,8 +398,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3ReqsLine = "dirreq-v3-reqs us=1744,de=1224,"
+ "it=1080,fr=832,es=664,ru=536,br=344,gb=296,kr=272,in=216";
+
private static ExtraInfoDescriptor createWithDirreqV3ReqsLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -349,7 +409,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2ReqsLine = "dirreq-v2-reqs ";
+
private static ExtraInfoDescriptor createWithDirreqV2ReqsLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -357,9 +419,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3RespLine = "dirreq-v3-resp ok=10848,"
+ "not-enough-sigs=8,unavailable=0,not-found=0,not-modified=0,"
+ "busy=80";
+
private static ExtraInfoDescriptor createWithDirreqV3RespLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -367,8 +431,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2RespLine = "dirreq-v2-resp ok=0,unavailable=0,"
+ "not-found=1576,not-modified=0,busy=0";
+
private static ExtraInfoDescriptor createWithDirreqV2RespLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -376,7 +442,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2ShareLine = "dirreq-v2-share 0.37%";
+
private static ExtraInfoDescriptor createWithDirreqV2ShareLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -384,7 +452,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3ShareLine = "dirreq-v3-share 0.37%";
+
private static ExtraInfoDescriptor createWithDirreqV3ShareLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -392,10 +462,12 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3DirectDlLine = "dirreq-v3-direct-dl "
+ "complete=36,timeout=4,running=0,min=7538,d1=20224,d2=28950,"
+ "q1=40969,d3=55786,d4=145813,md=199164,d6=267230,d7=480900,"
+ "q3=481049,d8=531276,d9=778086,max=15079428";
+
private static ExtraInfoDescriptor createWithDirreqV3DirectDlLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -403,8 +475,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2DirectDlLine = "dirreq-v2-direct-dl "
+ "complete=0,timeout=0,running=0";
+
private static ExtraInfoDescriptor createWithDirreqV2DirectDlLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -412,10 +486,12 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3TunneledDlLine = "dirreq-v3-tunneled-dl "
+ "complete=10608,timeout=204,running=4,min=507,d1=20399,"
+ "d2=27588,q1=29292,d3=30889,d4=40624,md=59967,d6=103333,"
+ "d7=161170,q3=209415,d8=256711,d9=452503,max=23417777";
+
private static ExtraInfoDescriptor createWithDirreqV3TunneledDlLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -423,8 +499,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2TunneledDlLine = "dirreq-v2-tunneled-dl "
+ "complete=0,timeout=0,running=0";
+
private static ExtraInfoDescriptor createWithDirreqV2TunneledDlLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -432,11 +510,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithDirreqStatsLines(
new DirreqStatsBuilder().buildDirreqStatsLines());
}
+
private String buildDirreqStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.dirreqStatsEndLine != null) {
@@ -489,8 +569,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of entry-stats lines based on default
* data and modifications requested by test methods. */
private static class EntryStatsBuilder {
+
private String entryStatsEndLine = "entry-stats-end 2012-02-11 "
+ "01:59:39 (86400 s)";
+
private static ExtraInfoDescriptor createWithEntryStatsEndLine(
String line) throws DescriptorParseException {
EntryStatsBuilder esb = new EntryStatsBuilder();
@@ -498,9 +580,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithEntryStatsLines(
esb.buildEntryStatsLines());
}
+
private String entryIpsLine = "entry-ips ir=25368,us=15744,it=14816,"
+ "de=13256,es=8280,fr=8120,br=5176,sy=4760,ru=4504,sa=4216,"
+ "gb=3152,pl=2928,nl=2208,kr=1856,ca=1792,ua=1272,in=1192";
+
private static ExtraInfoDescriptor createWithEntryIpsLine(
String line) throws DescriptorParseException {
EntryStatsBuilder esb = new EntryStatsBuilder();
@@ -508,11 +592,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithEntryStatsLines(
esb.buildEntryStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithEntryStatsLines(
new EntryStatsBuilder().buildEntryStatsLines());
}
+
private String buildEntryStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.entryStatsEndLine != null) {
@@ -532,8 +618,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of cell-stats lines based on default
* data and modifications requested by test methods. */
private static class CellStatsBuilder {
+
private String cellStatsEndLine = "cell-stats-end 2012-02-11 "
+ "01:59:39 (86400 s)";
+
private static ExtraInfoDescriptor createWithCellStatsEndLine(
String line) throws DescriptorParseException {
CellStatsBuilder csb = new CellStatsBuilder();
@@ -541,8 +629,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private String cellProcessedCellsLine = "cell-processed-cells "
+ "1441,11,6,4,2,1,1,1,1,1";
+
private static ExtraInfoDescriptor createWithCellProcessedCellsLine(
String line) throws DescriptorParseException {
CellStatsBuilder csb = new CellStatsBuilder();
@@ -550,8 +640,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private String cellQueuedCellsLine = "cell-queued-cells "
+ "3.29,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
+
private static ExtraInfoDescriptor createWithCellQueuedCellsLine(
String line) throws DescriptorParseException {
CellStatsBuilder csb = new CellStatsBuilder();
@@ -559,8 +651,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private String cellTimeInQueueLine = "cell-time-in-queue "
+ "524,1,1,0,0,25,0,0,0,0";
+
private static ExtraInfoDescriptor createWithCellTimeInQueueLine(
String line) throws DescriptorParseException {
CellStatsBuilder csb = new CellStatsBuilder();
@@ -568,8 +662,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private String cellCircuitsPerDecileLine = "cell-circuits-per-decile "
+ "866";
+
private static ExtraInfoDescriptor
createWithCellCircuitsPerDecileLine(String line)
throws DescriptorParseException {
@@ -578,11 +674,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithCellStatsLines(
new CellStatsBuilder().buildCellStatsLines());
}
+
private String buildCellStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.cellStatsEndLine != null) {
@@ -611,8 +709,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of exit-stats lines based on default
* data and modifications requested by test methods. */
private static class ExitStatsBuilder {
+
private String exitStatsEndLine = "exit-stats-end 2012-02-11 "
+ "01:59:39 (86400 s)";
+
private static ExtraInfoDescriptor createWithExitStatsEndLine(
String line) throws DescriptorParseException {
ExitStatsBuilder esb = new ExitStatsBuilder();
@@ -620,9 +720,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithExitStatsLines(
esb.buildExitStatsLines());
}
+
private String exitKibibytesWrittenLine = "exit-kibibytes-written "
+ "25=74647,80=31370,443=20577,49755=23,52563=12,52596=1111,"
+ "57528=4,60912=11,61351=6,64811=3365,other=2592";
+
private static ExtraInfoDescriptor createWithExitKibibytesWrittenLine(
String line) throws DescriptorParseException {
ExitStatsBuilder esb = new ExitStatsBuilder();
@@ -630,10 +732,12 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithExitStatsLines(
esb.buildExitStatsLines());
}
+
private String exitKibibytesReadLine = "exit-kibibytes-read "
+ "25=35562,80=1254256,443=110279,49755=9396,52563=1911,"
+ "52596=648,57528=1188,60912=1427,61351=1824,64811=14,"
+ "other=3054";
+
private static ExtraInfoDescriptor createWithExitKibibytesReadLine(
String line) throws DescriptorParseException {
ExitStatsBuilder esb = new ExitStatsBuilder();
@@ -641,9 +745,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithExitStatsLines(
esb.buildExitStatsLines());
}
+
private String exitStreamsOpenedLine = "exit-streams-opened "
+ "25=369748,80=64212,443=151660,49755=4,52563=4,52596=4,57528=4,"
+ "60912=4,61351=4,64811=4,other=1212";
+
private static ExtraInfoDescriptor createWithExitStreamsOpenedLine(
String line) throws DescriptorParseException {
ExitStatsBuilder esb = new ExitStatsBuilder();
@@ -651,11 +757,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithExitStatsLines(
esb.buildExitStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithExitStatsLines(
new ExitStatsBuilder().buildExitStatsLines());
}
+
private String buildExitStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.exitStatsEndLine != null) {
@@ -681,8 +789,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of bridge-stats lines based on default
* data and modifications requested by test methods. */
private static class BridgeStatsBuilder {
+
private String bridgeStatsEndLine = "bridge-stats-end 2012-02-11 "
+ "01:59:39 (86400 s)";
+
private static ExtraInfoDescriptor createWithBridgeStatsEndLine(
String line) throws DescriptorParseException {
BridgeStatsBuilder bsb = new BridgeStatsBuilder();
@@ -690,8 +800,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithBridgeStatsLines(
bsb.buildBridgeStatsLines());
}
+
private String bridgeIpsLine = "bridge-ips ir=24,sy=16,??=8,cn=8,"
+ "de=8,es=8,fr=8,gb=8,in=8,jp=8,kz=8,nl=8,ua=8,us=8,vn=8,za=8";
+
private static ExtraInfoDescriptor createWithBridgeIpsLine(
String line) throws DescriptorParseException {
BridgeStatsBuilder bsb = new BridgeStatsBuilder();
@@ -699,7 +811,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithBridgeStatsLines(
bsb.buildBridgeStatsLines());
}
+
private String bridgeIpVersionsLine = "bridge-ip-versions v4=8,v6=16";
+
private static ExtraInfoDescriptor createWithBridgeIpVersionsLine(
String line) throws DescriptorParseException {
BridgeStatsBuilder bsb = new BridgeStatsBuilder();
@@ -707,8 +821,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithBridgeStatsLines(
bsb.buildBridgeStatsLines());
}
+
private String bridgeIpTransportsLine = "bridge-ip-transports "
+ "<OR>=8,obfs2=792,obfs3=1728";
+
private static ExtraInfoDescriptor createWithBridgeIpTransportsLine(
String line) throws DescriptorParseException {
BridgeStatsBuilder bsb = new BridgeStatsBuilder();
@@ -716,11 +832,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithBridgeStatsLines(
bsb.buildBridgeStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithBridgeStatsLines(
new BridgeStatsBuilder().buildBridgeStatsLines());
}
+
private String buildBridgeStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.bridgeStatsEndLine != null) {
@@ -746,8 +864,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of hidserv-stats lines based on default
* data and modifications requested by test methods. */
private static class HidservStatsBuilder {
+
private String hidservStatsEndLine = "hidserv-stats-end 2015-12-03 "
+ "14:26:56 (86400 s)";
+
private static ExtraInfoDescriptor createWithHidservStatsEndLine(
String line) throws DescriptorParseException {
HidservStatsBuilder hsb = new HidservStatsBuilder();
@@ -755,9 +875,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithHidservStatsLines(
hsb.buildHidservStatsLines());
}
+
private String hidservRendRelayedCellsLine =
"hidserv-rend-relayed-cells 36474281 delta_f=2048 epsilon=0.30 "
+ "bin_size=1024";
+
private static ExtraInfoDescriptor
createWithHidservRendRelayedCellsLine(String line)
throws DescriptorParseException {
@@ -766,8 +888,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithHidservStatsLines(
hsb.buildHidservStatsLines());
}
+
private String hidservDirOnionsSeenLine = "hidserv-dir-onions-seen "
+ "-3 delta_f=8 epsilon=0.30 bin_size=8";
+
private static ExtraInfoDescriptor createWithHidservDirOnionsSeenLine(
String line) throws DescriptorParseException {
HidservStatsBuilder hsb = new HidservStatsBuilder();
@@ -775,11 +899,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithHidservStatsLines(
hsb.buildHidservStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithHidservStatsLines(
new HidservStatsBuilder().buildHidservStatsLines());
}
+
private String buildHidservStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.hidservStatsEndLine != null) {
@@ -809,11 +935,11 @@ public class ExtraInfoDescriptorImplTest {
descriptor.getFingerprint());
assertEquals(1328951316000L, descriptor.getPublishedMillis());
assertNotNull(descriptor.getWriteHistory());
- assertEquals(1328951019000L, descriptor.getWriteHistory().
- getHistoryEndMillis());
+ assertEquals(1328951019000L, descriptor.getWriteHistory()
+ .getHistoryEndMillis());
assertEquals(900L, descriptor.getWriteHistory().getIntervalLength());
- assertEquals(4572675072L, (long) descriptor.getWriteHistory().
- getBandwidthValues().get(1328951019000L));
+ assertEquals(4572675072L, (long) descriptor.getWriteHistory()
+ .getBandwidthValues().get(1328951019000L));
assertNotNull(descriptor.getReadHistory());
assertNotNull(descriptor.getDirreqWriteHistory());
assertNotNull(descriptor.getDirreqReadHistory());
@@ -826,8 +952,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testExtraInfoOpt() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoLine("opt extra-info chaoscomputerclub5 "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoLine("opt extra-info chaoscomputerclub5 "
+ "A9C039A5FD02FCA06303DCFAABE25C5912C63B26");
assertEquals("chaoscomputerclub5", descriptor.getNickname());
assertEquals("A9C039A5FD02FCA06303DCFAABE25C5912C63B26",
@@ -837,8 +963,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testExtraInfoNicknameTwoSpaces()
throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoLine("opt extra-info chaoscomputerclub5 "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoLine("opt extra-info chaoscomputerclub5 "
+ "A9C039A5FD02FCA06303DCFAABE25C5912C63B26");
assertEquals("chaoscomputerclub5", descriptor.getNickname());
assertEquals("A9C039A5FD02FCA06303DCFAABE25C5912C63B26",
@@ -899,15 +1025,15 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testPublishedOpt() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithPublishedLine("opt published 2012-02-11 09:08:36");
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithPublishedLine("opt published 2012-02-11 09:08:36");
assertEquals(1328951316000L, descriptor.getPublishedMillis());
}
@Test()
public void testPublishedMillis() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithPublishedLine("opt published 2012-02-11 09:08:36.123");
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithPublishedLine("opt published 2012-02-11 09:08:36.123");
assertEquals(1328951316000L, descriptor.getPublishedMillis());
}
@@ -977,8 +1103,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testGeoipDbDigestValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithGeoipDbDigestLine("geoip-db-digest "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithGeoipDbDigestLine("geoip-db-digest "
+ "916A3CA8B7DF61473D5AE5B21711F35F301CE9E8");
assertEquals("916A3CA8B7DF61473D5AE5B21711F35F301CE9E8",
descriptor.getGeoipDbDigest());
@@ -1006,8 +1132,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testGeoip6DbDigestValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithGeoip6DbDigestLine("geoip6-db-digest "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithGeoip6DbDigestLine("geoip6-db-digest "
+ "916A3CA8B7DF61473D5AE5B21711F35F301CE9E8");
assertEquals("916A3CA8B7DF61473D5AE5B21711F35F301CE9E8",
descriptor.getGeoip6DbDigest());
@@ -1015,8 +1141,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testGeoipStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = GeoipStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = GeoipStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328898771000L, descriptor.getGeoipStartTimeMillis());
SortedMap<String, Integer> ips = descriptor.getGeoipClientOrigins();
assertNotNull(ips);
@@ -1117,8 +1243,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testDirreqStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DirreqStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = DirreqStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328921993000L, descriptor.getDirreqStatsEndMillis());
assertEquals(86400L, descriptor.getDirreqStatsIntervalLength());
SortedMap<String, Integer> ips = descriptor.getDirreqV3Ips();
@@ -1237,8 +1363,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testEntryStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = EntryStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = EntryStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328925579000L, descriptor.getEntryStatsEndMillis());
assertEquals(86400L, descriptor.getEntryStatsIntervalLength());
SortedMap<String, Integer> ips = descriptor.getEntryIps();
@@ -1262,8 +1388,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testCellStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = CellStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = CellStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328925579000L, descriptor.getCellStatsEndMillis());
assertEquals(86400L, descriptor.getCellStatsIntervalLength());
List<Integer> processedCells = descriptor.getCellProcessedCells();
@@ -1319,8 +1445,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testConnBiDirectValid()
throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithConnBiDirectLine("conn-bi-direct 2012-02-11 01:59:39 "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithConnBiDirectLine("conn-bi-direct 2012-02-11 01:59:39 "
+ "(86400 s) 42173,1591,1310,1744");
assertEquals(1328925579000L,
descriptor.getConnBiDirectStatsEndMillis());
@@ -1340,35 +1466,35 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testExitStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = ExitStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = ExitStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328925579000L, descriptor.getExitStatsEndMillis());
assertEquals(86400L, descriptor.getExitStatsIntervalLength());
String[] ports = new String[] { "25", "80", "443", "49755",
"52563", "52596", "57528", "60912", "61351", "64811", "other" };
int[] writtenValues = new int[] { 74647, 31370, 20577, 23, 12, 1111,
4, 11, 6, 3365, 2592 };
- int i = 0;
+ int index = 0;
for (Map.Entry<String, Long> e :
descriptor.getExitKibibytesWritten().entrySet()) {
- assertEquals(ports[i], e.getKey());
- assertEquals(writtenValues[i++], e.getValue().intValue());
+ assertEquals(ports[index], e.getKey());
+ assertEquals(writtenValues[index++], e.getValue().intValue());
}
int[] readValues = new int[] { 35562, 1254256, 110279, 9396, 1911,
648, 1188, 1427, 1824, 14, 3054 };
- i = 0;
+ index = 0;
for (Map.Entry<String, Long> e :
descriptor.getExitKibibytesRead().entrySet()) {
- assertEquals(ports[i], e.getKey());
- assertEquals(readValues[i++], e.getValue().intValue());
+ assertEquals(ports[index], e.getKey());
+ assertEquals(readValues[index++], e.getValue().intValue());
}
int[] streamsValues = new int[] { 369748, 64212, 151660, 4, 4, 4, 4,
4, 4, 4, 1212 };
- i = 0;
+ index = 0;
for (Map.Entry<String, Long> e :
descriptor.getExitStreamsOpened().entrySet()) {
- assertEquals(ports[i], e.getKey());
- assertEquals(streamsValues[i++], e.getValue().intValue());
+ assertEquals(ports[index], e.getKey());
+ assertEquals(streamsValues[index++], e.getValue().intValue());
}
}
@@ -1416,8 +1542,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testBridgeStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = BridgeStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = BridgeStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328925579000L, descriptor.getBridgeStatsEndMillis());
assertEquals(86400L, descriptor.getBridgeStatsIntervalLength());
SortedMap<String, Integer> ips = descriptor.getBridgeIps();
@@ -1482,8 +1608,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testHidservStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = HidservStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = HidservStatsBuilder
+ .createWithDefaultLines();
assertEquals(1449152816000L, descriptor.getHidservStatsEndMillis());
assertEquals(86400L, descriptor.getHidservStatsIntervalLength());
assertEquals(36474281.0, descriptor.getHidservRendRelayedCells(),
@@ -1575,8 +1701,8 @@ public class ExtraInfoDescriptorImplTest {
public void testUnrecognizedLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithUnrecognizedLine(unrecognizedLine, false);
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithUnrecognizedLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
@@ -1727,7 +1853,8 @@ public class ExtraInfoDescriptorImplTest {
+ "geoip6-db-digest 212DE17D5A368DCAFA19B95F168BFFA101145A93\n"
+ "router-digest-sha256 "
+ "TvrqpjI7OmCtwGwair/NHUxg5ROVVQYz6/EDyXsDHR4\n"
- + "router-digest 00B98F076B586272C3172B7F3DA29ADEE75F2ED8\n").getBytes();
+ + "router-digest 00B98F076B586272C3172B7F3DA29ADEE75F2ED8\n")
+ .getBytes();
BridgeExtraInfoDescriptor descriptor =
new BridgeExtraInfoDescriptorImpl(descriptorBytes, true);
assertEquals("TvrqpjI7OmCtwGwair/NHUxg5ROVVQYz6/EDyXsDHR4",
diff --git a/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
index abb51db..20b0849 100644
--- a/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
@@ -1,20 +1,19 @@
+/* Copyright 2015--2017 The Tor Project
+ * See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
-import org.junit.Test;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.Microdescriptor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import org.junit.Test;
public class MicrodescriptorImplTest {
/* Helper class to build a microdescriptor based on default data and
* modifications requested by test methods. */
private static class DescriptorBuilder {
+
private String onionKeyLines = "onion-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIGJAoGBALNZ4pNsHHkl7a+kFWbBmPHNAepjjvuhjTr1TaMB3UKuCRaXJmS2Qr"
@@ -22,20 +21,25 @@ public class MicrodescriptorImplTest {
+ "UutXaZ\nfkyty5XOgV4Qucx9wokzTMCHlO0V0x9y0FwFsK5Nb6ugqfQLLQ6XAg"
+ "MBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static Microdescriptor createWithDefaultLines()
throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
return new MicrodescriptorImpl(db.buildDescriptor(), true);
}
+
private String ntorOnionKeyLine =
"ntor-onion-key PXLa7IGE+TzPDMsM5j9rFnDa37rd6kfZa5QuzqqJukw=";
+
private String idLine = "id rsa1024 bvegfGxp8k7T9QFpjPTrPaJTa/8";
+
private static Microdescriptor createWithIdLine(String line)
throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.idLine = line;
return new MicrodescriptorImpl(db.buildDescriptor(), true);
}
+
private byte[] buildDescriptor() {
StringBuilder sb = new StringBuilder();
if (this.onionKeyLines != null) {
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
index 57a2d89..ebcbd83 100644
--- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
@@ -1,9 +1,7 @@
/* Copyright 2011--2017 The Tor Project
* See LICENSE for licensing information */
-package org.torproject.descriptor.impl;
-import org.torproject.descriptor.DescriptorParseException;
-import org.torproject.descriptor.DirectorySignature;
+package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -11,15 +9,17 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.DirectorySignature;
+import org.torproject.descriptor.NetworkStatusEntry;
+import org.torproject.descriptor.RelayNetworkStatusConsensus;
+
+import org.junit.Test;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
-import org.junit.Test;
-import org.torproject.descriptor.NetworkStatusEntry;
-import org.torproject.descriptor.RelayNetworkStatusConsensus;
-
/* TODO Add test cases for all lines starting with "opt ". */
/* Test parsing of network status consensuses. The main focus is on
@@ -31,6 +31,7 @@ public class RelayNetworkStatusConsensusImplTest {
/* Helper class to build a directory source based on default data and
* modifications requested by test methods. */
private static class DirSourceBuilder {
+
private static RelayNetworkStatusConsensus
createWithDirSource(String dirSourceString)
throws DescriptorParseException {
@@ -39,7 +40,9 @@ public class RelayNetworkStatusConsensusImplTest {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
true);
}
+
private String nickname = "gabelmoo";
+
private static RelayNetworkStatusConsensus
createWithNickname(String string)
throws DescriptorParseException {
@@ -47,7 +50,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.nickname = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String identity = "ED03BB616EB2F60BEC80151114BB25CEF515B226";
+
private static RelayNetworkStatusConsensus
createWithIdentity(String string)
throws DescriptorParseException {
@@ -55,7 +60,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.identity = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String hostName = "212.112.245.170";
+
private static RelayNetworkStatusConsensus
createWithHostName(String string)
throws DescriptorParseException {
@@ -63,7 +70,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.hostName = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String address = "212.112.245.170";
+
private static RelayNetworkStatusConsensus
createWithAddress(String string)
throws DescriptorParseException {
@@ -71,7 +80,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.address = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String dirPort = "80";
+
private static RelayNetworkStatusConsensus
createWithDirPort(String string)
throws DescriptorParseException {
@@ -79,7 +90,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.dirPort = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String orPort = "443";
+
private static RelayNetworkStatusConsensus
createWithOrPort(String string)
throws DescriptorParseException {
@@ -87,8 +100,10 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.orPort = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String contactLine = "contact 4096R/C5AA446D Sebastian Hahn "
+ "<tor@xxxxxxxxxxxxxxxxx>";
+
private static RelayNetworkStatusConsensus
createWithContactLine(String line)
throws DescriptorParseException {
@@ -96,8 +111,10 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.contactLine = line;
return createWithDirSource(dsb.buildDirSource());
}
+
private String voteDigestLine =
"vote-digest 0F398A5834D2C139E1D92310B09F814F243354D1";
+
private static RelayNetworkStatusConsensus
createWithVoteDigestLine(String line)
throws DescriptorParseException {
@@ -105,6 +122,7 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.voteDigestLine = line;
return createWithDirSource(dsb.buildDirSource());
}
+
private String buildDirSource() {
StringBuilder sb = new StringBuilder();
String dirSourceLine = "dir-source " + this.nickname + " "
@@ -127,6 +145,7 @@ public class RelayNetworkStatusConsensusImplTest {
/* Helper class to build a status entry based on default data and
* modifications requested by test methods. */
private static class StatusEntryBuilder {
+
private static RelayNetworkStatusConsensus
createWithStatusEntry(String statusEntryString)
throws DescriptorParseException {
@@ -135,7 +154,9 @@ public class RelayNetworkStatusConsensusImplTest {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
true);
}
+
private String nickname = "right2privassy3";
+
private static RelayNetworkStatusConsensus
createWithNickname(String string)
throws DescriptorParseException {
@@ -143,7 +164,9 @@ public class RelayNetworkStatusConsensusImplTest {
seb.nickname = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String fingerprintBase64 = "ADQ6gCT3DiFHKPDFr3rODBUI8HM";
+
private static RelayNetworkStatusConsensus
createWithFingerprintBase64(String string)
throws DescriptorParseException {
@@ -151,7 +174,9 @@ public class RelayNetworkStatusConsensusImplTest {
seb.fingerprintBase64 = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String descriptorBase64 = "Yiti+nayuT2Efe2X1+M4nslwVuU";
+
private static RelayNetworkStatusConsensus
createWithDescriptorBase64(String string)
throws DescriptorParseException {
@@ -159,7 +184,9 @@ public class RelayNetworkStatusConsensusImplTest {
seb.descriptorBase64 = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String publishedString = "2011-11-29 21:34:27";
+
private static RelayNetworkStatusConsensus
createWithPublishedString(String string)
throws DescriptorParseException {
@@ -167,55 +194,75 @@ public class RelayNetworkStatusConsensusImplTest {
seb.publishedString = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String address = "50.63.8.215";
+
private static RelayNetworkStatusConsensus
createWithAddress(String string) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.address = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String orPort = "9023";
+
private static RelayNetworkStatusConsensus
createWithOrPort(String string) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.orPort = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String dirPort = "0";
+
private static RelayNetworkStatusConsensus
createWithDirPort(String string) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.dirPort = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:membername")
private String sLine = "s Exit Fast Named Running Stable Valid";
+
private static RelayNetworkStatusConsensus
createWithSLine(String line) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.sLine = line;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:membername")
private String vLine = "v Tor 0.2.1.29 (r8e9b25e6c7a2e70c)";
+
private static RelayNetworkStatusConsensus
createWithVLine(String line) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.vLine = line;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:membername")
private String wLine = "w Bandwidth=1";
+
private static RelayNetworkStatusConsensus
createWithWLine(String line) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.wLine = line;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:membername")
private String pLine = "p accept 80,1194,1220,1293";
+
private static RelayNetworkStatusConsensus
createWithPLine(String line) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.pLine = line;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:localvariablename")
private String buildStatusEntry() {
StringBuilder sb = new StringBuilder();
String rLine = "r " + nickname + " " + fingerprintBase64 + " "
@@ -244,6 +291,7 @@ public class RelayNetworkStatusConsensusImplTest {
/* Helper class to build a directory signature based on default data and
* modifications requested by test methods. */
private static class DirectorySignatureBuilder {
+
private static RelayNetworkStatusConsensus
createWithDirectorySignature(String directorySignatureString)
throws DescriptorParseException {
@@ -252,7 +300,9 @@ public class RelayNetworkStatusConsensusImplTest {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
true);
}
+
private String identity = "ED03BB616EB2F60BEC80151114BB25CEF515B226";
+
private static RelayNetworkStatusConsensus
createWithIdentity(String string)
throws DescriptorParseException {
@@ -260,8 +310,10 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.identity = string;
return createWithDirectorySignature(dsb.buildDirectorySignature());
}
+
private String signingKey =
"845CF1D0B370CA443A8579D18E7987E7E532F639";
+
private static RelayNetworkStatusConsensus
createWithSigningKey(String string)
throws DescriptorParseException {
@@ -269,6 +321,7 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.signingKey = string;
return createWithDirectorySignature(dsb.buildDirectorySignature());
}
+
private String buildDirectorySignature() {
String directorySignature = "directory-signature " + identity + " "
+ signingKey + "\n"
@@ -1093,16 +1146,16 @@ public class RelayNetworkStatusConsensusImplTest {
@Test()
public void testBandwidthWeightsLineNoSpace()
throws DescriptorParseException {
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithBandwidthWeightsLine("bandwidth-weights");
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithBandwidthWeightsLine("bandwidth-weights");
assertNotNull(consensus.getBandwidthWeights());
}
@Test()
public void testBandwidthWeightsLineOneSpace()
throws DescriptorParseException {
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithBandwidthWeightsLine("bandwidth-weights ");
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithBandwidthWeightsLine("bandwidth-weights ");
assertNotNull(consensus.getBandwidthWeights());
}
@@ -1185,8 +1238,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedHeaderLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedHeaderLine(unrecognizedLine, false);
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedHeaderLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
@@ -1204,8 +1257,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedDirSourceLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
@@ -1223,8 +1276,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedStatusEntryLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedStatusEntryLine(unrecognizedLine, false);
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedStatusEntryLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
@@ -1242,8 +1295,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedDirectoryFooterLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedFooterLine(unrecognizedLine, false);
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedFooterLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
@@ -1261,8 +1314,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedDirectorySignatureLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedDirectorySignatureLine(unrecognizedLine,
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedDirectorySignatureLine(unrecognizedLine,
false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
index 8f4ece2..d550d26 100644
--- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
@@ -1,37 +1,31 @@
/* Copyright 2016--2017 The Tor Project
* See LICENSE for licensing information */
-package org.torproject.descriptor.impl;
-import org.torproject.descriptor.DescriptorParseException;
+package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import org.torproject.descriptor.DescriptorParseException;
import org.junit.Test;
-import org.torproject.descriptor.RelayNetworkStatus;
public class RelayNetworkStatusImplTest {
- private final static String validHeader = "network-status-version 2\n"
- + "dir-source 194.109.206.212 194.109.206.212 80\n"
- + "fingerprint 7EA6EAD6FD83083C538F44038BBFA077587DD755\n"
- + "contact 1024R/8D56913D Alex de Joode <adejoode@xxxxxxxxxxxx>\n"
- + "published 2012-03-01 00:10:43\n"
- + "dir-options\n"
- + "dir-signing-key\n"
- + "-----BEGIN RSA PUBLIC KEY-----\n"
- + "MIGJAoGBAL7QJ6cmXhMlexV97ehnV5hn5ePOeo0sbDYXhlfw52CheEycoUqSD9Y/\n"
- + "3qEo0Rm7XTEol0dRW34ca1LMIXGM4B4whXxBKCRRYe1RY6nF70zb2EUuaHWEWc+f\n"
- + "c6JWYUWZSPpW1uyjyLPUI/ikyyH7zmtR4MfhSeNdt2zSakojYNaPAgMBAAE=\n"
- + "-----END RSA PUBLIC KEY-----\n";
-
- private final static String validStatus =
- "@type network-status-2 1.0\n" + validHeader;
+ private static final String validHeader = "network-status-version 2\n"
+ + "dir-source 194.109.206.212 194.109.206.212 80\n"
+ + "fingerprint 7EA6EAD6FD83083C538F44038BBFA077587DD755\n"
+ + "contact 1024R/8D56913D Alex de Joode <adejoode@xxxxxxxxxxxx>\n"
+ + "published 2012-03-01 00:10:43\n"
+ + "dir-options\n"
+ + "dir-signing-key\n"
+ + "-----BEGIN RSA PUBLIC KEY-----\n"
+ + "MIGJAoGBAL7QJ6cmXhMlexV97ehnV5hn5ePOeo0sbDYXhlfw52CheEycoUqSD9Y/\n"
+ + "3qEo0Rm7XTEol0dRW34ca1LMIXGM4B4whXxBKCRRYe1RY6nF70zb2EUuaHWEWc+f\n"
+ + "c6JWYUWZSPpW1uyjyLPUI/ikyyH7zmtR4MfhSeNdt2zSakojYNaPAgMBAAE=\n"
+ + "-----END RSA PUBLIC KEY-----\n";
+
+ private static final String validStatus =
+ "@type network-status-2 1.0\n" + validHeader;
@Test(expected = DescriptorParseException.class)
public void testParseBrokenHeader() throws DescriptorParseException {
@@ -42,12 +36,11 @@ public class RelayNetworkStatusImplTest {
@Test()
public void testValidHeader() throws DescriptorParseException {
- RelayNetworkStatusImpl rnsi
- = new RelayNetworkStatusImpl(validStatus.getBytes(), true);
+ RelayNetworkStatusImpl rnsi =
+ new RelayNetworkStatusImpl(validStatus.getBytes(), true);
rnsi.parseHeader(validHeader.getBytes());
assertEquals(rnsi.getContactLine(),
- "1024R/8D56913D Alex de Joode <adejoode@xxxxxxxxxxxx>");
+ "1024R/8D56913D Alex de Joode <adejoode@xxxxxxxxxxxx>");
}
-
}
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
index 79cb78c..847c538 100644
--- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
@@ -1,21 +1,22 @@
/* Copyright 2011--2017 The Tor Project
* See LICENSE for licensing information */
-package org.torproject.descriptor.impl;
-import org.torproject.descriptor.DescriptorParseException;
-import org.torproject.descriptor.DirectorySignature;
+package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.DirectorySignature;
+import org.torproject.descriptor.RelayNetworkStatusVote;
+
+import org.junit.Test;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.junit.Test;
-import org.torproject.descriptor.RelayNetworkStatusVote;
-
/* TODO Add test cases for all lines starting with "opt ". */
/* Test parsing of network status votes. Some of the vote-parsing code is
@@ -27,7 +28,9 @@ public class RelayNetworkStatusVoteImplTest {
/* Helper class to build a vote based on default data and modifications
* requested by test methods. */
private static class VoteBuilder {
+
private String networkStatusVersionLine = "network-status-version 3";
+
private static RelayNetworkStatusVote
createWithNetworkStatusVersionLine(String line)
throws DescriptorParseException {
@@ -35,7 +38,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.networkStatusVersionLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String voteStatusLine = "vote-status vote";
+
private static RelayNetworkStatusVote
createWithVoteStatusLine(String line)
throws DescriptorParseException {
@@ -43,8 +48,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.voteStatusLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String consensusMethodsLine =
"consensus-methods 1 2 3 4 5 6 7 8 9 10 11";
+
private static RelayNetworkStatusVote
createWithConsensusMethodsLine(String line)
throws DescriptorParseException {
@@ -52,7 +59,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.consensusMethodsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String publishedLine = "published 2011-11-30 08:50:01";
+
private static RelayNetworkStatusVote
createWithPublishedLine(String line)
throws DescriptorParseException {
@@ -60,7 +69,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.publishedLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String validAfterLine = "valid-after 2011-11-30 09:00:00";
+
private static RelayNetworkStatusVote
createWithValidAfterLine(String line)
throws DescriptorParseException {
@@ -68,7 +79,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.validAfterLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String freshUntilLine = "fresh-until 2011-11-30 10:00:00";
+
private static RelayNetworkStatusVote
createWithFreshUntilLine(String line)
throws DescriptorParseException {
@@ -76,7 +89,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.freshUntilLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String validUntilLine = "valid-until 2011-11-30 12:00:00";
+
private static RelayNetworkStatusVote
createWithValidUntilLine(String line)
throws DescriptorParseException {
@@ -84,7 +99,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.validUntilLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String votingDelayLine = "voting-delay 300 300";
+
private static RelayNetworkStatusVote
createWithVotingDelayLine(String line)
throws DescriptorParseException {
@@ -92,8 +109,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.votingDelayLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String clientVersionsLine = "client-versions 0.2.1.31,"
+ "0.2.2.34,0.2.3.6-alpha,0.2.3.7-alpha,0.2.3.8-alpha";
+
private static RelayNetworkStatusVote
createWithClientVersionsLine(String line)
throws DescriptorParseException {
@@ -101,8 +120,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.clientVersionsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String serverVersionsLine = "server-versions 0.2.1.31,"
+ "0.2.2.34,0.2.3.6-alpha,0.2.3.7-alpha,0.2.3.8-alpha";
+
private static RelayNetworkStatusVote
createWithServerVersionsLine(String line)
throws DescriptorParseException {
@@ -110,7 +131,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.serverVersionsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String packageLines = null;
+
protected static RelayNetworkStatusVote
createWithPackageLines(String lines)
throws DescriptorParseException {
@@ -118,8 +141,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.packageLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String knownFlagsLine = "known-flags Authority BadExit Exit "
+ "Fast Guard HSDir Named Running Stable Unnamed V2Dir Valid";
+
private static RelayNetworkStatusVote
createWithKnownFlagsLine(String line)
throws DescriptorParseException {
@@ -127,10 +152,12 @@ public class RelayNetworkStatusVoteImplTest {
vb.knownFlagsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String flagThresholdsLine = "flag-thresholds "
+ "stable-uptime=693369 stable-mtbf=153249 fast-speed=40960 "
+ "guard-wfu=94.669% guard-tk=691200 guard-bw-inc-exits=174080 "
+ "guard-bw-exc-exits=184320 enough-mtbf=1";
+
private static RelayNetworkStatusVote
createWithFlagThresholdsLine(String line)
throws DescriptorParseException {
@@ -138,11 +165,13 @@ public class RelayNetworkStatusVoteImplTest {
vb.flagThresholdsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String paramsLine = "params "
+ "CircuitPriorityHalflifeMsec=30000 bwauthbestratio=1 "
+ "bwauthcircs=1 bwauthdescbw=0 bwauthkp=10000 bwauthpid=1 "
+ "bwauthtd=5000 bwauthti=50000 bwauthtidecay=5000 cbtnummodes=3 "
+ "cbtquantile=80 circwindow=1000 refuseunknownexits=1";
+
private static RelayNetworkStatusVote
createWithParamsLine(String line)
throws DescriptorParseException {
@@ -150,9 +179,11 @@ public class RelayNetworkStatusVoteImplTest {
vb.paramsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirSourceLine = "dir-source urras "
+ "80550987E1D626E3EBA5E5E75A458DE0626D088C 208.83.223.34 "
+ "208.83.223.34 443 80";
+
private static RelayNetworkStatusVote
createWithDirSourceLine(String line)
throws DescriptorParseException {
@@ -160,8 +191,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirSourceLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String contactLine = "contact 4096R/E012B42D Jacob Appelbaum "
+ "<jacob@xxxxxxxxxxxxx>";
+
private static RelayNetworkStatusVote
createWithContactLine(String line)
throws DescriptorParseException {
@@ -169,7 +202,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.contactLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String legacyDirKeyLine = null;
+
private static RelayNetworkStatusVote
createWithLegacyDirKeyLine(String line)
throws DescriptorParseException {
@@ -177,8 +212,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.legacyDirKeyLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyCertificateVersionLine =
"dir-key-certificate-version 3";
+
private static RelayNetworkStatusVote
createWithDirKeyCertificateVersionLine(String line)
throws DescriptorParseException {
@@ -186,8 +223,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyCertificateVersionLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String fingerprintLine = "fingerprint "
+ "80550987E1D626E3EBA5E5E75A458DE0626D088C";
+
private static RelayNetworkStatusVote
createWithFingerprintLine(String line)
throws DescriptorParseException {
@@ -195,8 +234,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.fingerprintLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyPublishedLine = "dir-key-published 2011-04-27 "
+ "05:34:37";
+
private static RelayNetworkStatusVote
createWithDirKeyPublishedLine(String line)
throws DescriptorParseException {
@@ -204,8 +245,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyPublishedLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyExpiresLine = "dir-key-expires 2012-04-27 "
+ "05:34:37";
+
private static RelayNetworkStatusVote
createWithDirKeyExpiresLine(String line)
throws DescriptorParseException {
@@ -213,6 +256,7 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyExpiresLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirIdentityKeyLines = "dir-identity-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIIBigKCAYEAtKpuLgVK25sfScjsxfVU1ljofrDygt9GP7bNJl/rghX42KUT97"
@@ -225,6 +269,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "TvcaKz9CEj4XcKm+kOmzejYmIa\nkbWNcRpXPiUZ+xmwGtsq30xrzqiONmERkx"
+ "qlmf7bVQPFvh3Kz6hGcmTBhTbHSe9h\nzDgmdaTNn3EHAgMBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static RelayNetworkStatusVote
createWithDirIdentityKeyLines(String lines)
throws DescriptorParseException {
@@ -232,6 +277,7 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirIdentityKeyLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirSigningKeyLines = "dir-signing-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIGJAoGBAN05qyHFQlTqykMP8yLuD4G2UuYulD4Xs8iSX5uqF+WGsUA1E4zZh4"
@@ -239,6 +285,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "mBGsN7\nPUXyMNjwRKL6UvrcbYk1d2mRBLO7SAP/sFW5fHhIBVeLIWrzQ19rAg"
+ "MBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static RelayNetworkStatusVote
createWithDirSigningKeyLines(String lines)
throws DescriptorParseException {
@@ -246,12 +293,14 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirSigningKeyLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyCrosscertLines = "dir-key-crosscert\n"
+ "-----BEGIN ID SIGNATURE-----\n"
+ "rPBFn6IJ6TvAHj4pSwlg+RTn1fP89JGSVa08wuyJr5dAvZsdakQXvRjamT9oJU"
+ "aZ\nnY5Rl/tRlGuSQ0BglTPPKoXdKERK0FUr9f0EKrQy7NDUgE2j9losiRuyKz"
+ "hA3neZ\nK4yF8bhqAwM51u7fzAhIjNeRif9c04rhFJJCseco84w=\n"
+ "-----END ID SIGNATURE-----";
+
private static RelayNetworkStatusVote
createWithDirKeyCrosscertLines(String lines)
throws DescriptorParseException {
@@ -259,6 +308,7 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyCrosscertLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyCertificationLines = "dir-key-certification\n"
+ "-----BEGIN SIGNATURE-----\n"
+ "hPSh6FuohNF5ccjiMbkvr8cZJwGFuL11cNtwN9k0X3pUdFZVATIEkqBe7z+rE2"
@@ -271,6 +321,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "bEGbvY/P8mzVAZxp3Yz+sRtNel\nC1SWz/Fx+Saex5oI7DJ3xtSD4XqKb/wYwZ"
+ "FT8IxDYq1t2tFXdHxd4QPRVcvc0zYC\n"
+ "-----END SIGNATURE-----";
+
private static RelayNetworkStatusVote
createWithDirKeyCertificationLines(String lines)
throws DescriptorParseException {
@@ -278,14 +329,18 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyCertificationLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private List<String> statusEntries = null;
+
private static RelayNetworkStatusVote createWithStatusEntries(
List<String> statusEntries) throws DescriptorParseException {
VoteBuilder vb = new VoteBuilder();
vb.statusEntries = statusEntries;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String directoryFooterLine = "directory-footer";
+
private static RelayNetworkStatusVote
createWithDirectoryFooterLine(String line)
throws DescriptorParseException {
@@ -293,6 +348,7 @@ public class RelayNetworkStatusVoteImplTest {
vb.directoryFooterLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String directorySignatureLines = "directory-signature "
+ "80550987E1D626E3EBA5E5E75A458DE0626D088C "
+ "EEB9299D295C1C815E289FBF2F2BBEA5F52FDD19\n"
@@ -301,6 +357,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "F3Yh\nrXVaaoP07r6Ta+s0g1Zijm3lms50Nk/4tV2p8Y63c3F4Q3DAnK40Oi"
+ "kfOIwEj+Ny\n+zBRQssP3hPhTPOj/A7o3mZZwtL6x1sxpeu/nME1l5E=\n"
+ "-----END SIGNATURE-----";
+
private static RelayNetworkStatusVote
createWithDirectorySignatureLines(String lines)
throws DescriptorParseException {
@@ -308,7 +365,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.directorySignatureLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String unrecognizedHeaderLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedHeaderLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -318,7 +377,9 @@ public class RelayNetworkStatusVoteImplTest {
return new RelayNetworkStatusVoteImpl(vb.buildVote(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedDirSourceLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedDirSourceLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -328,7 +389,9 @@ public class RelayNetworkStatusVoteImplTest {
return new RelayNetworkStatusVoteImpl(vb.buildVote(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedStatusEntryLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedStatusEntryLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -338,7 +401,9 @@ public class RelayNetworkStatusVoteImplTest {
return new RelayNetworkStatusVoteImpl(vb.buildVote(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedFooterLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedFooterLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -348,7 +413,9 @@ public class RelayNetworkStatusVoteImplTest {
return new RelayNetworkStatusVoteImpl(vb.buildVote(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedDirectorySignatureLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedDirectorySignatureLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -378,6 +445,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "m 8,9,10,11 "
+ "sha256=9ciEx9t0McXk9A06I7qwN7pxuNOdpCP64RV/6cx2Zkc");
}
+
private byte[] buildVote() {
StringBuilder sb = new StringBuilder();
this.appendHeader(sb);
@@ -387,6 +455,7 @@ public class RelayNetworkStatusVoteImplTest {
this.appendDirectorySignature(sb);
return sb.toString().getBytes();
}
+
private void appendHeader(StringBuilder sb) {
if (this.networkStatusVersionLine != null) {
sb.append(this.networkStatusVersionLine).append("\n");
@@ -434,6 +503,7 @@ public class RelayNetworkStatusVoteImplTest {
sb.append(this.unrecognizedHeaderLine).append("\n");
}
}
+
private void appendDirSource(StringBuilder sb) {
if (this.dirSourceLine != null) {
sb.append(this.dirSourceLine).append("\n");
@@ -472,6 +542,7 @@ public class RelayNetworkStatusVoteImplTest {
sb.append(this.unrecognizedDirSourceLine).append("\n");
}
}
+
private void appendStatusEntries(StringBuilder sb) {
for (String statusEntry : this.statusEntries) {
sb.append(statusEntry).append("\n");
@@ -480,6 +551,7 @@ public class RelayNetworkStatusVoteImplTest {
sb.append(this.unrecognizedStatusEntryLine).append("\n");
}
}
+
private void appendFooter(StringBuilder sb) {
if (this.directoryFooterLine != null) {
sb.append(this.directoryFooterLine).append("\n");
@@ -488,6 +560,7 @@ public class RelayNetworkStatusVoteImplTest {
sb.append(this.unrecognizedFooterLine).append("\n");
}
}
+
private void appendDirectorySignature(StringBuilder sb) {
if (this.directorySignatureLines != null) {
sb.append(directorySignatureLines).append("\n");
@@ -517,8 +590,8 @@ public class RelayNetworkStatusVoteImplTest {
assertEquals(30000, (int) vote.getConsensusParams().get(
"CircuitPriorityHalflifeMsec"));
assertEquals("Tor 0.2.1.29 (r8e9b25e6c7a2e70c)",
- vote.getStatusEntry("00343A8024F70E214728F0C5AF7ACE0C1508F073").
- getVersion());
+ vote.getStatusEntry("00343A8024F70E214728F0C5AF7ACE0C1508F073")
+ .getVersion());
assertEquals(3, vote.getDirKeyCertificateVersion());
assertEquals("80550987E1D626E3EBA5E5E75A458DE0626D088C",
vote.getIdentity());
@@ -832,11 +905,11 @@ public class RelayNetworkStatusVoteImplTest {
}
}
- @Test(expected = DescriptorParseException.class)
- public void testPackageIncomplete() throws DescriptorParseException {
- String packageLine = "package shouldbesecond 0 http";
- ConsensusBuilder.createWithPackageLines(packageLine);
- }
+ @Test(expected = DescriptorParseException.class)
+ public void testPackageIncomplete() throws DescriptorParseException {
+ String packageLine = "package shouldbesecond 0 http";
+ ConsensusBuilder.createWithPackageLines(packageLine);
+ }
@Test(expected = DescriptorParseException.class)
public void testKnownFlagsNoLine() throws DescriptorParseException {
@@ -1284,8 +1357,8 @@ public class RelayNetworkStatusVoteImplTest {
public void testUnrecognizedHeaderLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusVote vote = VoteBuilder.
- createWithUnrecognizedHeaderLine(unrecognizedLine, false);
+ RelayNetworkStatusVote vote = VoteBuilder
+ .createWithUnrecognizedHeaderLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, vote.getUnrecognizedLines());
@@ -1303,8 +1376,8 @@ public class RelayNetworkStatusVoteImplTest {
public void testUnrecognizedDirSourceLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusVote vote = VoteBuilder.
- createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
+ RelayNetworkStatusVote vote = VoteBuilder
+ .createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, vote.getUnrecognizedLines());
@@ -1321,8 +1394,8 @@ public class RelayNetworkStatusVoteImplTest {
public void testUnrecognizedFooterLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusVote vote = VoteBuilder.
- createWithUnrecognizedFooterLine(unrecognizedLine, false);
+ RelayNetworkStatusVote vote = VoteBuilder
+ .createWithUnrecognizedFooterLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, vote.getUnrecognizedLines());
diff --git a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
index 0daa83b..3769ead 100644
--- a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
@@ -1,14 +1,20 @@
/* Copyright 2012--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
-import org.torproject.descriptor.DescriptorParseException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.torproject.descriptor.BandwidthHistory;
+import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.ServerDescriptor;
+
+import org.junit.Test;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -16,68 +22,79 @@ import java.util.Arrays;
import java.util.List;
import java.util.SortedMap;
-import org.junit.Test;
-import org.torproject.descriptor.BandwidthHistory;
-import org.torproject.descriptor.ServerDescriptor;
-
/* Test parsing of relay server descriptors. */
public class ServerDescriptorImplTest {
/* Helper class to build a descriptor based on default data and
* modifications requested by test methods. */
private static class DescriptorBuilder {
+
private String routerLine = "router saberrider2008 94.134.192.243 "
+ "9001 0 0";
+
private static ServerDescriptor createWithRouterLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.routerLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String bandwidthLine = "bandwidth 51200 51200 53470";
+
private static ServerDescriptor createWithBandwidthLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.bandwidthLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String platformLine = "platform Tor 0.2.2.35 "
+ "(git-b04388f9e7546a9f) on Linux i686";
+
private static ServerDescriptor createWithPlatformLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.platformLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String publishedLine = "published 2012-01-01 04:03:19";
+
private static ServerDescriptor createWithPublishedLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.publishedLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String fingerprintLine = "opt fingerprint D873 3048 FC8E "
+ "C910 2466 AD8F 3098 622B F1BF 71FD";
+
private static ServerDescriptor createWithFingerprintLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.fingerprintLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String hibernatingLine = null;
+
private static ServerDescriptor createWithHibernatingLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.hibernatingLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String uptimeLine = "uptime 48";
+
private static ServerDescriptor createWithUptimeLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.uptimeLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String onionKeyLines = "onion-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIGJAoGBAKM+iiHhO6eHsvd6Xjws9z9EQB1V/Bpuy5ciGJ1U4V9SeiKooSo5Bp"
@@ -85,12 +102,14 @@ public class ServerDescriptorImplTest {
+ "uC3cTF\n9wE4WXY4nX7w0RTN18UVLxrt1A9PP0cobFNiPs9rzJCbKFfacOkpAg"
+ "MBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static ServerDescriptor createWithOnionKeyLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.onionKeyLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String signingKeyLines = "signing-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIGJAoGBALMm3r3QDh482Ewe6Ub9wvRIfmEkoNX6q5cEAtQRNHSDcNx41gjELb"
@@ -98,99 +117,126 @@ public class ServerDescriptorImplTest {
+ "DhUROG\n8URDIhQoixcUeyyrVB8sxliSstKimulGnB7xpjYOlO8JKaHLNL4TAg"
+ "MBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static ServerDescriptor createWithSigningKeyLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.signingKeyLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String onionKeyCrosscertLines = null;
+
private static ServerDescriptor createWithOnionKeyCrosscertLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.onionKeyCrosscertLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String ntorOnionKeyCrosscertLines = null;
+
private static ServerDescriptor createWithNtorOnionKeyCrosscertLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.ntorOnionKeyCrosscertLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String exitPolicyLines = "reject *:*";
+
private static ServerDescriptor createWithExitPolicyLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.exitPolicyLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String contactLine = "contact Random Person <nobody AT "
+ "example dot com>";
+
private static ServerDescriptor createWithContactLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.contactLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String familyLine = null;
+
private static ServerDescriptor createWithFamilyLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.familyLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String readHistoryLine = null;
+
private static ServerDescriptor createWithReadHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.readHistoryLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String writeHistoryLine = null;
+
private static ServerDescriptor createWithWriteHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.writeHistoryLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String eventdnsLine = null;
+
private static ServerDescriptor createWithEventdnsLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.eventdnsLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String cachesExtraInfoLine = null;
+
private static ServerDescriptor createWithCachesExtraInfoLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.cachesExtraInfoLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String extraInfoDigestLine = "opt extra-info-digest "
+ "1469D1550738A25B1E7B47CDDBCD7B2899F51B74";
+
private static ServerDescriptor createWithExtraInfoDigestLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.extraInfoDigestLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String hiddenServiceDirLine = "opt hidden-service-dir";
+
private static ServerDescriptor createWithHiddenServiceDirLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.hiddenServiceDirLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String protocolsLine = "opt protocols Link 1 2 Circuit 1";
+
private static ServerDescriptor createWithProtocolsLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.protocolsLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String allowSingleHopExitsLine = null;
+
private static ServerDescriptor
createWithAllowSingleHopExitsLine(String line)
throws DescriptorParseException {
@@ -198,40 +244,50 @@ public class ServerDescriptorImplTest {
db.allowSingleHopExitsLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String ipv6PolicyLine = null;
+
private static ServerDescriptor createWithIpv6PolicyLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.ipv6PolicyLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String ntorOnionKeyLine = null;
+
private static ServerDescriptor createWithNtorOnionKeyLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.ntorOnionKeyLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String tunnelledDirServerLine = null;
+
private static ServerDescriptor createWithTunnelledDirServerLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.tunnelledDirServerLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String routerSignatureLines = "router-signature\n"
+ "-----BEGIN SIGNATURE-----\n"
+ "o4j+kH8UQfjBwepUnr99v0ebN8RpzHJ/lqYsTojXHy9kMr1RNI9IDeSzA7PSqT"
+ "uV\n4PL8QsGtlfwthtIoZpB2srZeyN/mcpA9fa1JXUrt/UN9K/+32Cyaad7h0n"
+ "HE6Xfb\njqpXDpnBpvk4zjmzjjKYnIsUWTnADmu0fo3xTRqXi7g=\n"
+ "-----END SIGNATURE-----";
+
private static ServerDescriptor createWithRouterSignatureLines(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.routerSignatureLines = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String unrecognizedLine = null;
+
private static ServerDescriptor createWithUnrecognizedLine(
String line, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
@@ -240,7 +296,9 @@ public class ServerDescriptorImplTest {
return new RelayServerDescriptorImpl(db.buildDescriptor(),
failUnrecognizedDescriptorLines);
}
+
private byte[] nonAsciiLineBytes = null;
+
private static ServerDescriptor createWithNonAsciiLineBytes(
byte[] lineBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
@@ -249,8 +307,13 @@ public class ServerDescriptorImplTest {
return new RelayServerDescriptorImpl(db.buildDescriptor(),
failUnrecognizedDescriptorLines);
}
- private String identityEd25519Lines = null,
- masterKeyEd25519Line = null, routerSigEd25519Line = null;
+
+ private String identityEd25519Lines = null;
+
+ private String masterKeyEd25519Line = null;
+
+ private String routerSigEd25519Line = null;
+
private static ServerDescriptor createWithEd25519Lines(
String identityEd25519Lines, String masterKeyEd25519Line,
String routerSigEd25519Line) throws DescriptorParseException {
@@ -260,6 +323,7 @@ public class ServerDescriptorImplTest {
db.routerSigEd25519Line = routerSigEd25519Line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private byte[] buildDescriptor() {
StringBuilder sb = new StringBuilder();
if (this.routerLine != null) {
@@ -418,8 +482,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testRouterOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithRouterLine("opt router saberrider2008 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithRouterLine("opt router saberrider2008 "
+ "94.134.192.243 9001 0 0");
assertEquals("saberrider2008", descriptor.getNickname());
assertEquals("94.134.192.243", descriptor.getAddress());
@@ -455,8 +519,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testNicknameTwoSpaces() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithRouterLine("router saberrider2008 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithRouterLine("router saberrider2008 "
+ "94.134.192.243 9001 0 0");
assertEquals("saberrider2008", descriptor.getNickname());
assertEquals("94.134.192.243", descriptor.getAddress());
@@ -512,15 +576,15 @@ public class ServerDescriptorImplTest {
@Test()
public void testPlatformMissing() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPlatformLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPlatformLine(null);
assertNull(descriptor.getPlatform());
}
@Test()
public void testPlatformOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPlatformLine("opt platform Tor 0.2.2.35 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPlatformLine("opt platform Tor 0.2.2.35 "
+ "(git-b04388f9e7546a9f) on Linux i686");
assertEquals("Tor 0.2.2.35 (git-b04388f9e7546a9f) on Linux i686",
descriptor.getPlatform());
@@ -528,22 +592,22 @@ public class ServerDescriptorImplTest {
@Test()
public void testPlatformNoSpace() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPlatformLine("platform");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPlatformLine("platform");
assertEquals("", descriptor.getPlatform());
}
@Test()
public void testPlatformSpace() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPlatformLine("platform ");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPlatformLine("platform ");
assertEquals("", descriptor.getPlatform());
}
@Test()
public void testProtocolsNoOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithProtocolsLine("protocols Link 1 2 Circuit 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithProtocolsLine("protocols Link 1 2 Circuit 1");
assertEquals(Arrays.asList(new Integer[] {1, 2}),
descriptor.getLinkProtocolVersions());
assertEquals(Arrays.asList(new Integer[] {1}),
@@ -551,7 +615,7 @@ public class ServerDescriptorImplTest {
}
@Test(expected = DescriptorParseException.class)
- public void testProtocolsAB() throws DescriptorParseException {
+ public void testProtocolsAb() throws DescriptorParseException {
DescriptorBuilder.createWithProtocolsLine("opt protocols Link A B "
+ "Circuit 1");
}
@@ -569,8 +633,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testPublishedOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPublishedLine("opt published 2012-01-01 04:03:19");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPublishedLine("opt published 2012-01-01 04:03:19");
assertEquals(1325390599000L, descriptor.getPublishedMillis());
}
@@ -599,15 +663,15 @@ public class ServerDescriptorImplTest {
@Test()
public void testPublishedMillis() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPublishedLine("opt published 2012-01-01 04:03:19.123");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPublishedLine("opt published 2012-01-01 04:03:19.123");
assertEquals(1325390599000L, descriptor.getPublishedMillis());
}
@Test()
public void testFingerprintNoOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFingerprintLine("fingerprint D873 3048 FC8E C910 2466 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFingerprintLine("fingerprint D873 3048 FC8E C910 2466 "
+ "AD8F 3098 622B F1BF 71FD");
assertEquals("D8733048FC8EC9102466AD8F3098622BF1BF71FD",
descriptor.getFingerprint());
@@ -639,15 +703,15 @@ public class ServerDescriptorImplTest {
@Test()
public void testUptimeMissing() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUptimeLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUptimeLine(null);
assertNull(descriptor.getUptime());
}
@Test()
public void testUptimeOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUptimeLine("opt uptime 48");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUptimeLine("opt uptime 48");
assertEquals(48, descriptor.getUptime().longValue());
}
@@ -678,8 +742,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testBandwidthOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithBandwidthLine("opt bandwidth 51200 51200 53470");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithBandwidthLine("opt bandwidth 51200 51200 53470");
assertEquals(51200, (int) descriptor.getBandwidthRate());
assertEquals(51200, (int) descriptor.getBandwidthBurst());
assertEquals(53470, (int) descriptor.getBandwidthObserved());
@@ -700,8 +764,8 @@ public class ServerDescriptorImplTest {
/* This is allowed, because Tor versions 0.0.8 and older only wrote
* bandwidth lines with rate and burst values, but no observed
* value. */
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithBandwidthLine("bandwidth 51200 51200");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithBandwidthLine("bandwidth 51200 51200");
assertEquals(51200, (int) descriptor.getBandwidthRate());
assertEquals(51200, (int) descriptor.getBandwidthBurst());
assertEquals(-1, (int) descriptor.getBandwidthObserved());
@@ -721,8 +785,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testExtraInfoDigestNoOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoDigestLine("extra-info-digest "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoDigestLine("extra-info-digest "
+ "1469D1550738A25B1E7B47CDDBCD7B2899F51B74");
assertEquals("1469D1550738A25B1E7B47CDDBCD7B2899F51B74",
descriptor.getExtraInfoDigest());
@@ -753,8 +817,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testExtraInfoDigestMissing()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoDigestLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoDigestLine(null);
assertNull(descriptor.getExtraInfoDigest());
}
@@ -766,8 +830,8 @@ public class ServerDescriptorImplTest {
"V609l+N6ActBveebfNbH5lQ6wHDNstDkFgyqEhBHwtA";
String extraInfoDigestLine = String.format("extra-info-digest %s %s",
extraInfoDigest, additionalExtraInfoDigest);
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoDigestLine(extraInfoDigestLine);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoDigestLine(extraInfoDigestLine);
assertEquals(extraInfoDigest, descriptor.getExtraInfoDigest());
}
@@ -796,16 +860,16 @@ public class ServerDescriptorImplTest {
@Test()
public void testHiddenServiceDirMissing()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHiddenServiceDirLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHiddenServiceDirLine(null);
assertNull(descriptor.getHiddenServiceDirVersions());
}
@Test()
public void testHiddenServiceDirNoOpt()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHiddenServiceDirLine("hidden-service-dir");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHiddenServiceDirLine("hidden-service-dir");
assertEquals(Arrays.asList(new Integer[] {2}),
descriptor.getHiddenServiceDirVersions());
}
@@ -813,23 +877,23 @@ public class ServerDescriptorImplTest {
@Test()
public void testHiddenServiceDirVersions2And3()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHiddenServiceDirLine("hidden-service-dir 2 3");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHiddenServiceDirLine("hidden-service-dir 2 3");
assertEquals(Arrays.asList(new Integer[] {2, 3}),
descriptor.getHiddenServiceDirVersions());
}
@Test()
public void testContactMissing() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithContactLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithContactLine(null);
assertNull(descriptor.getContact());
}
@Test()
public void testContactOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithContactLine("opt contact Random Person");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithContactLine("opt contact Random Person");
assertEquals("Random Person", descriptor.getContact());
}
@@ -841,8 +905,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testContactNoSpace() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithContactLine("contact");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithContactLine("contact");
assertEquals("", descriptor.getContact());
}
@@ -856,24 +920,24 @@ public class ServerDescriptorImplTest {
+ "07\rmTQoP40G4zqOrVEOOcXpdSiRnHWJYfgTnkibNZrOZEZLn3H1ywpovEgESm"
+ "oGEdAX\roid3XuIYRpRnqoafbFg9sg+OofX/mGrO+5ACfagQ9rlfx2oxCWijYw"
+ "pYFRk3NhCY=\r=Xaw3\r-----END PGP PUBLIC KEY BLOCK-----";
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithContactLine("contact " + contactString);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithContactLine("contact " + contactString);
assertEquals(contactString, descriptor.getContact());
}
@Test()
public void testExitPolicyRejectAllAcceptAll()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExitPolicyLines("reject *:*\naccept *:*");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExitPolicyLines("reject *:*\naccept *:*");
assertEquals(Arrays.asList(new String[] {"reject *:*", "accept *:*"}),
descriptor.getExitPolicyLines());
}
@Test()
public void testExitPolicyOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExitPolicyLines("opt reject *:*");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExitPolicyLines("opt reject *:*");
assertEquals(Arrays.asList(new String[] {"reject *:*"}),
descriptor.getExitPolicyLines());
}
@@ -886,8 +950,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testExitPolicyAccept80RejectAll()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExitPolicyLines("accept *:80\nreject *:*");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExitPolicyLines("accept *:80\nreject *:*");
assertEquals(Arrays.asList(new String[] {"accept *:80",
"reject *:*"}), descriptor.getExitPolicyLines());
}
@@ -916,8 +980,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testExitPolicyMaskTypes() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExitPolicyLines("reject 192.168.0.0/16:*\n"
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExitPolicyLines("reject 192.168.0.0/16:*\n"
+ "reject 94.134.192.243/255.255.255.0:*");
assertEquals(Arrays.asList(new String[] { "reject 192.168.0.0/16:*",
"reject 94.134.192.243/255.255.255.0:*"}),
@@ -947,22 +1011,22 @@ public class ServerDescriptorImplTest {
@Test()
public void testHibernatingOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHibernatingLine("opt hibernating 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHibernatingLine("opt hibernating 1");
assertTrue(descriptor.isHibernating());
}
@Test()
public void testHibernatingFalse() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHibernatingLine("hibernating 0");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHibernatingLine("hibernating 0");
assertFalse(descriptor.isHibernating());
}
@Test()
public void testHibernatingTrue() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHibernatingLine("hibernating 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHibernatingLine("hibernating 1");
assertTrue(descriptor.isHibernating());
}
@@ -978,16 +1042,16 @@ public class ServerDescriptorImplTest {
@Test()
public void testFamilyOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("opt family saberrider2008");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("opt family saberrider2008");
assertEquals(Arrays.asList(new String[] {"saberrider2008"}),
descriptor.getFamilyEntries());
}
@Test()
public void testFamilyFingerprint() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("family "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("family "
+ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD");
assertEquals(Arrays.asList(new String[] {
"$D8733048FC8EC9102466AD8F3098622BF1BF71FD"}),
@@ -996,8 +1060,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testFamilyNickname() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("family saberrider2008");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("family saberrider2008");
assertEquals(Arrays.asList(new String[] {"saberrider2008"}),
descriptor.getFamilyEntries());
}
@@ -1023,8 +1087,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testFamilyFingerprintNicknameNamed()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("family "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("family "
+ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD=saberrider2008");
assertEquals(Arrays.asList(new String[]
{ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD=saberrider2008" }),
@@ -1034,8 +1098,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testFamilyFingerprintNicknameUnnamed()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("family "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("family "
+ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD~saberrider2008");
assertEquals(Arrays.asList(new String[]
{ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD~saberrider2008" }),
@@ -1046,16 +1110,16 @@ public class ServerDescriptorImplTest {
public void testWriteHistory() throws DescriptorParseException {
String writeHistoryLine = "write-history 2012-01-01 03:51:44 (900 s) "
+ "4345856,261120,7591936,1748992";
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine(writeHistoryLine);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine(writeHistoryLine);
assertNotNull(descriptor.getWriteHistory());
BandwidthHistory parsedWriteHistory = descriptor.getWriteHistory();
assertEquals(writeHistoryLine, parsedWriteHistory.getLine());
- assertEquals(1325389904000L, (long) parsedWriteHistory.
- getHistoryEndMillis());
+ assertEquals(1325389904000L, (long) parsedWriteHistory
+ .getHistoryEndMillis());
assertEquals(900L, (long) parsedWriteHistory.getIntervalLength());
- SortedMap<Long, Long> bandwidthValues = parsedWriteHistory.
- getBandwidthValues();
+ SortedMap<Long, Long> bandwidthValues = parsedWriteHistory
+ .getBandwidthValues();
assertEquals(4345856L, (long) bandwidthValues.remove(1325387204000L));
assertEquals(261120L, (long) bandwidthValues.remove(1325388104000L));
assertEquals(7591936L, (long) bandwidthValues.remove(1325389004000L));
@@ -1065,8 +1129,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testWriteHistoryOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine("opt write-history 2012-01-01 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine("opt write-history 2012-01-01 "
+ "03:51:44 (900 s) 4345856,261120,7591936,1748992");
assertNotNull(descriptor.getWriteHistory());
}
@@ -1115,25 +1179,25 @@ public class ServerDescriptorImplTest {
@Test()
public void testWriteHistoryNoValuesSpace()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ "(900 s) ");
- assertEquals(900, (long) descriptor.getWriteHistory().
- getIntervalLength());
- assertTrue(descriptor.getWriteHistory().getBandwidthValues().
- isEmpty());
+ assertEquals(900, (long) descriptor.getWriteHistory()
+ .getIntervalLength());
+ assertTrue(descriptor.getWriteHistory().getBandwidthValues()
+ .isEmpty());
}
@Test()
public void testWriteHistoryNoValuesNoSpace()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ "(900 s)");
- assertEquals(900, (long) descriptor.getWriteHistory().
- getIntervalLength());
- assertTrue(descriptor.getWriteHistory().getBandwidthValues().
- isEmpty());
+ assertEquals(900, (long) descriptor.getWriteHistory()
+ .getIntervalLength());
+ assertTrue(descriptor.getWriteHistory().getBandwidthValues()
+ .isEmpty());
}
@Test(expected = DescriptorParseException.class)
@@ -1152,27 +1216,27 @@ public class ServerDescriptorImplTest {
@Test()
public void testWriteHistory1800Seconds()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ "(1800 s) 4345856");
- assertEquals(1800L, (long) descriptor.getWriteHistory().
- getIntervalLength());
+ assertEquals(1800L, (long) descriptor.getWriteHistory()
+ .getIntervalLength());
}
@Test()
public void testReadHistory() throws DescriptorParseException {
String readHistoryLine = "read-history 2012-01-01 03:51:44 (900 s) "
+ "4268032,139264,7797760,1415168";
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithReadHistoryLine(readHistoryLine);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithReadHistoryLine(readHistoryLine);
assertNotNull(descriptor.getReadHistory());
BandwidthHistory parsedReadHistory = descriptor.getReadHistory();
assertEquals(readHistoryLine, parsedReadHistory.getLine());
- assertEquals(1325389904000L, (long) parsedReadHistory.
- getHistoryEndMillis());
+ assertEquals(1325389904000L, (long) parsedReadHistory
+ .getHistoryEndMillis());
assertEquals(900L, (long) parsedReadHistory.getIntervalLength());
- SortedMap<Long, Long> bandwidthValues = parsedReadHistory.
- getBandwidthValues();
+ SortedMap<Long, Long> bandwidthValues = parsedReadHistory
+ .getBandwidthValues();
assertEquals(4268032L, (long) bandwidthValues.remove(1325387204000L));
assertEquals(139264L, (long) bandwidthValues.remove(1325388104000L));
assertEquals(7797760L, (long) bandwidthValues.remove(1325389004000L));
@@ -1191,22 +1255,22 @@ public class ServerDescriptorImplTest {
@Test()
public void testEventdnsOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithEventdnsLine("opt eventdns 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithEventdnsLine("opt eventdns 1");
assertTrue(descriptor.getUsesEnhancedDnsLogic());
}
@Test()
public void testEventdns1() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithEventdnsLine("eventdns 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithEventdnsLine("eventdns 1");
assertTrue(descriptor.getUsesEnhancedDnsLogic());
}
@Test()
public void testEventdns0() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithEventdnsLine("eventdns 0");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithEventdnsLine("eventdns 0");
assertFalse(descriptor.getUsesEnhancedDnsLogic());
}
@@ -1222,16 +1286,16 @@ public class ServerDescriptorImplTest {
@Test()
public void testCachesExtraInfoOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithCachesExtraInfoLine("opt caches-extra-info");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithCachesExtraInfoLine("opt caches-extra-info");
assertTrue(descriptor.getCachesExtraInfo());
}
@Test()
public void testCachesExtraInfoNoSpace()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithCachesExtraInfoLine("caches-extra-info");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithCachesExtraInfoLine("caches-extra-info");
assertTrue(descriptor.getCachesExtraInfo());
}
@@ -1244,16 +1308,16 @@ public class ServerDescriptorImplTest {
@Test()
public void testAllowSingleHopExitsOpt()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithAllowSingleHopExitsLine("opt allow-single-hop-exits");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithAllowSingleHopExitsLine("opt allow-single-hop-exits");
assertTrue(descriptor.getAllowSingleHopExits());
}
@Test()
public void testAllowSingleHopExitsNoSpace()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithAllowSingleHopExitsLine("allow-single-hop-exits");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithAllowSingleHopExitsLine("allow-single-hop-exits");
assertTrue(descriptor.getAllowSingleHopExits());
}
@@ -1278,8 +1342,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testIpv6PolicyLine() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithIpv6PolicyLine("ipv6-policy accept 80,1194,1220,1293");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithIpv6PolicyLine("ipv6-policy accept 80,1194,1220,1293");
assertEquals("accept", descriptor.getIpv6DefaultPolicy());
assertEquals("80,1194,1220,1293", descriptor.getIpv6PortList());
}
@@ -1317,8 +1381,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testNtorOnionKeyLine() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithNtorOnionKeyLine("ntor-onion-key "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithNtorOnionKeyLine("ntor-onion-key "
+ "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY=");
assertEquals("Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY",
descriptor.getNtorOnionKey());
@@ -1327,8 +1391,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testNtorOnionKeyLineNoPadding()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithNtorOnionKeyLine("ntor-onion-key "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithNtorOnionKeyLine("ntor-onion-key "
+ "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY");
assertEquals("Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY",
descriptor.getNtorOnionKey());
@@ -1403,8 +1467,8 @@ public class ServerDescriptorImplTest {
public void testUnrecognizedLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUnrecognizedLine(unrecognizedLine, false);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUnrecognizedLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
@@ -1426,8 +1490,8 @@ public class ServerDescriptorImplTest {
for (String line : unrecognizedLines) {
sb.append("\n").append(line);
}
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUnrecognizedLine(sb.toString().substring(1), false);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUnrecognizedLine(sb.toString().substring(1), false);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
}
@@ -1447,8 +1511,8 @@ public class ServerDescriptorImplTest {
for (String line : unrecognizedLines) {
sb.append("\n").append(line);
}
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUnrecognizedLine(sb.toString().substring(1), false);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUnrecognizedLine(sb.toString().substring(1), false);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
}
@@ -1579,7 +1643,7 @@ public class ServerDescriptorImplTest {
public void testOnionKeyCrosscertDuplicate()
throws DescriptorParseException {
DescriptorBuilder.createWithOnionKeyCrosscertLines(
- ONION_KEY_CROSSCERT_LINES + "\n" + ONION_KEY_CROSSCERT_LINES);
+ ONION_KEY_CROSSCERT_LINES + "\n" + ONION_KEY_CROSSCERT_LINES);
}
@Test()
diff --git a/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java b/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java
index 62d0875..080d16d 100644
--- a/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java
@@ -1,19 +1,21 @@
/* Copyright 2015--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import java.util.List;
+import org.torproject.descriptor.Descriptor;
import org.junit.Test;
-import org.torproject.descriptor.Descriptor;
+
+import java.util.List;
public class TorperfResultImplTest {
@Test()
- public void testAnnotatedInput() throws Exception{
+ public void testAnnotatedInput() throws Exception {
TorperfResultImpl result = (TorperfResultImpl)
(TorperfResultImpl.parseTorperfResults((torperfAnnotation + input)
.getBytes("US-ASCII"), false).get(0));
@@ -29,7 +31,7 @@ public class TorperfResultImplTest {
}
@Test()
- public void testPartiallyAnnotatedInput() throws Exception{
+ public void testPartiallyAnnotatedInput() throws Exception {
byte[] asciiBytes = (torperfAnnotation
+ input + input + input).getBytes("US-ASCII");
List<Descriptor> result = TorperfResultImpl.parseTorperfResults(
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits