|
19 | 19 |
|
20 | 20 | import org.apache.knox.gateway.services.security.AliasService; |
21 | 21 | import org.apache.knox.gateway.services.security.AliasServiceException; |
| 22 | +import org.apache.knox.gateway.services.security.CryptoService; |
22 | 23 | import org.apache.knox.gateway.services.security.impl.DefaultCryptoService; |
23 | 24 | import org.easymock.Capture; |
24 | 25 | import org.easymock.EasyMock; |
25 | 26 | import org.junit.Assert; |
26 | 27 | import org.junit.Test; |
| 28 | +import org.pac4j.core.context.Cookie; |
27 | 29 | import org.pac4j.core.profile.CommonProfile; |
28 | 30 | import org.pac4j.core.util.Pac4jConstants; |
29 | 31 | import org.pac4j.jee.context.JEEContext; |
30 | 32 | import org.pac4j.saml.profile.SAML2Profile; |
31 | 33 |
|
32 | 34 | import javax.servlet.http.HttpServletResponse; |
33 | 35 | import java.util.Arrays; |
| 36 | +import java.util.Collections; |
34 | 37 | import java.util.HashMap; |
35 | 38 | import java.util.HashSet; |
36 | 39 | import java.util.Map; |
|
44 | 47 | import static org.apache.knox.gateway.pac4j.filter.Pac4jDispatcherFilter.PAC4J_SESSION_STORE_EXCLUDE_ROLES; |
45 | 48 | import static org.apache.knox.gateway.pac4j.filter.Pac4jDispatcherFilter.PAC4J_SESSION_STORE_EXCLUDE_ROLES_DEFAULT; |
46 | 49 | import static org.apache.knox.gateway.pac4j.session.KnoxSessionStore.PAC4J_PASSWORD; |
| 50 | +import static org.apache.knox.gateway.pac4j.session.KnoxSessionStore.PAC4J_SESSION_PREFIX; |
47 | 51 |
|
48 | 52 | public class KnoxSessionStoreTest { |
49 | 53 | private static final String CLUSTER_NAME = "knox"; |
@@ -158,4 +162,20 @@ public void filterConfigParamsTest() |
158 | 162 | Assert.assertNotNull(samlProfile.getAttribute("https://knox.apache.org/SAML/Attributes/groups")); |
159 | 163 | Assert.assertNotNull(samlProfile.getAttribute("https://knox.apache.org/SAML/Attributes/groups2")); |
160 | 164 | } |
| 165 | + |
| 166 | + @Test |
| 167 | + public void testNullCookieValue() throws AliasServiceException { |
| 168 | + final CryptoService cryptoService = EasyMock.createNiceMock(CryptoService.class); |
| 169 | + final Map<String, String> sessionStoreConfigs = new HashMap<>(); |
| 170 | + |
| 171 | + final JEEContext mockContext = EasyMock.createNiceMock(JEEContext.class); |
| 172 | + final String keyWithNullValue = "keyWithNullValue"; |
| 173 | + Cookie cookie = new Cookie(PAC4J_SESSION_PREFIX + keyWithNullValue, "null"); |
| 174 | + EasyMock.expect(mockContext.getRequestCookies()).andReturn(Collections.singletonList(cookie)); |
| 175 | + EasyMock.replay(mockContext); |
| 176 | + |
| 177 | + final KnoxSessionStore sessionStore = new KnoxSessionStore(cryptoService, CLUSTER_NAME, null, sessionStoreConfigs); |
| 178 | + Assert.assertTrue(sessionStore.get(mockContext, keyWithNullValue).isEmpty()); |
| 179 | + } |
| 180 | + |
161 | 181 | } |
0 commit comments