From 77bc6689bcb561a8a8b1a648c0ef3e33845fe27c Mon Sep 17 00:00:00 2001 From: Tomasz Adamski Date: Tue, 27 Feb 2018 17:41:34 +0100 Subject: [PATCH] improving readability Signed-off-by: Tomasz Adamski --- .../B3TextMapCodecResiliencyTest.java | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/jaeger-core/src/test/java/com/uber/jaeger/propagation/B3TextMapCodecResiliencyTest.java b/jaeger-core/src/test/java/com/uber/jaeger/propagation/B3TextMapCodecResiliencyTest.java index 61a59db30..71f9012c7 100644 --- a/jaeger-core/src/test/java/com/uber/jaeger/propagation/B3TextMapCodecResiliencyTest.java +++ b/jaeger-core/src/test/java/com/uber/jaeger/propagation/B3TextMapCodecResiliencyTest.java @@ -14,6 +14,9 @@ package com.uber.jaeger.propagation; +import static com.uber.jaeger.propagation.B3TextMapCodec.PARENT_SPAN_ID_NAME; +import static com.uber.jaeger.propagation.B3TextMapCodec.SPAN_ID_NAME; +import static com.uber.jaeger.propagation.B3TextMapCodec.TRACE_ID_NAME; import static org.junit.Assert.assertNull; import com.tngtech.java.junit.dataprovider.DataProvider; @@ -21,7 +24,6 @@ import com.tngtech.java.junit.dataprovider.UseDataProvider; import com.uber.jaeger.SpanContext; import io.opentracing.propagation.TextMap; -import java.util.Arrays; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,36 +33,37 @@ public class B3TextMapCodecResiliencyTest { private B3TextMapCodec sut = new B3TextMapCodec(); @DataProvider - public static Object[] maliciousInputs() { - return new Object[] { - "abcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbd", - "", - "ABCDEF", + public static Object[][] maliciousInputs() { + return new Object[][]{ + {TRACE_ID_NAME, "abcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbd"}, + {TRACE_ID_NAME, ""}, + {TRACE_ID_NAME, "ABCDEF"}, + {SPAN_ID_NAME, "abcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbd"}, + {SPAN_ID_NAME, ""}, + {SPAN_ID_NAME, "ABCDEF"}, + {PARENT_SPAN_ID_NAME, "abcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbd"}, + {PARENT_SPAN_ID_NAME, ""}, + {PARENT_SPAN_ID_NAME, "ABCDEF"} }; } @Test @UseDataProvider("maliciousInputs") - public void shouldFallbackWhenMaliciousInput(String maliciousInput) { - String validInput = "ffffffffffffffffffffffffffffffff"; - TextMap maliciousCarrier = new B3TextMapCodecTest.DelegatingTextMap(); - maliciousCarrier.put(B3TextMapCodec.TRACE_ID_NAME, validInput); - maliciousCarrier.put(B3TextMapCodec.SPAN_ID_NAME, validInput); - maliciousCarrier.put(B3TextMapCodec.PARENT_SPAN_ID_NAME, validInput); - - // everything is valid, except for one of the headers at a time: - for (String header : Arrays.asList( - B3TextMapCodec.TRACE_ID_NAME, - B3TextMapCodec.SPAN_ID_NAME, - B3TextMapCodec.PARENT_SPAN_ID_NAME)) { - maliciousCarrier.put(header, maliciousInput); - //when - SpanContext extract = sut.extract(maliciousCarrier); - - //then - assertNull(extract); + public void shouldFallbackWhenMaliciousInput(String headerName, String maliciousInput) { + TextMap maliciousCarrier = validHeaders(); + maliciousCarrier.put(headerName, maliciousInput); + //when + SpanContext extract = sut.extract(maliciousCarrier); + //then + assertNull(extract); + } - maliciousCarrier.put(header, validInput); - } + private TextMap validHeaders() { + TextMap maliciousCarrier = new B3TextMapCodecTest.DelegatingTextMap(); + String validInput = "ffffffffffffffffffffffffffffffff"; + maliciousCarrier.put(TRACE_ID_NAME, validInput); + maliciousCarrier.put(SPAN_ID_NAME, validInput); + maliciousCarrier.put(PARENT_SPAN_ID_NAME, validInput); + return maliciousCarrier; } }