-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE-2674 Strip sensitive data from the url (open-telemetry#6417)
Fixes open-telemetry#2674 by replacing basic auth information as part of the URL with `username:password`. Co-authored-by: Malte <[email protected]> Co-authored-by: Mateusz Rzeszutek <[email protected]> Co-authored-by: Trask Stalnaker <[email protected]>
- Loading branch information
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import static java.util.Collections.emptyList; | ||
import static java.util.Collections.singletonList; | ||
import static org.assertj.core.api.Assertions.entry; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
|
@@ -19,8 +20,12 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
import javax.annotation.Nullable; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
class HttpClientAttributesExtractorTest { | ||
|
||
|
@@ -112,6 +117,39 @@ void normal() { | |
asList("654", "321"))); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("stripUrlArguments") | ||
void stripBasicAuthTest(String url, String expectedResult) { | ||
Map<String, String> request = new HashMap<>(); | ||
request.put("url", url); | ||
|
||
stripRequestTest(request, expectedResult); | ||
} | ||
|
||
private static Stream<Arguments> stripUrlArguments() { | ||
return Stream.of( | ||
arguments("https://user1:[email protected]", "https://github.com"), | ||
arguments("https://user1:[email protected]/path/", "https://github.com/path/"), | ||
arguments("https://user1:[email protected]#test.html", "https://github.com#test.html"), | ||
arguments("https://user1:[email protected]?foo=b@r", "https://github.com?foo=b@r"), | ||
arguments( | ||
"https://user1:[email protected]/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"), | ||
arguments("https://github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"), | ||
arguments("https://github.com#[email protected]", "https://github.com#[email protected]"), | ||
arguments("user1:[email protected]", "user1:[email protected]"), | ||
arguments("https://github.com@", "https://github.com@")); | ||
} | ||
|
||
private static void stripRequestTest(Map<String, String> request, String expected) { | ||
HttpClientAttributesExtractor<Map<String, String>, Map<String, String>> extractor = | ||
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()).build(); | ||
|
||
AttributesBuilder attributes = Attributes.builder(); | ||
extractor.onStart(attributes, Context.root(), request); | ||
|
||
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_URL, expected)); | ||
} | ||
|
||
@Test | ||
void invalidStatusCode() { | ||
Map<String, String> request = new HashMap<>(); | ||
|