mirror of
https://github.com/apache/struts.git
synced 2026-08-06 23:27:07 +00:00
WW-5517 Adds a dedicate test case to cover allowlist
This commit is contained in:
+30
-13
@@ -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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user