[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/master] Test for empty keys in more places.
commit 3c0b08135a2f81d15c5b43c43a1765265a655e57
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Tue May 16 12:06:14 2017 +0200
Test for empty keys in more places.
---
.../org/torproject/descriptor/impl/ParseHelper.java | 4 ++--
.../descriptor/impl/ExtraInfoDescriptorImplTest.java | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
index e77bded..d5ce50f 100644
--- a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
+++ b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
@@ -401,7 +401,7 @@ public class ParseHelper {
/* Handle below. */
}
}
- if (null == key) {
+ if (null == key || key.isEmpty()) {
throw new DescriptorParseException("Line '" + line + "' "
+ "contains an illegal key or value in list element '"
+ listElement + "'.");
@@ -483,7 +483,7 @@ public class ParseHelper {
/* Handle below. */
}
}
- if (null == key) {
+ if (null == key || key.isEmpty()) {
throw new DescriptorParseException("Line '" + line + "' contains "
+ "an illegal key or value in list element '" + listElement
+ "'.");
diff --git a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
index 5b3fe1f..8b96c88 100644
--- a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
@@ -1383,6 +1383,15 @@ public class ExtraInfoDescriptorImplTest {
}
@Test()
+ public void testDirreqV3RespEmptyString()
+ throws DescriptorParseException {
+ this.thrown.expect(DescriptorParseException.class);
+ this.thrown.expectMessage(
+ "Line 'dirreq-v3-resp =10848' contains an illegal key or value.");
+ DirreqStatsBuilder.createWithDirreqV3RespLine("dirreq-v3-resp =10848");
+ }
+
+ @Test()
public void testDirreqV3RespExtraArg()
throws DescriptorParseException {
DirreqStatsBuilder.createWithDirreqV3RespLine("dirreq-v3-resp "
@@ -1624,6 +1633,16 @@ public class ExtraInfoDescriptorImplTest {
"exit-kibibytes-written unknown=74647");
}
+ @Test()
+ public void testExitStatsWrittenEmptyString()
+ throws DescriptorParseException {
+ this.thrown.expect(DescriptorParseException.class);
+ this.thrown.expectMessage("Line 'exit-kibibytes-written =74647' contains "
+ + "an illegal key or value in list element '=74647'.");
+ ExitStatsBuilder.createWithExitKibibytesWrittenLine(
+ "exit-kibibytes-written =74647");
+ }
+
@Test(expected = DescriptorParseException.class)
public void testExitStatsReadNegativeBytes()
throws DescriptorParseException {
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits