Skip to content

Commit edee6e3

Browse files
committed
WW-5517 Adds a dedicate test case to cover allowlist
1 parent f3997f7 commit edee6e3

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

core/src/test/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptorTest.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import org.apache.struts2.dispatcher.RequestMap;
2727
import org.apache.struts2.dispatcher.SessionMap;
2828
import org.apache.struts2.mock.MockActionInvocation;
29+
import org.apache.struts2.ognl.ThreadAllowlist;
2930
import org.apache.struts2.util.ValueStack;
31+
import org.assertj.core.api.InstanceOfAssertFactories;
3032
import org.assertj.core.util.Maps;
31-
import org.junit.After;
3233
import org.junit.Before;
3334
import org.junit.Test;
3435
import org.springframework.mock.web.MockHttpServletRequest;
@@ -47,6 +48,7 @@ public class DebuggingInterceptorTest extends StrutsJUnit4InternalTestCase {
4748
private MockHttpServletRequest request;
4849
private MockHttpServletResponse response;
4950
private ActionContext context;
51+
private TestAction action;
5052

5153
@Test
5254
public void noDevMode() throws Exception {
@@ -509,6 +511,31 @@ function expand(src, path) {
509511
""");
510512
}
511513

514+
@Test
515+
public void allowlist() throws Exception {
516+
interceptor.setDevMode("true");
517+
context.withParameters(HttpParameters.create(Maps.newHashMap("debug", "browser")).build());
518+
519+
assertThat(container.getInstance(ThreadAllowlist.class))
520+
.extracting(ThreadAllowlist::getAllowlist).asInstanceOf(InstanceOfAssertFactories.SET)
521+
.isEmpty();
522+
523+
interceptor.intercept(invocation);
524+
invocation.invoke();
525+
526+
assertThat(container.getInstance(ThreadAllowlist.class))
527+
.extracting(ThreadAllowlist::getAllowlist).asInstanceOf(InstanceOfAssertFactories.SET)
528+
.contains(
529+
org.apache.struts2.interceptor.ValidationAware.class,
530+
org.apache.struts2.Validateable.class,
531+
org.apache.struts2.action.Action.class,
532+
org.apache.struts2.text.TextProvider.class,
533+
org.apache.struts2.ActionSupport.class,
534+
org.apache.struts2.locale.LocaleProvider.class,
535+
org.apache.struts2.TestAction.class
536+
);
537+
}
538+
512539
@Before
513540
public void before() {
514541
request = new MockHttpServletRequest();
@@ -530,23 +557,13 @@ public void before() {
530557
invocation = new MockActionInvocation();
531558
invocation.setResultCode("mock");
532559
invocation.setInvocationContext(context);
533-
invocation.setAction(new TestAction());
560+
action = new TestAction();
561+
invocation.setAction(action);
534562
invocation.setStack(valueStack);
535563

536564
valueStack.set("action", invocation.getAction());
537565

538566
context = context.withActionInvocation(invocation).bind();
539567
}
540568

541-
@After
542-
public void after() {
543-
interceptor.destroy();
544-
interceptor = null;
545-
invocation = null;
546-
547-
servletContext = null;
548-
request = null;
549-
response = null;
550-
}
551-
552569
}

core/src/test/java/org/apache/struts2/views/jsp/ui/DebugTagTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.struts2.dispatcher.PrepareOperations;
2424
import org.apache.struts2.views.jsp.AbstractUITagTest;
2525

26+
import java.util.Collections;
2627
import java.util.HashMap;
2728
import java.util.Map;
2829

@@ -204,9 +205,7 @@ public void testTagAttributeOverrideDevModeFalse_clearTagStateSet() throws Excep
204205
}
205206

206207
private void setDevMode(final boolean devMode) {
207-
setStrutsConstant(new HashMap<>() {{
208-
put(StrutsConstants.STRUTS_DEVMODE, Boolean.toString(devMode));
209-
}});
208+
setStrutsConstant(Collections.singletonMap(StrutsConstants.STRUTS_DEVMODE, Boolean.toString(devMode)));
210209
}
211210

212211
/**

0 commit comments

Comments
 (0)