WW-5517 Adds a dedicate test case to cover allowlist

This commit is contained in:
Lukasz Lenart
2025-01-20 08:49:52 +01:00
parent f3997f705e
commit 8f4fa06855
2 changed files with 32 additions and 17 deletions
@@ -26,9 +26,10 @@ import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.RequestMap;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.mock.MockActionInvocation;
import org.apache.struts2.ognl.ThreadAllowlist;
import org.apache.struts2.util.ValueStack;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.util.Maps;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -47,6 +48,7 @@ public class DebuggingInterceptorTest extends StrutsJUnit4InternalTestCase {
private MockHttpServletRequest request;
private MockHttpServletResponse response;
private ActionContext context;
private TestAction action;
@Test
public void noDevMode() throws Exception {
@@ -509,6 +511,31 @@ public class DebuggingInterceptorTest extends StrutsJUnit4InternalTestCase {
""");
}
@Test
public void allowlist() throws Exception {
interceptor.setDevMode("true");
context.withParameters(HttpParameters.create(Maps.newHashMap("debug", "browser")).build());
assertThat(container.getInstance(ThreadAllowlist.class))
.extracting(ThreadAllowlist::getAllowlist).asInstanceOf(InstanceOfAssertFactories.SET)
.isEmpty();
interceptor.intercept(invocation);
invocation.invoke();
assertThat(container.getInstance(ThreadAllowlist.class))
.extracting(ThreadAllowlist::getAllowlist).asInstanceOf(InstanceOfAssertFactories.SET)
.contains(
org.apache.struts2.interceptor.ValidationAware.class,
org.apache.struts2.Validateable.class,
org.apache.struts2.action.Action.class,
org.apache.struts2.text.TextProvider.class,
org.apache.struts2.ActionSupport.class,
org.apache.struts2.locale.LocaleProvider.class,
org.apache.struts2.TestAction.class
);
}
@Before
public void before() {
request = new MockHttpServletRequest();
@@ -530,7 +557,8 @@ public class DebuggingInterceptorTest extends StrutsJUnit4InternalTestCase {
invocation = new MockActionInvocation();
invocation.setResultCode("mock");
invocation.setInvocationContext(context);
invocation.setAction(new TestAction());
action = new TestAction();
invocation.setAction(action);
invocation.setStack(valueStack);
valueStack.set("action", invocation.getAction());
@@ -538,15 +566,4 @@ public class DebuggingInterceptorTest extends StrutsJUnit4InternalTestCase {
context = context.withActionInvocation(invocation).bind();
}
@After
public void after() {
interceptor.destroy();
interceptor = null;
invocation = null;
servletContext = null;
request = null;
response = null;
}
}
@@ -23,7 +23,7 @@ import org.apache.struts2.StrutsConstants;
import org.apache.struts2.dispatcher.PrepareOperations;
import org.apache.struts2.views.jsp.AbstractUITagTest;
import java.util.HashMap;
import java.util.Collections;
import java.util.Map;
/**
@@ -204,9 +204,7 @@ public class DebugTagTest extends AbstractUITagTest {
}
private void setDevMode(final boolean devMode) {
setStrutsConstant(new HashMap<>() {{
put(StrutsConstants.STRUTS_DEVMODE, Boolean.toString(devMode));
}});
setStrutsConstant(Collections.singletonMap(StrutsConstants.STRUTS_DEVMODE, Boolean.toString(devMode)));
}
/**