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

[tor-commits] [metrics-lib/master] Added test and bugfix for RelayNetworkStatusImpl.



commit 0f367a046ec49eebe2b356ff01850eca68b2245e
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Tue Jul 5 22:20:59 2016 +0000

    Added test and bugfix for RelayNetworkStatusImpl.
---
 .../descriptor/impl/BridgePoolAssignmentImpl.java  |  1 -
 .../descriptor/impl/RelayNetworkStatusImpl.java    |  3 +-
 .../impl/RelayNetworkStatusImplTest.java           | 53 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java b/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
index aaef048..75451a2 100644
--- a/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
@@ -15,7 +15,6 @@ import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
-/* TODO Write a test class. */
 public class BridgePoolAssignmentImpl extends DescriptorImpl
     implements BridgePoolAssignment {
 
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
index 666e879..1807b33 100644
--- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
@@ -20,8 +20,6 @@ import java.util.TreeSet;
 
 import javax.xml.bind.DatatypeConverter;
 
-/* TODO Write unit tests. */
-
 public class RelayNetworkStatusImpl extends NetworkStatusImpl
     implements RelayNetworkStatus {
 
@@ -142,6 +140,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
                 + "block in v2 network status.");
           }
           nextCrypto = "";
+          break;
         default:
           if (crypto != null) {
             crypto.append(line).append("\n");
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
new file mode 100644
index 0000000..636c7d9
--- /dev/null
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
@@ -0,0 +1,53 @@
+/* Copyright 2016 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.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+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;
+
+  @Test(expected = DescriptorParseException.class)
+  public void testParseBrokenHeader() throws DescriptorParseException {
+    RelayNetworkStatusImpl rnsi
+        = new RelayNetworkStatusImpl(validStatus.getBytes(), true);
+    rnsi.parseHeader("network-status-version 2\nxyx\nabc".getBytes());
+  }
+
+  @Test()
+  public void testValidHeader() throws DescriptorParseException {
+    RelayNetworkStatusImpl rnsi
+      = new RelayNetworkStatusImpl(validStatus.getBytes(), true);
+    rnsi.parseHeader(validHeader.getBytes());
+    assertEquals(rnsi.getContactLine(),
+                 "1024R/8D56913D Alex de Joode <adejoode@xxxxxxxxxxxx>");
+  }
+
+}
+



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