From 76a5287e85efee9ea3d2b2822684a3555183b070 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:14:42 +0100 Subject: [PATCH] add test assertion for elastic attribute leak --- ...lerInstrumentationWithExceptionResolverTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationWithExceptionResolverTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationWithExceptionResolverTest.java index 1f62d500d2..0800056204 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationWithExceptionResolverTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationWithExceptionResolverTest.java @@ -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; @@ -45,6 +48,16 @@ public void testCallApiWithExceptionThrown() throws Exception { MvcResult result = resultActions.andReturn(); MockHttpServletResponse response = result.getResponse(); + + Enumeration 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"));