|
24 | 24 | import java.io.IOException; |
25 | 25 | import java.net.InetSocketAddress; |
26 | 26 | import java.net.Proxy; |
| 27 | +import java.util.List; |
27 | 28 | import java.util.Objects; |
| 29 | +import java.util.logging.Level; |
| 30 | +import java.util.logging.LogRecord; |
| 31 | +import java.util.logging.Logger; |
28 | 32 | import javax.annotation.Nonnull; |
29 | 33 |
|
30 | 34 | import com.influxdb.LogLevel; |
@@ -440,6 +444,34 @@ public void customClientType() throws InterruptedException { |
440 | 444 | } |
441 | 445 | } |
442 | 446 |
|
| 447 | + @Test |
| 448 | + public void redactedAuthorizationHeader() { |
| 449 | + |
| 450 | + mockServer.enqueue(new MockResponse()); |
| 451 | + |
| 452 | + MockLogHandler handler = new MockLogHandler(); |
| 453 | + |
| 454 | + final Logger logger = Logger.getLogger("okhttp3.OkHttpClient"); |
| 455 | + logger.addHandler(handler); |
| 456 | + |
| 457 | + try (InfluxDBClient client = InfluxDBClientFactory.create(mockServer.url("/").toString(), "my-token".toCharArray())) { |
| 458 | + client.setLogLevel(LogLevel.HEADERS); |
| 459 | + client |
| 460 | + .getWriteApiBlocking() |
| 461 | + .writeRecord("my-bucket", "my-org", WritePrecision.NS, "m2m,tag=a field=1"); |
| 462 | + } |
| 463 | + |
| 464 | + List<LogRecord> records = handler.getRecords(Level.INFO); |
| 465 | + |
| 466 | + LogRecord authorizationLog = records |
| 467 | + .stream() |
| 468 | + .filter(it -> it.getMessage().startsWith("Authorization: ")) |
| 469 | + .findFirst() |
| 470 | + .get(); |
| 471 | + |
| 472 | + Assertions.assertThat(authorizationLog.getMessage()).isEqualTo("Authorization: ██"); |
| 473 | + } |
| 474 | + |
443 | 475 | private void queryAndTest(final String expected) throws InterruptedException { |
444 | 476 | RecordedRequest request = takeRequest(); |
445 | 477 | Assertions.assertThat(request).isNotNull(); |
|
0 commit comments