This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/main by this push:
new 1db8a72bb WW-5525 Fixes NPE when checking if expressions is acceptable
(#1201)
1db8a72bb is described below
commit 1db8a72bb5184b4e6fa9dac56dd0fb2e107cb73b
Author: Lukasz Lenart <[email protected]>
AuthorDate: Mon Feb 17 08:53:42 2025 +0100
WW-5525 Fixes NPE when checking if expressions is acceptable (#1201)
* WW-5525 Fixes NPE when checking if expressions is acceptable
* WW-5525 Fixes bugs introduced by previous commit
---
.../ognl/SecurityMemberAccessProxyTest.java | 88 ++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git
a/plugins/spring/src/test/java/org/apache/struts2/ognl/SecurityMemberAccessProxyTest.java
b/plugins/spring/src/test/java/org/apache/struts2/ognl/SecurityMemberAccessProxyTest.java
index 91ffae19e..43f82bfe5 100644
---
a/plugins/spring/src/test/java/org/apache/struts2/ognl/SecurityMemberAccessProxyTest.java
+++
b/plugins/spring/src/test/java/org/apache/struts2/ognl/SecurityMemberAccessProxyTest.java
@@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class SecurityMemberAccessProxyTest extends XWorkJUnit4TestCase {
@@ -87,4 +88,91 @@ public class SecurityMemberAccessProxyTest extends
XWorkJUnit4TestCase {
assertTrue(sma.isAccessible(context, proxy.getAction(),
proxyObjectProxyMember, ""));
assertTrue(sma.isAccessible(context, proxy.getAction(),
proxyObjectNonProxyMember, ""));
}
+
+ @Test
+ public void nullTargetAndTargetAndMemberNotAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
+ assertTrue(sma.isAccessible(context, null, proxyObjectProxyMember,
""));
+ }
+
+ @Test
+ public void nullTargetAndTargetAllowedAndMemberNotAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
+ assertTrue(sma.isAccessible(context, null, proxyObjectProxyMember,
""));
+ }
+
+ @Test
+ public void nullTargetAndTargetAndMemberAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
+ assertTrue(sma.isAccessible(context, null, proxyObjectProxyMember,
""));
+ }
+
+ @Test
+ public void nullMemberAndTargetAndMemberNotAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
+ Object action = proxy.getAction();
+ assertThrows("Member cannot be null!", IllegalArgumentException.class,
+ () -> sma.isAccessible(context, action, null, ""));
+ }
+
+ @Test
+ public void nullMemberAndTargetAllowedAndMemberNotAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
+ Object action = proxy.getAction();
+ assertThrows("Member cannot be null!", IllegalArgumentException.class,
+ () -> sma.isAccessible(context, action, null, ""));
+ }
+
+ @Test
+ public void nullMemberAndTargetNotAllowedAndMemberAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
+ Object action = proxy.getAction();
+ assertThrows("Member cannot be null!", IllegalArgumentException.class,
+ () -> sma.isAccessible(context, action, null, ""));
+ }
+
+ @Test
+ public void nullTargetAndMemberAndTargetAndMemberNotAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
+ assertThrows("Member cannot be null!", IllegalArgumentException.class,
+ () -> sma.isAccessible(context, null, null, ""));
+ }
+
+ @Test
+ public void nullTargetAndMemberAndTargetNotAllowedAndMemberAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
+ assertThrows("Member cannot be null!", IllegalArgumentException.class,
+ () -> sma.isAccessible(context, null, null, ""));
+ }
+
+ @Test
+ public void nullTargetAndMemberAndTargetAllowedAndMemberNotAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
+ assertThrows("Member cannot be null!", IllegalArgumentException.class,
+ () -> sma.isAccessible(context, null, null, ""));
+ }
+
+ @Test
+ public void nullTargetAndMemberAndTargetAndMemberAllowed() {
+ sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
+ sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
+ assertThrows("Member cannot be null!", IllegalArgumentException.class,
+ () -> sma.isAccessible(context, null, null, ""));
+ }
+
+ @Test
+ public void nullPropertyName() {
+ sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
+ Object action = proxy.getAction();
+ assertTrue(sma.isAccessible(context, action, proxyObjectProxyMember,
null));
+ }
}