|
23 | 23 | import static java.util.Collections.emptyMap;
|
24 | 24 | import static java.util.Collections.singletonList;
|
25 | 25 | import static org.assertj.core.api.Assertions.entry;
|
| 26 | +import static org.junit.jupiter.params.provider.Arguments.arguments; |
26 | 27 |
|
27 | 28 | import io.opentelemetry.api.common.AttributeKey;
|
28 | 29 | import io.opentelemetry.api.common.Attributes;
|
|
36 | 37 | import java.util.List;
|
37 | 38 | import java.util.Map;
|
38 | 39 | import java.util.function.ToIntFunction;
|
| 40 | +import java.util.stream.Stream; |
39 | 41 | import javax.annotation.Nullable;
|
40 | 42 | import org.junit.jupiter.api.Test;
|
| 43 | +import org.junit.jupiter.api.extension.ExtensionContext; |
41 | 44 | import org.junit.jupiter.params.ParameterizedTest;
|
| 45 | +import org.junit.jupiter.params.provider.Arguments; |
| 46 | +import org.junit.jupiter.params.provider.ArgumentsProvider; |
42 | 47 | import org.junit.jupiter.params.provider.ArgumentsSource;
|
43 | 48 | import org.junit.jupiter.params.provider.ValueSource;
|
44 | 49 |
|
@@ -200,6 +205,78 @@ void normal() {
|
200 | 205 | entry(NETWORK_PEER_PORT, 456L));
|
201 | 206 | }
|
202 | 207 |
|
| 208 | + @ParameterizedTest |
| 209 | + @ArgumentsSource(StripUrlArgumentSource.class) |
| 210 | + void stripBasicAuthTest(String url, String expectedResult) { |
| 211 | + Map<String, String> request = new HashMap<>(); |
| 212 | + request.put("urlFull", url); |
| 213 | + |
| 214 | + System.setProperty( |
| 215 | + "otel.instrumentation.http.client.experimental.redact-sensitive-parameters", "true"); |
| 216 | + AttributesExtractor<Map<String, String>, Map<String, String>> extractor = |
| 217 | + HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); |
| 218 | + |
| 219 | + AttributesBuilder attributes = Attributes.builder(); |
| 220 | + extractor.onStart(attributes, Context.root(), request); |
| 221 | + |
| 222 | + assertThat(attributes.build()).containsOnly(entry(URL_FULL, expectedResult)); |
| 223 | + } |
| 224 | + |
| 225 | + static final class StripUrlArgumentSource implements ArgumentsProvider { |
| 226 | + |
| 227 | + @Override |
| 228 | + public Stream<? extends Arguments> provideArguments(ExtensionContext context) { |
| 229 | + return Stream.of( |
| 230 | + arguments( "https://user1:[email protected]", "https://REDACTED:[email protected]"), |
| 231 | + arguments( |
| 232 | + "https://user1:[email protected]/path/", |
| 233 | + "https://REDACTED:[email protected]/path/"), |
| 234 | + arguments( |
| 235 | + "https://user1:[email protected]#test.html", |
| 236 | + "https://REDACTED:[email protected]#test.html"), |
| 237 | + arguments( |
| 238 | + "https://user1:[email protected]?foo=b@r", |
| 239 | + "https://REDACTED:[email protected]?foo=b@r"), |
| 240 | + arguments( |
| 241 | + "https://user1:[email protected]/p@th?foo=b@r", |
| 242 | + "https://REDACTED:[email protected]/p@th?foo=b@r"), |
| 243 | + arguments("https://github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"), |
| 244 | + arguments( "https://github.com#[email protected]", "https://github.com#[email protected]"), |
| 245 | + |
| 246 | + arguments("https://github.com@", "https://github.com@"), |
| 247 | + arguments( |
| 248 | + "https://service.com?paramA=valA¶mB=valB", |
| 249 | + "https://service.com?paramA=valA¶mB=valB"), |
| 250 | + arguments( |
| 251 | + "https://service.com?AWSAccessKeyId=AKIAIOSFODNN7", |
| 252 | + "https://service.com?AWSAccessKeyId=REDACTED"), |
| 253 | + arguments( |
| 254 | + "https://service.com?Signature=39Up9jzHkxhuIhFE9594DJxe7w6cIRCg0V6ICGS0%3A377", |
| 255 | + "https://service.com?Signature=REDACTED"), |
| 256 | + arguments( |
| 257 | + "https://service.com?sig=39Up9jzHkxhuIhFE9594DJxe7w6cIRCg0V6ICGS0", |
| 258 | + "https://service.com?sig=REDACTED"), |
| 259 | + arguments( |
| 260 | + "https://service.com?X-Goog-Signature=39Up9jzHkxhuIhFE9594DJxe7w6cIRCg0V6ICGS0", |
| 261 | + "https://service.com?X-Goog-Signature=REDACTED"), |
| 262 | + arguments( |
| 263 | + "https://service.com?paramA=valA&AWSAccessKeyId=AKIAIOSFODNN7¶mB=valB", |
| 264 | + "https://service.com?paramA=valA&AWSAccessKeyId=REDACTED¶mB=valB"), |
| 265 | + arguments( |
| 266 | + "https://service.com?AWSAccessKeyId=AKIAIOSFODNN7¶mA=valA", |
| 267 | + "https://service.com?AWSAccessKeyId=REDACTED¶mA=valA"), |
| 268 | + arguments( |
| 269 | + "https://service.com?paramA=valA&AWSAccessKeyId=AKIAIOSFODNN7", |
| 270 | + "https://service.com?paramA=valA&AWSAccessKeyId=REDACTED"), |
| 271 | + arguments( |
| 272 | + "https://service.com?AWSAccessKeyId=AKIAIOSFODNN7&AWSAccessKeyId=ZGIAIOSFODNN7", |
| 273 | + "https://service.com?AWSAccessKeyId=REDACTED&AWSAccessKeyId=REDACTED"), |
| 274 | + arguments( |
| 275 | + "https://service.com?AWSAccessKeyId=AKIAIOSFODNN7#ref", |
| 276 | + "https://service.com?AWSAccessKeyId=REDACTED#ref")); |
| 277 | + } |
| 278 | + } |
| 279 | + |
203 | 280 | @ParameterizedTest
|
204 | 281 | @ArgumentsSource(ValidRequestMethodsProvider.class)
|
205 | 282 | void shouldExtractKnownMethods(String requestMethod) {
|
|
0 commit comments