commit 44bcd9f57b33a5e76ba43bf242bd787fa8375a77 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed Aug 16 18:00:18 2017 +0200
Add test for sanitizing status without entries.
Related to #23255. --- .../collector/bridgedescs/DescriptorBuilder.java | 15 +++++++++++++++ .../collector/bridgedescs/SanitizedBridgesWriterTest.java | 13 +++++++++++++ 2 files changed, 28 insertions(+)
diff --git a/src/test/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java b/src/test/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java index 08f9820..429a0ea 100644 --- a/src/test/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java +++ b/src/test/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java @@ -60,6 +60,21 @@ abstract class DescriptorBuilder extends ArrayList<String> { fail("Line start not found: " + lineStart); }
+ /** Finds the first line that starts with the given line start and truncates + * that line and possibly subsequent lines, or fails if no line can be found + * with that line start. */ + void truncateAtLineStartingWith(String lineStart) { + for (int i = 0; i < this.size(); i++) { + if (this.get(i).startsWith(lineStart)) { + while (this.size() > i) { + this.remove(i); + } + return; + } + } + fail("Line start not found: " + lineStart); + } + /** Writes all descriptor lines with newlines to the given output stream. */ void build(OutputStream outputStream) throws IOException { for (String line : this) { diff --git a/src/test/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriterTest.java b/src/test/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriterTest.java index 40e3a47..0e62573 100644 --- a/src/test/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriterTest.java +++ b/src/test/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriterTest.java @@ -659,6 +659,19 @@ public class SanitizedBridgesWriterTest { }
@Test + public void testNetworkStatusNoEntry() throws Exception { + this.defaultNetworkStatusBuilder.truncateAtLineStartingWith("r "); + this.runTest(); + assertFalse("Skipped network status without entries.", + this.parsedNetworkStatuses.isEmpty()); + for (String line : this.parsedNetworkStatuses.get(0)) { + if (line.startsWith("r ")) { + fail("Sanitized non-existent r line: " + line); + } + } + } + + @Test public void testNetworkStatusFromBifroest() throws Exception { this.defaultTarballBuilder.setTarballFileName( this.defaultTarballBuilder.getTarballFileName()
tor-commits@lists.torproject.org