Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

tests for malicious input for B3TextMapCodec #353

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.uber.jaeger.propagation;

import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.isNotNull;

import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import com.uber.jaeger.SpanContext;
import io.opentracing.propagation.TextMap;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(DataProviderRunner.class)
public class B3TextMapCodecResiliencyTest {

private B3TextMapCodec sut = new B3TextMapCodec();

@DataProvider
public static Object[] maliciousInputs(){
return new Object[]{
"abcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbd",
"",
"ABCDEF"
};
}


@Test
@UseDataProvider("maliciousInputs")
public void shouldFallbackWhenMaliciousInput(String maliciousInput) {
TextMap maliciousCarrier = new B3TextMapCodecTest.DelegatingTextMap();
maliciousCarrier.put(B3TextMapCodec.TRACE_ID_NAME, maliciousInput);
maliciousCarrier.put(B3TextMapCodec.SPAN_ID_NAME, maliciousInput);
maliciousCarrier.put(B3TextMapCodec.PARENT_SPAN_ID_NAME, maliciousInput);

//when
SpanContext extract = sut.extract(maliciousCarrier);

//then
assertThat(extract, isNotNull());
}
}