Skip to content

Commit d35ec15

Browse files
lukaszlenartkusalk
authored andcommitted
WW-5525 Fixes NPE when checking if expressions is acceptable
(cherry picked from commit 9fee06c)
1 parent 583b174 commit d35ec15

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

plugins/spring/src/test/java/com/opensymphony/xwork2/ognl/SecurityMemberAccessProxyTest.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Map;
3232

3333
import static org.junit.Assert.assertFalse;
34+
import static org.junit.Assert.assertThrows;
3435
import static org.junit.Assert.assertTrue;
3536

3637
public class SecurityMemberAccessProxyTest extends XWorkJUnit4TestCase {
@@ -87,4 +88,91 @@ public void allowAllProxyAccess() {
8788
assertTrue(sma.isAccessible(context, proxy.getAction(), proxyObjectProxyMember, ""));
8889
assertTrue(sma.isAccessible(context, proxy.getAction(), proxyObjectNonProxyMember, ""));
8990
}
91+
92+
@Test
93+
public void nullTargetAndTargetAndMemberNotAllowed() {
94+
sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
95+
sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
96+
assertTrue(sma.isAccessible(context, null, proxyObjectProxyMember, ""));
97+
}
98+
99+
@Test
100+
public void nullTargetAndTargetAllowedAndMemberNotAllowed() {
101+
sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
102+
sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
103+
assertTrue(sma.isAccessible(context, null, proxyObjectProxyMember, ""));
104+
}
105+
106+
@Test
107+
public void nullTargetAndTargetAndMemberAllowed() {
108+
sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
109+
sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
110+
assertTrue(sma.isAccessible(context, null, proxyObjectProxyMember, ""));
111+
}
112+
113+
@Test
114+
public void nullMemberAndTargetAndMemberNotAllowed() {
115+
sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
116+
sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
117+
Object action = proxy.getAction();
118+
assertThrows("Member cannot be null!", IllegalArgumentException.class,
119+
() -> sma.isAccessible(context, action, null, ""));
120+
}
121+
122+
@Test
123+
public void nullMemberAndTargetAllowedAndMemberNotAllowed() {
124+
sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
125+
sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
126+
Object action = proxy.getAction();
127+
assertThrows("Member cannot be null!", IllegalArgumentException.class,
128+
() -> sma.isAccessible(context, action, null, ""));
129+
}
130+
131+
@Test
132+
public void nullMemberAndTargetNotAllowedAndMemberAllowed() {
133+
sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
134+
sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
135+
Object action = proxy.getAction();
136+
assertThrows("Member cannot be null!", IllegalArgumentException.class,
137+
() -> sma.isAccessible(context, action, null, ""));
138+
}
139+
140+
@Test
141+
public void nullTargetAndMemberAndTargetAndMemberNotAllowed() {
142+
sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
143+
sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
144+
assertThrows("Member cannot be null!", IllegalArgumentException.class,
145+
() -> sma.isAccessible(context, null, null, ""));
146+
}
147+
148+
@Test
149+
public void nullTargetAndMemberAndTargetNotAllowedAndMemberAllowed() {
150+
sma.useDisallowProxyObjectAccess(Boolean.TRUE.toString());
151+
sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
152+
assertThrows("Member cannot be null!", IllegalArgumentException.class,
153+
() -> sma.isAccessible(context, null, null, ""));
154+
}
155+
156+
@Test
157+
public void nullTargetAndMemberAndTargetAllowedAndMemberNotAllowed() {
158+
sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
159+
sma.useDisallowProxyMemberAccess(Boolean.TRUE.toString());
160+
assertThrows("Member cannot be null!", IllegalArgumentException.class,
161+
() -> sma.isAccessible(context, null, null, ""));
162+
}
163+
164+
@Test
165+
public void nullTargetAndMemberAndTargetAndMemberAllowed() {
166+
sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
167+
sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
168+
assertThrows("Member cannot be null!", IllegalArgumentException.class,
169+
() -> sma.isAccessible(context, null, null, ""));
170+
}
171+
172+
@Test
173+
public void nullPropertyName() {
174+
sma.useDisallowProxyMemberAccess(Boolean.FALSE.toString());
175+
Object action = proxy.getAction();
176+
assertTrue(sma.isAccessible(context, action, proxyObjectProxyMember, null));
177+
}
90178
}

0 commit comments

Comments
 (0)