-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#16 - Obfuscate Authorization header and suppress logging payloads fo…
…r AuthToken request and via request.suppressLogging()
- Loading branch information
Showing
7 changed files
with
90 additions
and
3 deletions.
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
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
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
35 changes: 35 additions & 0 deletions
35
client/src/test/java/io/avaje/http/client/DHttpClientRequestTest.java
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.avaje.http.client; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class DHttpClientRequestTest { | ||
|
||
@Test | ||
void suppressLogging_listenerEvent_expect_suppressedPayloadContent() { | ||
|
||
final DHttpClientRequest request = new DHttpClientRequest(mock(DHttpClientContext.class), Duration.ZERO); | ||
|
||
request.suppressLogging(); | ||
final RequestListener.Event event = request.listenerEvent(); | ||
|
||
assertThat(event.requestBody()).isEqualTo("<suppressed request body>"); | ||
assertThat(event.responseBody()).isEqualTo("<suppressed response body>"); | ||
} | ||
|
||
@Test | ||
void skipAuthToken_listenerEvent_expect_suppressedPayloadContent() { | ||
|
||
final DHttpClientRequest request = new DHttpClientRequest(mock(DHttpClientContext.class), Duration.ZERO); | ||
|
||
request.skipAuthToken(); | ||
final RequestListener.Event event = request.listenerEvent(); | ||
|
||
assertThat(event.requestBody()).isEqualTo("<suppressed request body>"); | ||
assertThat(event.responseBody()).isEqualTo("<suppressed response body>"); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
client/src/test/java/io/avaje/http/client/RequestLoggerTest.java
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.avaje.http.client; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class RequestLoggerTest { | ||
|
||
private final RequestLogger requestLogger = new RequestLogger(); | ||
|
||
@Test | ||
void obfuscate() { | ||
assertTrue(requestLogger.obfuscate("Authorization")); | ||
assertFalse(requestLogger.obfuscate("Foo")); | ||
} | ||
} |