use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class B3TextMapCodecResiliencyTest method shouldFallbackWhenMaliciousInput.
@Test
@UseDataProvider("maliciousInputs")
public void shouldFallbackWhenMaliciousInput(String headerName, String maliciousInput) {
TextMap maliciousCarrier = validHeaders();
maliciousCarrier.put(headerName, maliciousInput);
// when
JaegerSpanContext extract = sut.extract(maliciousCarrier);
// then
assertNull(extract);
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class BinaryCodecTest method testBaggage.
/**
* Tests that the codec will return non-null SpanContext even if the only header
* present is "jaeger-baggage".
*/
@Test
public void testBaggage() {
Map<String, String> baggage = new HashMap<String, String>();
for (int i = 0; i < 200; i++) {
baggage.put("k" + i, "v" + i);
}
BinaryCodec codec = new BinaryCodec();
JaegerSpanContext inContext = new JaegerSpanContext(0L, 42L, 1L, 1L, (byte) 1).withBaggage(baggage);
TestBinaryCarrier carrier = new TestBinaryCarrier();
codec.inject(inContext, carrier);
// check with a new carrier just to make sure testing is accurate.
byte[] raw = new byte[carrier.buffer.capacity()];
carrier.buffer.rewind();
carrier.buffer.get(raw);
TestBinaryCarrier carrier2 = new TestBinaryCarrier(ByteBuffer.wrap(raw));
JaegerSpanContext outContext = codec.extract(carrier2);
assertTrue(carrier2.buffer.remaining() == 0);
for (int i = 0; i < 200; i++) {
assertEquals("v" + i, outContext.getBaggageItem("k" + i));
}
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class BinaryCodecTest method testBaggageWithLargeValues.
@Test
public void testBaggageWithLargeValues() {
String key1 = "";
String val1 = "";
for (int i = 0; i < 256; i++) {
key1 += "A";
val1 += "B";
}
String key2 = "";
String val2 = "";
for (int i = 0; i < 1024; i++) {
key2 += "C";
val2 += "D";
}
Map<String, String> baggage = new HashMap<String, String>();
baggage.put(key1, val1);
baggage.put(key2, val2);
JaegerSpanContext inContext = new JaegerSpanContext(0L, 1L, 1L, 1L, (byte) 1).withBaggage(baggage);
BinaryCodec codec = new BinaryCodec();
TestBinaryCarrier carrier = new TestBinaryCarrier();
codec.inject(inContext, carrier);
JaegerSpanContext outContext = codec.extract(carrier);
assertEquals(val1, outContext.getBaggageItem(key1));
assertEquals(val2, outContext.getBaggageItem(key2));
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class BinaryCodecTest method testInvalidByteOrder.
@Test
public void testInvalidByteOrder() {
BinaryCodec codec = new BinaryCodec();
ByteBuffer buf = ByteBuffer.allocate(128);
buf.order(ByteOrder.LITTLE_ENDIAN);
TestBinaryCarrier carrier = new TestBinaryCarrier(buf);
try {
codec.inject(new JaegerSpanContext(0L, 0L, 0L, 0L, (byte) 0), carrier);
fail("Exception not thrown.");
} catch (IllegalStateException expected) {
assertEquals("Carrier byte order must be big endian.", expected.getMessage());
}
try {
codec.extract(carrier);
fail("Exception not thrown.");
} catch (IllegalStateException expected) {
assertEquals("Carrier byte order must be big endian.", expected.getMessage());
}
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testInvalidParentId.
@Test
public void testInvalidParentId() {
TextMapAdapter textMap = new TextMapAdapter(new HashMap<>());
textMap.put(TRACE_PARENT, "00-00000000000000000000000000000001-0000000000000000-00");
JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
assertNull(spanContext);
verifyWarningPresent();
}
Aggregations