DMAAP-DR Header Injection fix
[dmaap/datarouter.git] / datarouter-node / src / test / java / org / onap / dmaap / datarouter / node / NodeServletTest.java
index 4340b01..ad2fcf5 100644 (file)
@@ -204,6 +204,17 @@ public class NodeServletTest {
         verifyEnteringExitCalled(listAppender);
     }
 
+    @Test
+    public void Given_Request_Is_HTTP_PUT_And_Internal_Publish_But_Invalid_Header_Then_Bad_Request_Response_Is_Generated() throws Exception {
+        when(request.getPathInfo()).thenReturn("/internal/publish/1/blah");
+        when(request.getRemoteAddr()).thenReturn("1.2.3.4");
+        when(config.isAnotherNode(anyString(), anyString())).thenReturn(true);
+        when(request.getHeader("X-DMAAP-DR-PUBLISH-ID")).thenReturn("User1+");
+        nodeServlet.doPut(request, response);
+        verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), anyString());
+        verifyEnteringExitCalled(listAppender);
+    }
+
     @Test
     public void Given_Request_Is_HTTP_PUT_On_Publish_And_Ingress_Node_Is_Provided_Then_Request_Is_Redirected() throws Exception {
         setNodeConfigManagerToAllowRedirectOnIngressNode();