Skip to content

Commit

Permalink
add test assertion for elastic attribute leak
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJuge committed Feb 14, 2024
1 parent 325bee1 commit 76a5287
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;

import java.util.Enumeration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;

Expand All @@ -45,6 +48,16 @@ public void testCallApiWithExceptionThrown() throws Exception {
MvcResult result = resultActions.andReturn();
MockHttpServletResponse response = result.getResponse();


Enumeration<String> attributeNames = result.getRequest().getAttributeNames();
while (attributeNames.hasMoreElements()) {
String attributeName = attributeNames.nextElement();
assertThat(attributeName)
.describedAs("elastic attributes should be removed after usage")
.doesNotStartWith("co.elastic.");
}


assertExceptionCapture(ExceptionResolverRuntimeException.class, response, 200, "", "runtime exception occurred", "View#render error-page");
assertEquals("error-page", response.getForwardedUrl());
assertEquals("runtime exception occurred", result.getModelAndView().getModel().get("message"));
Expand Down

0 comments on commit 76a5287

Please sign in to comment.