commit 266051f3397bb0f676054ce2459502f680bfab6d Author: iwakeh iwakeh@torproject.org Date: Fri Oct 27 17:35:10 2017 +0000
Rename SanitizedBridgeDescriptorBuilder to DescriptorBuilder.
The class doesn't 'know' about descriptor sanitization, it is only a sort of container for writing descriptors. It could be actually moved to some util package and used in other parsing steps, too.
Also rename test helper classes to avoid naming conflicts. Remove 'descriptor' from variable names. Make DescriptorBuilder public. Adapt other classes as well as tests. --- .../collector/bridgedescs/DescriptorBuilder.java | 57 +++++++++ .../SanitizedBridgeDescriptorBuilder.java | 54 -------- .../bridgedescs/SanitizedBridgesWriter.java | 4 +- ...er.java => ExtraInfoTestDescriptorBuilder.java} | 4 +- ...ava => NetworkStatusTestDescriptorBuilder.java} | 4 +- .../bridgedescs/SanitizedBridgesWriterTest.java | 142 +++++++++++---------- ...ilder.java => ServerTestDescriptorBuilder.java} | 4 +- ...TarballBuilder.java => TarballTestBuilder.java} | 12 +- ...ptorBuilder.java => TestDescriptorBuilder.java} | 2 +- 9 files changed, 145 insertions(+), 138 deletions(-)
diff --git a/src/main/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java b/src/main/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java new file mode 100644 index 0000000..12a8956 --- /dev/null +++ b/src/main/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java @@ -0,0 +1,57 @@ +/* Copyright 2018 The Tor Project + * See LICENSE for licensing information */ + +package org.torproject.collector.bridgedescs; + +import java.util.ArrayList; +import java.util.List; + +/** Builder for descriptors. + * + * <p>This builder class can be used while parsing and processing an original + * descriptor. It accepts {@code String}s, {@code DescriptorBuilder}s and + * {@code StringBuilder}s. The latter two as placeholders for parts that can + * only be processed after finishing the parsing step.</p> */ +class DescriptorBuilder { + + private List<StringBuilder> parts; + + private StringBuilder lastPart; + + public DescriptorBuilder() { + this.parts = new ArrayList<>(); + this.lastPart = new StringBuilder(); + this.parts.add(this.lastPart); + } + + public DescriptorBuilder append(String sanitizedString) { + this.lastPart.append(sanitizedString); + return this; + } + + public DescriptorBuilder append(StringBuilder placeholder) { + this.parts.add(placeholder); + this.lastPart = new StringBuilder(); + this.parts.add(this.lastPart); + return this; + } + + public DescriptorBuilder space() { + this.lastPart.append(' '); + return this; + } + + public DescriptorBuilder newLine() { + this.lastPart.append('\n'); + return this; + } + + @Override + public String toString() { + StringBuilder full = new StringBuilder(); + for (StringBuilder part : this.parts) { + full.append(part); + } + return full.toString(); + } +} diff --git a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgeDescriptorBuilder.java b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgeDescriptorBuilder.java deleted file mode 100644 index 174a5ae..0000000 --- a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgeDescriptorBuilder.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.torproject.collector.bridgedescs; - -import java.util.ArrayList; -import java.util.List; - -/** Builder for sanitized bridge descriptors. - * - * <p>This builder class can be used while parsing and sanitizing an original - * bridge descriptor. It accepts already sanitized {@code String}s and - * {@code StringBuilder}s as placeholders for parts that can only be sanitized - * after finishing the parsing step.</p> */ -class SanitizedBridgeDescriptorBuilder { - - private List<StringBuilder> descriptorParts; - - private StringBuilder lastDescriptorPart; - - SanitizedBridgeDescriptorBuilder() { - this.descriptorParts = new ArrayList<>(); - this.lastDescriptorPart = new StringBuilder(); - this.descriptorParts.add(this.lastDescriptorPart); - } - - SanitizedBridgeDescriptorBuilder append(String sanitizedString) { - this.lastDescriptorPart.append(sanitizedString); - return this; - } - - SanitizedBridgeDescriptorBuilder append(StringBuilder placeholder) { - this.descriptorParts.add(placeholder); - this.lastDescriptorPart = new StringBuilder(); - this.descriptorParts.add(this.lastDescriptorPart); - return this; - } - - SanitizedBridgeDescriptorBuilder space() { - this.lastDescriptorPart.append(' '); - return this; - } - - SanitizedBridgeDescriptorBuilder newLine() { - this.lastDescriptorPart.append('\n'); - return this; - } - - @Override - public String toString() { - StringBuilder fullDescriptor = new StringBuilder(); - for (StringBuilder descriptorPart : this.descriptorParts) { - fullDescriptor.append(descriptorPart); - } - return fullDescriptor.toString(); - } -} diff --git a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java index 1ef1d60..1d264a5 100644 --- a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java +++ b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java @@ -679,8 +679,7 @@ public class SanitizedBridgesWriter extends CollecTorMain { Map<StringBuilder, String> scrubbedTcpPorts = new HashMap<>(); Map<StringBuilder, String> scrubbedIpAddressesAndTcpPorts = new HashMap<>(); String masterKeyEd25519FromIdentityEd25519 = null; - SanitizedBridgeDescriptorBuilder scrubbed = - new SanitizedBridgeDescriptorBuilder(); + DescriptorBuilder scrubbed = new DescriptorBuilder(); try (BufferedReader br = new BufferedReader(new StringReader( new String(data, "US-ASCII")))) { scrubbed.append(Annotation.BridgeServer.toString()); @@ -923,7 +922,6 @@ public class SanitizedBridgesWriter extends CollecTorMain { return; } } - br.close(); } catch (Exception e) { logger.warn("Could not parse server " + "descriptor.", e); diff --git a/src/test/java/org/torproject/collector/bridgedescs/ExtraInfoDescriptorBuilder.java b/src/test/java/org/torproject/collector/bridgedescs/ExtraInfoTestDescriptorBuilder.java similarity index 95% rename from src/test/java/org/torproject/collector/bridgedescs/ExtraInfoDescriptorBuilder.java rename to src/test/java/org/torproject/collector/bridgedescs/ExtraInfoTestDescriptorBuilder.java index 2c77d47..71d52e9 100644 --- a/src/test/java/org/torproject/collector/bridgedescs/ExtraInfoDescriptorBuilder.java +++ b/src/test/java/org/torproject/collector/bridgedescs/ExtraInfoTestDescriptorBuilder.java @@ -8,10 +8,10 @@ import java.util.Arrays; /** Builds a non-sanitized bridge extra-info descriptor that comes with an * original bridge descriptor (of a bundled and therefore publicly known bridge) * by default. */ -class ExtraInfoDescriptorBuilder extends DescriptorBuilder { +class ExtraInfoTestDescriptorBuilder extends TestDescriptorBuilder {
/** Initializes the descriptor builder. */ - ExtraInfoDescriptorBuilder() { + ExtraInfoTestDescriptorBuilder() { this.addAll(Arrays.asList( "extra-info MeekGoogle " + "46D4A71197B8FA515A826C6B017C522FE264655B", diff --git a/src/test/java/org/torproject/collector/bridgedescs/NetworkStatusBuilder.java b/src/test/java/org/torproject/collector/bridgedescs/NetworkStatusTestDescriptorBuilder.java similarity index 89% rename from src/test/java/org/torproject/collector/bridgedescs/NetworkStatusBuilder.java rename to src/test/java/org/torproject/collector/bridgedescs/NetworkStatusTestDescriptorBuilder.java index 31cccf7..b8c1cc9 100644 --- a/src/test/java/org/torproject/collector/bridgedescs/NetworkStatusBuilder.java +++ b/src/test/java/org/torproject/collector/bridgedescs/NetworkStatusTestDescriptorBuilder.java @@ -8,10 +8,10 @@ import java.util.Arrays; /** Builds a non-sanitized bridge network status that comes with an original * bridge network status entry (of a bundled and therefore publicly known * bridge) by default. */ -class NetworkStatusBuilder extends DescriptorBuilder { +class NetworkStatusTestDescriptorBuilder extends TestDescriptorBuilder {
/** Initializes the descriptor builder. */ - NetworkStatusBuilder() { + NetworkStatusTestDescriptorBuilder() { this.addAll(Arrays.asList( "published 2016-06-30 23:40:28", "flag-thresholds stable-uptime=807660 stable-mtbf=1425164 " diff --git a/src/test/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriterTest.java b/src/test/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriterTest.java index 7e58497..41a88c6 100644 --- a/src/test/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriterTest.java +++ b/src/test/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriterTest.java @@ -62,23 +62,23 @@ public class SanitizedBridgesWriterTest {
/** Server descriptor builder used to build the first and only server * descriptor for this test, unless removed from the tarball builder.*/ - private DescriptorBuilder defaultServerDescriptorBuilder; + private TestDescriptorBuilder defaultServerTestDescriptorBuilder;
/** Extra-info descriptor builder used to build the first and only * extra-info descriptor for this test, unless removed from the tarball * builder.*/ - private DescriptorBuilder defaultExtraInfoDescriptorBuilder; + private TestDescriptorBuilder defaultExtraInfoTestDescriptorBuilder;
/** Network status builder used to build the first and only network * status for this test, unless removed from the tarball builder.*/ - private DescriptorBuilder defaultNetworkStatusBuilder; + private TestDescriptorBuilder defaultNetworkStatusTestDescriptorBuilder;
/** Tarball builder to build the first and only tarball, unless removed * from the test. */ - private TarballBuilder defaultTarballBuilder; + private TarballTestBuilder defaultTarballTestBuilder;
/** Tarball builder(s) for this test. */ - private List<TarballBuilder> tarballBuilders; + private List<TarballTestBuilder> tarballBuilders;
/** Parsed sanitized bridge descriptors with keys being file names and * values being sanitized descriptor lines. */ @@ -104,24 +104,26 @@ public class SanitizedBridgesWriterTest { this.sanitizedBridgesDirectory = this.temporaryFolder.newFolder("out", "bridge-descriptors").toPath(); this.initializeTestConfiguration(); - this.defaultServerDescriptorBuilder = new ServerDescriptorBuilder(); - this.defaultExtraInfoDescriptorBuilder = new ExtraInfoDescriptorBuilder(); - this.defaultNetworkStatusBuilder = new NetworkStatusBuilder(); - this.defaultTarballBuilder = new TarballBuilder( + this.defaultServerTestDescriptorBuilder = new ServerTestDescriptorBuilder(); + this.defaultExtraInfoTestDescriptorBuilder + = new ExtraInfoTestDescriptorBuilder(); + this.defaultNetworkStatusTestDescriptorBuilder + = new NetworkStatusTestDescriptorBuilder(); + this.defaultTarballTestBuilder = new TarballTestBuilder( "from-tonga-2016-07-01T000702Z.tar.gz", 1467331624000L); - this.defaultTarballBuilder.add("bridge-descriptors", 1467331622000L, - Arrays.asList(new DescriptorBuilder[] { - this.defaultServerDescriptorBuilder })); - this.defaultTarballBuilder.add("cached-extrainfo", 1467327972000L, - Arrays.asList(new DescriptorBuilder[] { - this.defaultExtraInfoDescriptorBuilder })); - this.defaultTarballBuilder.add("cached-extrainfo.new", 1467331623000L, - Arrays.asList(new DescriptorBuilder[] { })); - this.defaultTarballBuilder.add("networkstatus-bridges", - 1467330028000L, Arrays.asList(new DescriptorBuilder[] { - this.defaultNetworkStatusBuilder })); + this.defaultTarballTestBuilder.add("bridge-descriptors", 1467331622000L, + Arrays.asList(new TestDescriptorBuilder[] { + this.defaultServerTestDescriptorBuilder })); + this.defaultTarballTestBuilder.add("cached-extrainfo", 1467327972000L, + Arrays.asList(new TestDescriptorBuilder[] { + this.defaultExtraInfoTestDescriptorBuilder })); + this.defaultTarballTestBuilder.add("cached-extrainfo.new", 1467331623000L, + Arrays.asList(new TestDescriptorBuilder[] { })); + this.defaultTarballTestBuilder.add("networkstatus-bridges", + 1467330028000L, Arrays.asList(new TestDescriptorBuilder[] { + this.defaultNetworkStatusTestDescriptorBuilder })); this.tarballBuilders = new ArrayList<>( - Arrays.asList(this.defaultTarballBuilder)); + Arrays.asList(this.defaultTarballTestBuilder)); }
/** Initializes a configuration for the bridge descriptor sanitizer. */ @@ -142,7 +144,7 @@ public class SanitizedBridgesWriterTest { /** Runs this test by executing all builders, performing the sanitizing * process, and parsing sanitized bridge descriptors for inspection. */ private void runTest() throws IOException, ConfigurationException { - for (TarballBuilder tarballBuilder : this.tarballBuilders) { + for (TarballTestBuilder tarballBuilder : this.tarballBuilders) { tarballBuilder.build(new File(this.bridgeDirectoriesDir)); } SanitizedBridgesWriter sbw = new SanitizedBridgesWriter(configuration); @@ -206,7 +208,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorEmpty() throws Exception { - this.defaultServerDescriptorBuilder.clear(); + this.defaultServerTestDescriptorBuilder.clear(); this.runTest(); assertTrue("No server descriptor provided as input.", this.parsedServerDescriptors.isEmpty()); @@ -214,14 +216,14 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorOnlyAnnotation() throws Exception { - this.defaultServerDescriptorBuilder.removeAllExcept("@purpose bridge"); + this.defaultServerTestDescriptorBuilder.removeAllExcept("@purpose bridge"); this.runTest(); }
@Test public void testServerDescriptorAdditionalAnnotation() throws Exception { - this.defaultServerDescriptorBuilder.insertBeforeLineStartingWith( + this.defaultServerTestDescriptorBuilder.insertBeforeLineStartingWith( "@purpose bridge", Arrays.asList("@source 198.50.200.131")); this.runTest(); assertEquals("Expected 3 sanitized descriptors.", 3, @@ -234,7 +236,7 @@ public class SanitizedBridgesWriterTest { "true"); this.configuration.setProperty(Key.BridgeDescriptorMappingsLimit.name(), "30000"); - this.defaultServerDescriptorBuilder.insertBeforeLineStartingWith( + this.defaultServerTestDescriptorBuilder.insertBeforeLineStartingWith( "platform ", Arrays.asList("or-address [2:5:2:5:2:5:2:5]:25")); Path bridgeIpSecretsFile = Paths.get(statsDirectory, "bridge-ip-secrets"); BufferedWriter writer = Files.newBufferedWriter(bridgeIpSecretsFile, @@ -256,7 +258,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorRouterLineTruncated() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith("router ", + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith("router ", Arrays.asList("router MeekGoogle")); this.runTest(); assertTrue("Sanitized server descriptor with invalid router line.", @@ -265,7 +267,8 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorProtoLine() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith("protocols ", + this.defaultServerTestDescriptorBuilder + .replaceLineStartingWith("protocols ", Arrays.asList("proto Cons=1-2 Desc=1-2 DirCache=1 HSDir=1 HSIntro=3 " + "HSRend=1-2 Link=1-4 LinkAuth=1 Microdesc=1-2 Relay=1-2")); this.runTest(); @@ -275,7 +278,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorFingerprintTruncated() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "fingerprint ", Arrays.asList("fingerprint 4")); this.runTest(); assertTrue("Sanitized server descriptor with invalid fingerprint " @@ -285,7 +288,7 @@ public class SanitizedBridgesWriterTest { @Test public void testServerDescriptorFingerprintInvalidHex() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "fingerprint ", Arrays.asList("fingerprint FUN!")); this.runTest(); assertTrue("Sanitized server descriptor with invalid fingerprint " @@ -294,7 +297,8 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorFingerprintOpt() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith("fingerprint ", + this.defaultServerTestDescriptorBuilder + .replaceLineStartingWith("fingerprint ", Arrays.asList("opt fingerprint 46D4 A711 97B8 FA51 5A82 6C6B 017C 522F " + "E264 655B")); this.runTest(); @@ -305,7 +309,7 @@ public class SanitizedBridgesWriterTest { @Test public void testServerDescriptorExtraInfoDigestInvalidHex() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "extra-info-digest ", Arrays.asList("extra-info-digest 6")); this.runTest(); assertTrue("Sanitized server descriptor with invalid extra-info " @@ -315,7 +319,7 @@ public class SanitizedBridgesWriterTest { @Test public void testServerDescriptorExtraInfoDigestInvalidBase64() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "extra-info-digest ", Arrays.asList("extra-info-digest " + "6D03E80568DEFA102968D144CB35FFA6E3355B8A " + "#*?$%x@nxukmmcT1+UnDg4qh0yKbjVUYKhGL8VksoJA")); @@ -327,7 +331,7 @@ public class SanitizedBridgesWriterTest { @Test public void testServerDescriptorExtraInfoDigestSha1Only() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "extra-info-digest ", Arrays.asList("extra-info-digest " + "6D03E80568DEFA102968D144CB35FFA6E3355B8A")); this.runTest(); @@ -339,7 +343,7 @@ public class SanitizedBridgesWriterTest { @Test public void testServerDescriptorExtraInfoDigestThirdArgument() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "extra-info-digest ", Arrays.asList("extra-info-digest " + "6D03E80568DEFA102968D144CB35FFA6E3355B8A " + "cy/LwP7nxukmmcT1+UnDg4qh0yKbjVUYKhGL8VksoJA 00")); @@ -350,7 +354,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorExtraInfoDigestOpt() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "extra-info-digest ", Arrays.asList("opt extra-info-digest " + "6D03E80568DEFA102968D144CB35FFA6E3355B8A " + "cy/LwP7nxukmmcT1+UnDg4qh0yKbjVUYKhGL8VksoJA")); @@ -362,7 +366,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorRejectOwnAddress() throws Exception { - this.defaultServerDescriptorBuilder.insertBeforeLineStartingWith( + this.defaultServerTestDescriptorBuilder.insertBeforeLineStartingWith( "reject *:*", Arrays.asList("reject 198.50.200.131:*", "accept *:80")); this.runTest(); List<String> parsedLines = this.parsedServerDescriptors.get(0); @@ -382,7 +386,7 @@ public class SanitizedBridgesWriterTest { @Test public void testServerDescriptorEd25519IdentityMasterKeyMismatch() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "master-key-ed25519 ", Arrays.asList("master-key-ed25519 " + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); this.runTest(); @@ -392,7 +396,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorEd25519IdentityA() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "identity-ed25519", Arrays.asList("identity-ed25519", "-----BEGIN ED25519 CERT-----", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", @@ -408,7 +412,8 @@ public class SanitizedBridgesWriterTest { public void testServerDescriptorEd25519IdentityEToF() throws Exception { String change9sTo6s = "ZEXE7RkiEJ1l5Ij9hc9TJOpM7/9XSPZnF/PbMfE0u3n3JbOO3s82GN6BPuA0v2Cs"; - this.defaultServerDescriptorBuilder.replaceLineStartingWith(change9sTo6s, + this.defaultServerTestDescriptorBuilder + .replaceLineStartingWith(change9sTo6s, Arrays.asList(change9sTo6s.replaceAll("9", "6"))); this.runTest(); assertTrue("Mismatch between identity and master key.", @@ -417,7 +422,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testServerDescriptorEd25519IdentitySlash() throws Exception { - this.defaultServerDescriptorBuilder.replaceLineStartingWith( + this.defaultServerTestDescriptorBuilder.replaceLineStartingWith( "identity-ed25519", Arrays.asList("identity-ed25519", "-----BEGIN ED25519 CERT-----", "////////////////////////////////////////////////////////////////", @@ -432,7 +437,7 @@ public class SanitizedBridgesWriterTest { @Test public void testServerDescriptorFamilyInvalidFingerprint() throws Exception { - this.defaultServerDescriptorBuilder.insertBeforeLineStartingWith( + this.defaultServerTestDescriptorBuilder.insertBeforeLineStartingWith( "hidden-service-dir", Arrays.asList("family $0")); this.runTest(); assertTrue("Sanitized server descriptor with invalid fingerprint in " @@ -446,8 +451,8 @@ public class SanitizedBridgesWriterTest { "true"); String fingerprintLine = "fingerprint 46D4 A711 97B8 FA51 5A82 6C6B 017C 522F E264 655B"; - this.defaultServerDescriptorBuilder.removeLine(fingerprintLine); - this.defaultServerDescriptorBuilder.insertBeforeLineStartingWith( + this.defaultServerTestDescriptorBuilder.removeLine(fingerprintLine); + this.defaultServerTestDescriptorBuilder.insertBeforeLineStartingWith( "published ", Arrays.asList(fingerprintLine)); this.runTest(); assertFalse(this.parsedServerDescriptors.isEmpty()); @@ -493,7 +498,7 @@ public class SanitizedBridgesWriterTest { @Test public void testExtraInfoDescriptorExtraInfoLineTruncated() throws Exception { - this.defaultExtraInfoDescriptorBuilder.replaceLineStartingWith( + this.defaultExtraInfoTestDescriptorBuilder.replaceLineStartingWith( "extra-info ", Arrays.asList("extra-info ")); this.runTest(); } @@ -501,7 +506,7 @@ public class SanitizedBridgesWriterTest { @Test public void testExtraInfoDescriptorExtraInfoInvalidHex() throws Exception { - this.defaultExtraInfoDescriptorBuilder.replaceLineStartingWith( + this.defaultExtraInfoTestDescriptorBuilder.replaceLineStartingWith( "extra-info ", Arrays.asList("extra-info MeekGoogle 4")); this.runTest(); assertTrue("Sanitized extra-info descriptor with invalid extra-info " @@ -510,7 +515,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testExtraInfoDescriptorTransportSpace() throws Exception { - this.defaultExtraInfoDescriptorBuilder.replaceLineStartingWith( + this.defaultExtraInfoTestDescriptorBuilder.replaceLineStartingWith( "transport ", Arrays.asList("transport ")); this.runTest(); assertTrue("Sanitized extra-info descriptor with invalid transport " @@ -519,7 +524,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testExtraInfoDescriptorTransportInfoRemoved() throws Exception { - this.defaultExtraInfoDescriptorBuilder.insertBeforeLineStartingWith( + this.defaultExtraInfoTestDescriptorBuilder.insertBeforeLineStartingWith( "bridge-stats-end ", Arrays.asList("transport-info secretkey")); this.runTest(); for (String line : this.parsedExtraInfoDescriptors.get(0)) { @@ -530,7 +535,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testExtraInfoDescriptorHidservRetained() throws Exception { - this.defaultExtraInfoDescriptorBuilder.insertBeforeLineStartingWith( + this.defaultExtraInfoTestDescriptorBuilder.insertBeforeLineStartingWith( "transport ", Arrays.asList("hidserv-stats-end 2016-11-23 14:48:05 (86400 s)", "hidserv-rend-relayed-cells 27653088 delta_f=2048 epsilon=0.30 " @@ -551,7 +556,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testExtraInfoDescriptorPaddingCountsRetained() throws Exception { - this.defaultExtraInfoDescriptorBuilder.insertBeforeLineStartingWith( + this.defaultExtraInfoTestDescriptorBuilder.insertBeforeLineStartingWith( "transport ", Arrays.asList("padding-counts 2017-05-10 01:48:43 (86400 s) " + "bin-size=10000 write-drop=10000 write-pad=10000 " @@ -575,7 +580,7 @@ public class SanitizedBridgesWriterTest { @Test public void testExtraInfoDescriptorRouterSignatureLineSpace() throws Exception { - this.defaultExtraInfoDescriptorBuilder.replaceLineStartingWith( + this.defaultExtraInfoTestDescriptorBuilder.replaceLineStartingWith( "router-signature", Arrays.asList("router-signature ")); this.runTest(); assertTrue("Sanitized extra-info descriptor with invalid " @@ -609,7 +614,7 @@ public class SanitizedBridgesWriterTest {
@Test public void testNetworkStatusPublishedLineMissing() throws Exception { - this.defaultNetworkStatusBuilder.removeLine( + this.defaultNetworkStatusTestDescriptorBuilder.removeLine( "published 2016-06-30 23:40:28"); this.runTest(); String sanitizedNetworkStatusFileName = "2016/07/statuses/01/" @@ -622,9 +627,9 @@ public class SanitizedBridgesWriterTest { @Test public void testNetworkStatusPublishedLineMissingTarballFileNameChange() throws Exception { - this.defaultNetworkStatusBuilder.removeLine( + this.defaultNetworkStatusTestDescriptorBuilder.removeLine( "published 2016-06-30 23:40:28"); - this.defaultTarballBuilder.setTarballFileName( + this.defaultTarballTestBuilder.setTarballFileName( "from-tonga-with-love-2016-07-01T000702Z.tar.gz"); this.runTest(); assertTrue("Sanitized network status without published line and with " @@ -633,14 +638,14 @@ public class SanitizedBridgesWriterTest {
@Test public void testNetworkStatusRlineTruncated() throws Exception { - this.defaultNetworkStatusBuilder.replaceLineStartingWith("r ", + this.defaultNetworkStatusTestDescriptorBuilder.replaceLineStartingWith("r ", Arrays.asList("r MeekGoogle")); this.runTest(); }
@Test public void testNetworkStatusRlineInvalidBase64() throws Exception { - this.defaultNetworkStatusBuilder.replaceLineStartingWith("r ", + this.defaultNetworkStatusTestDescriptorBuilder.replaceLineStartingWith("r ", Arrays.asList("r MeekGoogle R#SnE*e4+lFag:xr_XxSL+J;ZVs " + "g+M7'w+lG$mv6NW9&RmvzLO(R0Y 2016-06-30 21:43:52 " + "198.50.200.131 8008 0")); @@ -653,8 +658,8 @@ public class SanitizedBridgesWriterTest { public void testNetworkStatusAlinePortMissing() throws Exception { this.configuration.setProperty(Key.ReplaceIpAddressesWithHashes.name(), "true"); - this.defaultNetworkStatusBuilder.insertBeforeLineStartingWith("s ", - Arrays.asList("a 198.50.200.132")); + this.defaultNetworkStatusTestDescriptorBuilder + .insertBeforeLineStartingWith("s ", Arrays.asList("a 198.50.200.132")); this.runTest(); for (String line : this.parsedNetworkStatuses.get(0)) { if (line.startsWith("a ")) { @@ -665,8 +670,8 @@ public class SanitizedBridgesWriterTest {
@Test public void testNetworkStatusVLineUnknown() throws Exception { - this.defaultNetworkStatusBuilder.insertBeforeLineStartingWith("w ", - Arrays.asList("v Tor 0.2.7.6")); + this.defaultNetworkStatusTestDescriptorBuilder + .insertBeforeLineStartingWith("w ", Arrays.asList("v Tor 0.2.7.6")); this.runTest(); assertTrue("Should not have sanitized status with v line which is unknown " + "in this descriptor type.", this.parsedNetworkStatuses.isEmpty()); @@ -674,7 +679,8 @@ public class SanitizedBridgesWriterTest {
@Test public void testNetworkStatusNoEntry() throws Exception { - this.defaultNetworkStatusBuilder.truncateAtLineStartingWith("r "); + this.defaultNetworkStatusTestDescriptorBuilder + .truncateAtLineStartingWith("r "); this.runTest(); assertFalse("Skipped network status without entries.", this.parsedNetworkStatuses.isEmpty()); @@ -687,8 +693,8 @@ public class SanitizedBridgesWriterTest {
@Test public void testNetworkStatusFromBifroest() throws Exception { - this.defaultTarballBuilder.setTarballFileName( - this.defaultTarballBuilder.getTarballFileName() + this.defaultTarballTestBuilder.setTarballFileName( + this.defaultTarballTestBuilder.getTarballFileName() .replaceAll("tonga", "bifroest")); this.runTest(); assertTrue("Sanitized status should contain Bifroest's fingerprint.", @@ -698,8 +704,8 @@ public class SanitizedBridgesWriterTest {
@Test public void testNetworkStatusFromTrifroest() throws Exception { - this.defaultTarballBuilder.setTarballFileName( - this.defaultTarballBuilder.getTarballFileName() + this.defaultTarballTestBuilder.setTarballFileName( + this.defaultTarballTestBuilder.getTarballFileName() .replaceAll("tonga", "trifroest")); this.runTest(); assertTrue("Should not have recognized unknown bridge authority Trifroest.", @@ -708,9 +714,9 @@ public class SanitizedBridgesWriterTest {
@Test public void testTarballContainsSameFileTwice() throws Exception { - this.defaultTarballBuilder.add("cached-extrainfo.new", 1467331623000L, - Arrays.asList(new DescriptorBuilder[] { - this.defaultExtraInfoDescriptorBuilder })); + this.defaultTarballTestBuilder.add("cached-extrainfo.new", 1467331623000L, + Arrays.asList(new TestDescriptorBuilder[] { + this.defaultExtraInfoTestDescriptorBuilder })); this.runTest(); assertEquals("There should only be one.", 1, this.parsedExtraInfoDescriptors.size()); diff --git a/src/test/java/org/torproject/collector/bridgedescs/ServerDescriptorBuilder.java b/src/test/java/org/torproject/collector/bridgedescs/ServerTestDescriptorBuilder.java similarity index 97% rename from src/test/java/org/torproject/collector/bridgedescs/ServerDescriptorBuilder.java rename to src/test/java/org/torproject/collector/bridgedescs/ServerTestDescriptorBuilder.java index e49e126..b23c9e9 100644 --- a/src/test/java/org/torproject/collector/bridgedescs/ServerDescriptorBuilder.java +++ b/src/test/java/org/torproject/collector/bridgedescs/ServerTestDescriptorBuilder.java @@ -8,10 +8,10 @@ import java.util.Arrays; /** Builds a non-sanitized bridge server descriptor that comes with an original * bridge descriptor (of a bundled and therefore publicly known bridge) by * default. */ -class ServerDescriptorBuilder extends DescriptorBuilder { +class ServerTestDescriptorBuilder extends TestDescriptorBuilder {
/** Initializes the descriptor builder. */ - ServerDescriptorBuilder() { + ServerTestDescriptorBuilder() { this.addAll(Arrays.asList( "@purpose bridge", "router MeekGoogle 198.50.200.131 8008 0 0", diff --git a/src/test/java/org/torproject/collector/bridgedescs/TarballBuilder.java b/src/test/java/org/torproject/collector/bridgedescs/TarballTestBuilder.java similarity index 91% rename from src/test/java/org/torproject/collector/bridgedescs/TarballBuilder.java rename to src/test/java/org/torproject/collector/bridgedescs/TarballTestBuilder.java index c85e93b..2cfe0f5 100644 --- a/src/test/java/org/torproject/collector/bridgedescs/TarballBuilder.java +++ b/src/test/java/org/torproject/collector/bridgedescs/TarballTestBuilder.java @@ -22,7 +22,7 @@ import java.util.Map; /** Builds a tarball containing non-sanitized bridge descriptors built using * descriptor builders and writes the tarball to a new file with the given file * name. */ -class TarballBuilder { +class TarballTestBuilder {
/** Internal helper class to store details about a file contained in the * tarball. */ @@ -32,7 +32,7 @@ class TarballBuilder { private long modifiedMillis;
/** Descriptor builders used to generate the file content. */ - private List<DescriptorBuilder> descriptorBuilders; + private List<TestDescriptorBuilder> descriptorBuilders; }
/** File name of the tarball. */ @@ -54,7 +54,7 @@ class TarballBuilder {
/** Initializes a new tarball builder that is going to write a tarball to the * file with given file name and last-modified time. */ - TarballBuilder(String tarballFileName, long modifiedMillis) { + TarballTestBuilder(String tarballFileName, long modifiedMillis) { this.tarballFileName = tarballFileName; this.modifiedMillis = modifiedMillis; this.tarballFiles = new LinkedHashMap<>(); @@ -62,8 +62,8 @@ class TarballBuilder {
/** Adds a new file to the tarball with given name, last-modified time, and * descriptor builders to generate the file content. */ - TarballBuilder add(String fileName, long modifiedMillis, - List<DescriptorBuilder> descriptorBuilders) throws IOException { + TarballTestBuilder add(String fileName, long modifiedMillis, + List<TestDescriptorBuilder> descriptorBuilders) throws IOException { TarballFile file = new TarballFile(); file.modifiedMillis = modifiedMillis; file.descriptorBuilders = descriptorBuilders; @@ -91,7 +91,7 @@ class TarballBuilder { for (Map.Entry<String, TarballFile> file : this.tarballFiles.entrySet()) { TarArchiveEntry tae = new TarArchiveEntry(file.getKey()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - for (DescriptorBuilder descriptorBuilder + for (TestDescriptorBuilder descriptorBuilder : file.getValue().descriptorBuilders) { descriptorBuilder.build(baos); } diff --git a/src/test/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java b/src/test/java/org/torproject/collector/bridgedescs/TestDescriptorBuilder.java similarity index 97% rename from src/test/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java rename to src/test/java/org/torproject/collector/bridgedescs/TestDescriptorBuilder.java index eaa6335..73c00b7 100644 --- a/src/test/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java +++ b/src/test/java/org/torproject/collector/bridgedescs/TestDescriptorBuilder.java @@ -14,7 +14,7 @@ import java.util.List;
/** Builds a descriptor by concatenating the given lines with newlines and * writing the output to the given output stream. */ -abstract class DescriptorBuilder extends ArrayList<String> { +abstract class TestDescriptorBuilder extends ArrayList<String> {
/** Removes the given line, or fails if that line cannot be found. */ void removeLine(String line) {
tor-commits@lists.torproject.org