ramanathan1504 commented on code in PR #4360:
URL: https://github.com/apache/logging-log4j2/pull/4360#discussion_r4126950385


##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java:
##########
@@ -271,6 +272,30 @@ void testAppendCustomHeader() throws Exception {
                 .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + 
"\"")));
     }
 
+    @Test
+    void testAppendSkipsHeaderWithInvalidRuntimeValue() throws Exception {

Review Comment:
   This gives the test the status listener, like `testAppendErrorIgnore`.
   
   ```suggestion
       @Test
       @UsingStatusListener
       void testAppendSkipsHeaderWithInvalidRuntimeValue(final 
ListStatusListener statusListener) throws Exception {
   ```
   



##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java:
##########
@@ -271,6 +272,30 @@ void testAppendCustomHeader() throws Exception {
                 .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + 
"\"")));
     }
 
+    @Test
+    void testAppendSkipsHeaderWithInvalidRuntimeValue() throws Exception {
+        
WIRE_MOCK.stubFor(post(urlEqualTo("/test/log4j/")).willReturn(SUCCESS_RESPONSE));
+        ThreadContext.put("tenant", "tenant\nwith-line-break");
+        try {
+            final Appender appender = HttpAppender.newBuilder()
+                    .setName("Http")
+                    .setLayout(JsonLayout.createDefaultLayout())
+                    .setConfiguration(CONFIGURATION)
+                    .setIgnoreExceptions(false)
+                    .setUrl(wireMockUrl("/test/log4j/", false, false))
+                    .setHeaders(new Property[] 
{Property.createProperty("X-Tenant", "${ctx:tenant}")})
+                    .build();
+            appender.append(createLogEvent());
+        } finally {
+            ThreadContext.remove("tenant");
+        }
+
+        WIRE_MOCK.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
+                .withoutHeader("X-Tenant")
+                .withHeader("Content-Type", containing("application/json"))
+                .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + 
"\"")));

Review Comment:
   This checks the warning. Without it, deleting the `LOGGER.warn` line keeps 
the test green.
   
   ```suggestion
                   .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE 
+ "\"")));
           assertThat(statusListener.findStatusData(Level.WARN))
                   .anySatisfy(data -> 
assertThat(data.getMessage().getFormattedMessage()).contains("X-Tenant"));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to