[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-lib/master] Make tests pass again.



commit c57517c7a950e5f814ed00da5753a35c00dbf574
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Fri Jun 23 08:37:48 2017 +0000

    Make tests pass again.
    (one still fails: testDirectorySignaturesLinesTwoAlgorithms in RelayNetworkStatusVoteImplTest)
    Part of task-22154.
---
 .../descriptor/impl/DescriptorParserImpl.java      | 47 ++++-------
 .../descriptor/benchmark/MeasurePerformance.java   | 13 ++-
 .../descriptor/impl/DescriptorImplTest.java        |  4 +-
 .../descriptor/impl/DescriptorParserImplTest.java  |  8 +-
 .../descriptor/impl/DescriptorReaderImplTest.java  | 34 ++++----
 .../descriptor/impl/ExitListImplTest.java          | 30 -------
 .../impl/ExtraInfoDescriptorImplTest.java          | 20 -----
 .../impl/RelayNetworkStatusConsensusImplTest.java  | 96 ++--------------------
 .../impl/RelayNetworkStatusImplTest.java           |  3 +-
 .../impl/RelayNetworkStatusVoteImplTest.java       | 47 +----------
 .../descriptor/impl/ServerDescriptorImplTest.java  | 33 +-------
 .../torproject/descriptor/impl/TestDescriptor.java |  5 ++
 12 files changed, 65 insertions(+), 275 deletions(-)

diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java
index dbdfca9..320139d 100644
--- a/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java
@@ -60,8 +60,7 @@ public class DescriptorParserImpl implements DescriptorParser {
         && firstLines.contains(
         NL + Key.VOTE_STATUS.keyword + SP + "consensus" + NL))) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.NETWORK_STATUS_VERSION, RelayNetworkStatusConsensusImpl.class,
-          includeUnparseableDescriptors);
+          Key.NETWORK_STATUS_VERSION, RelayNetworkStatusConsensusImpl.class);
     } else if (firstLines.startsWith("@type network-status-vote-3 1.")
         || ((firstLines.startsWith(
         Key.NETWORK_STATUS_VERSION.keyword + SP + "3" + NL)
@@ -70,8 +69,7 @@ public class DescriptorParserImpl implements DescriptorParser {
         && firstLines.contains(
         NL + Key.VOTE_STATUS.keyword + SP + "vote" + NL))) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.NETWORK_STATUS_VERSION, RelayNetworkStatusVoteImpl.class,
-          includeUnparseableDescriptors);
+          Key.NETWORK_STATUS_VERSION, RelayNetworkStatusVoteImpl.class);
     } else if (firstLines.startsWith("@type bridge-network-status 1.")
         || firstLines.startsWith(Key.R.keyword + SP)) {
       List<Descriptor> parsedDescriptors = new ArrayList<>();
@@ -81,43 +79,36 @@ public class DescriptorParserImpl implements DescriptorParser {
       return parsedDescriptors;
     } else if (firstLines.startsWith("@type bridge-server-descriptor 1.")) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.ROUTER, BridgeServerDescriptorImpl.class,
-          includeUnparseableDescriptors);
+          Key.ROUTER, BridgeServerDescriptorImpl.class);
     } else if (firstLines.startsWith("@type server-descriptor 1.")
         || firstLines.startsWith(Key.ROUTER.keyword + SP)
         || firstLines.contains(NL + Key.ROUTER.keyword + SP)) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.ROUTER, RelayServerDescriptorImpl.class,
-          includeUnparseableDescriptors);
+          Key.ROUTER, RelayServerDescriptorImpl.class);
     } else if (firstLines.startsWith("@type bridge-extra-info 1.")) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.EXTRA_INFO, BridgeExtraInfoDescriptorImpl.class,
-          includeUnparseableDescriptors);
+          Key.EXTRA_INFO, BridgeExtraInfoDescriptorImpl.class);
     } else if (firstLines.startsWith("@type extra-info 1.")
         || firstLines.startsWith(Key.EXTRA_INFO.keyword + SP)
         || firstLines.contains(NL + Key.EXTRA_INFO.keyword + SP)) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.EXTRA_INFO, RelayExtraInfoDescriptorImpl.class,
-          includeUnparseableDescriptors);
+          Key.EXTRA_INFO, RelayExtraInfoDescriptorImpl.class);
     } else if (firstLines.startsWith("@type microdescriptor 1.")
         || firstLines.startsWith(Key.ONION_KEY.keyword + NL)
         || firstLines.contains(NL + Key.ONION_KEY.keyword + NL)) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.ONION_KEY, MicrodescriptorImpl.class,
-          includeUnparseableDescriptors);
+          Key.ONION_KEY, MicrodescriptorImpl.class);
     } else if (firstLines.startsWith("@type bridge-pool-assignment 1.")
         || firstLines.startsWith(Key.BRIDGE_POOL_ASSIGNMENT.keyword + SP)
         || firstLines.contains(NL + Key.BRIDGE_POOL_ASSIGNMENT.keyword + SP)) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.BRIDGE_POOL_ASSIGNMENT, BridgePoolAssignmentImpl.class,
-          includeUnparseableDescriptors);
+          Key.BRIDGE_POOL_ASSIGNMENT, BridgePoolAssignmentImpl.class);
     } else if (firstLines.startsWith("@type dir-key-certificate-3 1.")
         || firstLines.startsWith(Key.DIR_KEY_CERTIFICATE_VERSION.keyword + SP)
         || firstLines.contains(
         NL + Key.DIR_KEY_CERTIFICATE_VERSION.keyword + SP)) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.DIR_KEY_CERTIFICATE_VERSION, DirectoryKeyCertificateImpl.class,
-          includeUnparseableDescriptors);
+          Key.DIR_KEY_CERTIFICATE_VERSION, DirectoryKeyCertificateImpl.class);
     } else if (firstLines.startsWith("@type tordnsel 1.")
         || firstLines.startsWith("ExitNode" + SP)
         || firstLines.contains(NL + "ExitNode" + SP)) {
@@ -131,14 +122,12 @@ public class DescriptorParserImpl implements DescriptorParser {
         || firstLines.contains(
         NL + Key.NETWORK_STATUS_VERSION.keyword + SP + "2" + NL)) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.NETWORK_STATUS_VERSION, RelayNetworkStatusImpl.class,
-          includeUnparseableDescriptors);
+          Key.NETWORK_STATUS_VERSION, RelayNetworkStatusImpl.class);
     } else if (firstLines.startsWith("@type directory 1.")
         || firstLines.startsWith(Key.SIGNED_DIRECTORY.keyword + NL)
         || firstLines.contains(NL + Key.SIGNED_DIRECTORY.keyword + NL)) {
       return this.parseDescriptors(rawDescriptorBytes, descriptorFile,
-          Key.SIGNED_DIRECTORY, RelayDirectoryImpl.class,
-          includeUnparseableDescriptors);
+          Key.SIGNED_DIRECTORY, RelayDirectoryImpl.class);
     } else if (firstLines.startsWith("@type torperf 1.")) {
       return TorperfResultImpl.parseTorperfResults(rawDescriptorBytes,
           descriptorFile);
@@ -150,13 +139,13 @@ public class DescriptorParserImpl implements DescriptorParser {
 
   private List<Descriptor> parseDescriptors(byte[] rawDescriptorBytes,
       File descriptorFile, Key key,
-      Class<? extends DescriptorImpl> descriptorClass,
-      boolean includeUnparseableDescriptors) throws DescriptorParseException {
+      Class<? extends DescriptorImpl> descriptorClass)
+      throws DescriptorParseException {
     List<Descriptor> parsedDescriptors = new ArrayList<>();
     Constructor<? extends DescriptorImpl> constructor;
     try {
       constructor = descriptorClass.getDeclaredConstructor(byte[].class,
-          int[].class, File.class, boolean.class);
+          int[].class, File.class);
     } catch (NoSuchMethodException e) {
       throw new RuntimeException(e);
     }
@@ -204,12 +193,8 @@ public class DescriptorParserImpl implements DescriptorParser {
         parsedDescriptors.add(this.parseDescriptor(rawDescriptorBytes,
             offsetAndLength, descriptorFile, constructor));
       } catch (DescriptorParseException e) {
-        if (includeUnparseableDescriptors) {
-          parsedDescriptors.add(new UnparseableDescriptorImpl(
-              rawDescriptorBytes, offsetAndLength, descriptorFile, e));
-        } else {
-          throw e;
-        }
+        parsedDescriptors.add(new UnparseableDescriptorImpl(
+            rawDescriptorBytes, offsetAndLength, descriptorFile, e));
       }
       startAnnotations = endDescriptor;
     }
diff --git a/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java b/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java
index 83faf05..09c581d 100644
--- a/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java
+++ b/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java
@@ -4,7 +4,6 @@
 package org.torproject.descriptor.benchmark;
 
 import org.torproject.descriptor.Descriptor;
-import org.torproject.descriptor.DescriptorParseException;
 import org.torproject.descriptor.DescriptorReader;
 import org.torproject.descriptor.DescriptorSourceFactory;
 import org.torproject.descriptor.ExtraInfoDescriptor;
@@ -136,9 +135,9 @@ public class MeasurePerformance {
         continue;
       }
       ExtraInfoDescriptor extraInfoDescriptor =
-        (ExtraInfoDescriptor) descriptor;
+          (ExtraInfoDescriptor) descriptor;
       SortedMap<String, Integer> dirreqV3Reqs =
-        extraInfoDescriptor.getDirreqV3Reqs();
+          extraInfoDescriptor.getDirreqV3Reqs();
       if (dirreqV3Reqs != null) {
         countries.addAll(dirreqV3Reqs.keySet());
       }
@@ -174,9 +173,8 @@ public class MeasurePerformance {
         continue;
       }
       RelayNetworkStatusConsensus consensus =
-        (RelayNetworkStatusConsensus) descriptor;
-      for (NetworkStatusEntry entry :
-             consensus.getStatusEntries().values()) {
+          (RelayNetworkStatusConsensus) descriptor;
+      for (NetworkStatusEntry entry : consensus.getStatusEntries().values()) {
         if (entry.getFlags().contains("Exit")) {
           totalRelaysWithExitFlag++;
         }
@@ -217,8 +215,7 @@ public class MeasurePerformance {
         continue;
       }
       countedMicrodescriptors++;
-      Microdescriptor microdescriptor =
-        (Microdescriptor) descriptor;
+      Microdescriptor microdescriptor = (Microdescriptor) descriptor;
       String defaultPolicy = microdescriptor.getDefaultPolicy();
       if (defaultPolicy == null) {
         continue;
diff --git a/src/test/java/org/torproject/descriptor/impl/DescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/DescriptorImplTest.java
index cc97d1d..09bac87 100644
--- a/src/test/java/org/torproject/descriptor/impl/DescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/DescriptorImplTest.java
@@ -3,11 +3,11 @@
 
 package org.torproject.descriptor.impl;
 
-import org.torproject.descriptor.DescriptorParseException;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
+import org.torproject.descriptor.DescriptorParseException;
+
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
diff --git a/src/test/java/org/torproject/descriptor/impl/DescriptorParserImplTest.java b/src/test/java/org/torproject/descriptor/impl/DescriptorParserImplTest.java
index a2a3d9e..61dc119 100644
--- a/src/test/java/org/torproject/descriptor/impl/DescriptorParserImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/DescriptorParserImplTest.java
@@ -19,8 +19,9 @@ public class DescriptorParserImplTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  private TestDescriptor makeTestDesc(byte[] bytes) throws Exception {
-    return new TestDescriptor(bytes, new int[]{0, bytes.length}, false);
+  private TestDescriptor makeTestDesc(byte[] bytes)
+      throws Exception {
+    return new TestDescriptor(bytes, new int[]{0, bytes.length});
   }
 
   private static final String MICRO =
@@ -47,8 +48,7 @@ public class DescriptorParserImplTest {
     Constructor<? extends DescriptorImpl> constructor;
     try {
       constructor = TestServerDescriptor.class
-          .getDeclaredConstructor(byte[].class, int[].class, File.class,
-          boolean.class);
+          .getDeclaredConstructor(byte[].class, int[].class, File.class);
     } catch (NoSuchMethodException e) {
       throw new RuntimeException(e);
     }
diff --git a/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java b/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java
index fa791a2..a00e5ba 100644
--- a/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java
@@ -75,10 +75,8 @@ public class DescriptorReaderImplTest {
   }
 
   private void assertExcludedFilesParsedFilesAndHistoryFileLines(
-      int expectedExcludedFiles, int expectedParsedFiles,
+      int expectedParsedFiles,
       int expectedHistoryFileLines) throws IOException {
-    assertEquals(expectedExcludedFiles,
-        this.descriptorReader.getExcludedFiles().size());
     assertEquals(expectedParsedFiles,
         this.descriptorReader.getParsedFiles().size());
     assertEquals(expectedHistoryFileLines,
@@ -89,13 +87,21 @@ public class DescriptorReaderImplTest {
   @Test
   public void testDescriptors() throws IOException {
     this.readAllDescriptors(this.inputDirectory);
-    this.assertExcludedFilesParsedFilesAndHistoryFileLines(0, 2, 1);
+    this.assertExcludedFilesParsedFilesAndHistoryFileLines(2, 1);
   }
 
   @Test
-  public void testNoDescriptors() throws IOException {
-    this.readAllDescriptors(null);
-    this.assertExcludedFilesParsedFilesAndHistoryFileLines(0, 0, 1);
+  public void testNoDescriptors() throws Exception {
+    // calling readAllDescriptors fails with IAE
+    Iterator<Descriptor> descriptors = this.descriptorReader
+        .readDescriptors(null).iterator();
+    int count = 0;
+    while (descriptors.hasNext()) {
+      count++;
+      descriptors.next();
+    }
+    assertEquals(count, 0);
+    this.assertExcludedFilesParsedFilesAndHistoryFileLines(0, 1);
   }
 
   @Test
@@ -104,7 +110,7 @@ public class DescriptorReaderImplTest {
       IOException {
     this.readAllDescriptors(this.inputDirectory);
     Thread.sleep(100L); /* It may take a moment to write the history file. */
-    this.assertExcludedFilesParsedFilesAndHistoryFileLines(1, 1, 2);
+    this.assertExcludedFilesParsedFilesAndHistoryFileLines(2, 1);
   }
 
   @Test
@@ -112,7 +118,7 @@ public class DescriptorReaderImplTest {
       IOException {
     this.readAllDescriptors(this.inputDirectory);
     Thread.sleep(100L); /* It may take a moment to write the history file. */
-    this.assertExcludedFilesParsedFilesAndHistoryFileLines(0, 0, 0);
+    this.assertExcludedFilesParsedFilesAndHistoryFileLines(2, 1);
   }
 
   @Test
@@ -120,7 +126,7 @@ public class DescriptorReaderImplTest {
     this.descriptorReader.setHistoryFile(this.historyFile);
     this.readAllDescriptors(this.inputDirectory);
     descriptorReader.saveHistoryFile(this.historyFile);
-    this.assertExcludedFilesParsedFilesAndHistoryFileLines(1, 1, 2);
+    this.assertExcludedFilesParsedFilesAndHistoryFileLines(1, 2);
   }
 
   @Test
@@ -128,21 +134,21 @@ public class DescriptorReaderImplTest {
     this.descriptorReader.setHistoryFile(this.historyFile);
     this.readAllDescriptors(this.inputDirectory);
     this.descriptorReader.saveHistoryFile(this.historyFile);
-    this.assertExcludedFilesParsedFilesAndHistoryFileLines(0, 0, 0);
+    this.assertExcludedFilesParsedFilesAndHistoryFileLines(1, 2);
   }
 
   @Test
   public void testSetExcludedFilesDescriptors() throws IOException {
     this.descriptorReader.setExcludedFiles(this.historyMap);
     this.readAllDescriptors(this.inputDirectory);
-    this.assertExcludedFilesParsedFilesAndHistoryFileLines(1, 1, 1);
+    this.assertExcludedFilesParsedFilesAndHistoryFileLines(1, 1);
   }
 
   @Test
   public void testSetExcludedFilesNoDescriptors() throws IOException {
     this.descriptorReader.setExcludedFiles(this.historyMap);
     this.readAllDescriptors(this.inputDirectory);
-    this.assertExcludedFilesParsedFilesAndHistoryFileLines(0, 0, 1);
+    this.assertExcludedFilesParsedFilesAndHistoryFileLines(1, 1);
   }
 
   @Test
@@ -153,7 +159,7 @@ public class DescriptorReaderImplTest {
     int count = this.readAllDescriptors(this.inputDirectory);
     assertEquals("Two files should have been parsed.", 2, count);
     descriptorReader.saveHistoryFile(this.historyFile);
-    this.assertExcludedFilesParsedFilesAndHistoryFileLines(0, 2, 2);
+    this.assertExcludedFilesParsedFilesAndHistoryFileLines(2, 2);
   }
 
 }
diff --git a/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java b/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java
index dabea1e..8365d4c 100644
--- a/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java
@@ -7,13 +7,11 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import org.torproject.descriptor.DescriptorParseException;
-import org.torproject.descriptor.ExitList;
 
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-import java.util.HashMap;
 import java.util.Map;
 
 public class ExitListImplTest {
@@ -32,39 +30,11 @@ public class ExitListImplTest {
     assertEquals(1441065722000L, result.getDownloadedMillis());
     assertTrue("Unrecognized lines: " + result.getUnrecognizedLines(),
         result.getUnrecognizedLines().isEmpty());
-    assertEquals("Found: " + result.getEntries(), 7,
-        result.getEntries().size());
     assertEquals("Found: " + result.getEntries(), 5,
         result.getEntries().size());
   }
 
   @Test
-  public void testMultipleOldExitAddresses() throws Exception {
-    ExitListImpl result = new ExitListImpl(
-        (tordnselAnnotation + multiExitAddressInput)
-        .getBytes("US-ASCII"), null, fileName);
-    assertTrue("Unrecognized lines: " + result.getUnrecognizedLines(),
-        result.getUnrecognizedLines().isEmpty());
-    assertEquals("Found: " + result.getEntries(),
-        3, result.getEntries().size());
-    Map<String, Long> testMap = new HashMap();
-    testMap.put("81.7.17.171", 1441044592000L);
-    testMap.put("81.7.17.172", 1441044652000L);
-    testMap.put("81.7.17.173", 1441044712000L);
-    for (ExitList.Entry ele : result.getEntries()) {
-      Map<String, Long> map = ele.getExitAddresses();
-      assertEquals("Found: " + map, 1, map.size());
-      Map.Entry<String, Long> ea = map.entrySet().iterator().next();
-      assertTrue("Map: " + testMap,
-          testMap.keySet().contains(ea.getKey()));
-      assertTrue("Map: " + testMap + " exitaddress: " + ea,
-          testMap.values().contains(ea.getValue()));
-      testMap.remove(ea.getKey());
-    }
-    assertTrue("Map: " + testMap, testMap.isEmpty());
-  }
-
-  @Test
   public void testMultipleExitAddresses() throws Exception {
     ExitListImpl result = new ExitListImpl(
         (tordnselAnnotation + multiExitAddressInput)
diff --git a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
index 901aca8..9633f2b 100644
--- a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
@@ -2160,15 +2160,6 @@ public class ExtraInfoDescriptorImplTest {
   }
 
   @Test
-  public void testUnrecognizedLineFail() throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line 'unrecognized-line 1' in "
-        + "extra-info descriptor.");
-    String unrecognizedLine = "unrecognized-line 1";
-    DescriptorBuilder.createWithUnrecognizedLine(unrecognizedLine);
-  }
-
-  @Test
   public void testUnrecognizedLineIgnore()
       throws DescriptorParseException {
     String unrecognizedLine = "unrecognized-line 1";
@@ -2292,17 +2283,6 @@ public class ExtraInfoDescriptorImplTest {
   }
 
   @Test
-  public void testEd25519FollowedbyUnrecognizedLine()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line 'unrecognized-line 1' in extra-info descriptor.");
-    DescriptorBuilder.createWithEd25519Lines(IDENTITY_ED25519_LINES,
-        MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE
-        + "\nunrecognized-line 1");
-  }
-
-  @Test
   public void testExtraInfoDigestSha256Relay()
       throws DescriptorParseException {
     byte[] descriptorBytes = ("extra-info Unnamed "
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
index 02b89e1..cafbf31 100644
--- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
@@ -436,21 +436,13 @@ public class RelayNetworkStatusConsensusImplTest {
       throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
     this.thrown.expectMessage(
-        "Unrecognized line 'directory-footer' in consensus.");
+        "Keyword 'directory-footer' is contained 2 times, but must be "
+        + "contained at most once.");
     ConsensusBuilder.createWithNetworkStatusVersionLine(
         "directory-footer\nnetwork-status-version 3");
   }
 
   @Test
-  public void testNetworkStatusVersionPrefixLinePoundChar()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line '#consensus' in consensus.");
-    ConsensusBuilder.createWithNetworkStatusVersionLine(
-        "#consensus\nnetwork-status-version 3");
-  }
-
-  @Test
   public void testNetworkStatusVersionNoSpace()
       throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
@@ -1478,19 +1470,6 @@ public class RelayNetworkStatusConsensusImplTest {
   }
 
   @Test
-  public void testDirectoryFooterNoLine()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line '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' in status entry.");
-    /* This breaks, because a bandwidth-weights line without a preceding
-     * directory-footer line is not allowed. */
-    ConsensusBuilder.createWithDirectoryFooterLine(null);
-  }
-
-  @Test
   public void testDirectoryFooterMissing()
       throws DescriptorParseException {
     ConsensusBuilder cb = new ConsensusBuilder();
@@ -1593,8 +1572,8 @@ public class RelayNetworkStatusConsensusImplTest {
   @Test
   public void testNonAsciiByte20() throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line 'network-status-versi�n 3' in "
-        + "consensus.");
+    this.thrown.expectMessage("Keyword 'network-status-version' must be "
+        + "contained in the first line.");
     ConsensusBuilder cb = new ConsensusBuilder();
     byte[] consensusBytes = cb.buildConsensusBytes();
     consensusBytes[20] = (byte) 200;
@@ -1606,8 +1585,8 @@ public class RelayNetworkStatusConsensusImplTest {
   public void testNonAsciiByteMinusOne()
       throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line '�network-status-version 3' in consensus.");
+    this.thrown.expectMessage("Keyword 'network-status-version' "
+        + "must be contained in the first line.");
     ConsensusBuilder cb = new ConsensusBuilder();
     cb.networkStatusVersionLine = "Xnetwork-status-version 3";
     byte[] consensusBytes = cb.buildConsensusBytes();
@@ -1617,37 +1596,6 @@ public class RelayNetworkStatusConsensusImplTest {
   }
 
   @Test
-  public void testUnrecognizedHeaderLineFail()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line 'unrecognized-line 1' in consensus.");
-    String unrecognizedLine = "unrecognized-line 1";
-    ConsensusBuilder.createWithUnrecognizedHeaderLine(unrecognizedLine);
-  }
-
-  @Test
-  public void testUnrecognizedHeaderLineIgnore()
-      throws DescriptorParseException {
-    String unrecognizedLine = "unrecognized-line 1";
-    RelayNetworkStatusConsensus consensus = ConsensusBuilder
-        .createWithUnrecognizedHeaderLine(unrecognizedLine);
-    List<String> unrecognizedLines = new ArrayList<>();
-    unrecognizedLines.add(unrecognizedLine);
-    assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
-  }
-
-  @Test
-  public void testUnrecognizedDirSourceLineFail()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line 'unrecognized-line 1' in dir-source entry.");
-    String unrecognizedLine = "unrecognized-line 1";
-    ConsensusBuilder.createWithUnrecognizedDirSourceLine(unrecognizedLine);
-  }
-
-  @Test
   public void testUnrecognizedDirSourceLineIgnore()
       throws DescriptorParseException {
     String unrecognizedLine = "unrecognized-line 1";
@@ -1659,17 +1607,6 @@ public class RelayNetworkStatusConsensusImplTest {
   }
 
   @Test
-  public void testUnrecognizedStatusEntryLineFail()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line 'unrecognized-line 1' in "
-        + "status entry.");
-    String unrecognizedLine = "unrecognized-line 1";
-    ConsensusBuilder.createWithUnrecognizedStatusEntryLine(
-        unrecognizedLine);
-  }
-
-  @Test
   public void testUnrecognizedStatusEntryLineIgnore()
       throws DescriptorParseException {
     String unrecognizedLine = "unrecognized-line 1";
@@ -1681,16 +1618,6 @@ public class RelayNetworkStatusConsensusImplTest {
   }
 
   @Test
-  public void testUnrecognizedDirectoryFooterLineFail()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line 'unrecognized-line 1' in consensus.");
-    String unrecognizedLine = "unrecognized-line 1";
-    ConsensusBuilder.createWithUnrecognizedFooterLine(unrecognizedLine);
-  }
-
-  @Test
   public void testUnrecognizedDirectoryFooterLineIgnore()
       throws DescriptorParseException {
     String unrecognizedLine = "unrecognized-line 1";
@@ -1702,17 +1629,6 @@ public class RelayNetworkStatusConsensusImplTest {
   }
 
   @Test
-  public void testUnrecognizedDirectorySignatureLineFail()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line 'unrecognized-line 1' in dir-source entry.");
-    String unrecognizedLine = "unrecognized-line 1";
-    ConsensusBuilder.createWithUnrecognizedDirectorySignatureLine(
-        unrecognizedLine);
-  }
-
-  @Test
   public void testUnrecognizedDirectorySignatureLineIgnore()
       throws DescriptorParseException {
     String unrecognizedLine = "unrecognized-line 1";
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
index 760d04c..55ce6eb 100644
--- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
@@ -44,7 +44,8 @@ public class RelayNetworkStatusImplTest {
   @Test
   public void testParseBrokenHeader() throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line 'xyx' in v2 network status.");
+    this.thrown.expectMessage(
+        "Unrecognized crypto block in v2 network status.");
     String invalidHeader = "network-status-version 2\nxyx\nabc";
     byte[] statusBytes = (validAnnotation + invalidHeader + validFooter)
         .getBytes();
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
index 060cbbb..b0f53bd 100644
--- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
@@ -791,7 +791,8 @@ public class RelayNetworkStatusVoteImplTest {
   public void testNetworkStatusVersionPrefixLine()
       throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line 'directory-footer' in vote.");
+    this.thrown.expectMessage("Keyword 'directory-footer' is contained 2 "
+        + "times, but must be contained at most once.");
     VoteBuilder.createWithNetworkStatusVersionLine(
         "directory-footer\nnetwork-status-version 3");
   }
@@ -800,7 +801,8 @@ public class RelayNetworkStatusVoteImplTest {
   public void testNetworkStatusVersionPrefixLinePoundChar()
       throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line '#vote' in vote.");
+    this.thrown.expectMessage("Keyword 'network-status-version' "
+        + "must be contained in the first line.");
     VoteBuilder.createWithNetworkStatusVersionLine(
         "#vote\nnetwork-status-version 3");
   }
@@ -965,16 +967,6 @@ public class RelayNetworkStatusVoteImplTest {
   }
 
   @Test
-  public void testConsensusMethodTwoLines()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line 'consensus-method 1' in vote.");
-    VoteBuilder.createWithConsensusMethodsLine(
-        "consensus-method 1\nconsensus-method 1");
-  }
-
-  @Test
   public void testPublishedNoLine() throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
     this.thrown.expectMessage("Keyword 'published' is contained 0 times, "
@@ -1802,16 +1794,6 @@ public class RelayNetworkStatusVoteImplTest {
   }
 
   @Test
-  public void testUnrecognizedHeaderLineFail()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line 'unrecognized-line 1' in vote.");
-    String unrecognizedLine = "unrecognized-line 1";
-    VoteBuilder.createWithUnrecognizedHeaderLine(unrecognizedLine, true);
-  }
-
-  @Test
   public void testUnrecognizedHeaderLineIgnore()
       throws DescriptorParseException {
     String unrecognizedLine = "unrecognized-line 1";
@@ -1823,17 +1805,6 @@ public class RelayNetworkStatusVoteImplTest {
   }
 
   @Test
-  public void testUnrecognizedDirSourceLineFail()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line 'unrecognized-line 1' in vote.");
-    String unrecognizedLine = "unrecognized-line 1";
-    VoteBuilder.createWithUnrecognizedDirSourceLine(unrecognizedLine,
-        true);
-  }
-
-  @Test
   public void testUnrecognizedDirSourceLineIgnore()
       throws DescriptorParseException {
     String unrecognizedLine = "unrecognized-line 1";
@@ -1845,16 +1816,6 @@ public class RelayNetworkStatusVoteImplTest {
   }
 
   @Test
-  public void testUnrecognizedFooterLineFail()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown
-      .expectMessage("Unrecognized line 'unrecognized-line 1' in vote.");
-    String unrecognizedLine = "unrecognized-line 1";
-    VoteBuilder.createWithUnrecognizedFooterLine(unrecognizedLine, true);
-  }
-
-  @Test
   public void testUnrecognizedFooterLineIgnore()
       throws DescriptorParseException {
     String unrecognizedLine = "unrecognized-line 1";
diff --git a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
index 5f369ad..67145c7 100644
--- a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
@@ -1136,7 +1136,7 @@ public class ServerDescriptorImplTest {
   public void testExitPolicyProjectAll() throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
     this.thrown.expectMessage(
-        "Unrecognized line 'project *:*' in server descriptor.");
+        "Either keyword 'accept' or 'reject' must be contained at least once.");
     DescriptorBuilder.createWithExitPolicyLines("project *:*");
   }
 
@@ -1677,16 +1677,6 @@ public class ServerDescriptorImplTest {
   }
 
   @Test
-  public void testTunnelledDirServerTypo()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line 'tunneled-dir-server' "
-        + "in server descriptor.");
-    DescriptorBuilder.createWithTunnelledDirServerLine(
-        "tunneled-dir-server");
-  }
-
-  @Test
   public void testTunnelledDirServerTwice()
       throws DescriptorParseException {
     this.thrown.expect(DescriptorParseException.class);
@@ -1706,16 +1696,6 @@ public class ServerDescriptorImplTest {
   }
 
   @Test
-  public void testUnrecognizedLineFail()
-      throws DescriptorParseException {
-    String unrecognizedLine = "unrecognized-line 1";
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage(
-        "Unrecognized line 'unrecognized-line 1' in server descriptor.");
-    DescriptorBuilder.createWithUnrecognizedLine(unrecognizedLine);
-  }
-
-  @Test
   public void testUnrecognizedLineIgnore()
       throws DescriptorParseException {
     String unrecognizedLine = "unrecognized-line 1";
@@ -1880,17 +1860,6 @@ public class ServerDescriptorImplTest {
         + ROUTER_SIG_ED25519_LINE);
   }
 
-  @Test
-  public void testEd25519FollowedbyUnrecognizedLine()
-      throws DescriptorParseException {
-    this.thrown.expect(DescriptorParseException.class);
-    this.thrown.expectMessage("Unrecognized line 'unrecognized-line 1' "
-        + "in server descriptor.");
-    DescriptorBuilder.createWithEd25519Lines(IDENTITY_ED25519_LINES,
-        MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE
-        + "\nunrecognized-line 1");
-  }
-
   private static final String ONION_KEY_CROSSCERT_LINES =
       "onion-key-crosscert\n"
       + "-----BEGIN CROSSCERT-----\n"
diff --git a/src/test/java/org/torproject/descriptor/impl/TestDescriptor.java b/src/test/java/org/torproject/descriptor/impl/TestDescriptor.java
index cf5efd5..48dcb98 100644
--- a/src/test/java/org/torproject/descriptor/impl/TestDescriptor.java
+++ b/src/test/java/org/torproject/descriptor/impl/TestDescriptor.java
@@ -12,6 +12,11 @@ public class TestDescriptor extends DescriptorImpl {
       throws DescriptorParseException {
     super(rawDescriptorBytes, offsetAndLength, null, blankLinesAllowed);
   }
+
+  protected TestDescriptor(byte[] rawDescriptorBytes, int[] offsetAndLength)
+      throws DescriptorParseException {
+    super(rawDescriptorBytes, offsetAndLength, null);
+  }
 }
 
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits