[java-identity-provider] branch main updated: IDP-2069 Null handling
Rod Widdowson
rdw at steadingsoftware.com
Sat Feb 25 19:50:33 UTC 2023
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=0ac1d9683a6601baf6a32567f4664d7fcad75164
The following commit(s) were added to refs/heads/main by this push:
new 0ac1d9683 IDP-2069 Null handling
0ac1d9683 is described below
commit 0ac1d9683a6601baf6a32567f4664d7fcad75164
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Feb 25 19:23:33 2023 +0000
IDP-2069 Null handling
https://shibboleth.atlassian.net/browse/IDP-2069
Cleanup idp-session-impl tests
---
.../idp/session/impl/DestroySessionsTest.java | 55 +++++++++--------
.../session/impl/PopulateSessionContextTest.java | 45 +++++++++-----
.../idp/session/impl/ProcessLogoutTest.java | 69 ++++++++++++---------
.../session/impl/SessionManagerBaseTestCase.java | 25 +++++++-
.../impl/StorageBackedSessionManagerTest.java | 72 +++++++++++++++-------
.../UpdateSessionWithAuthenticationResultTest.java | 67 ++++++++++++--------
.../impl/UpdateSessionWithSPSessionTest.java | 6 +-
7 files changed, 218 insertions(+), 121 deletions(-)
diff --git a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/DestroySessionsTest.java b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/DestroySessionsTest.java
index de7010dfe..d34d99c7b 100644
--- a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/DestroySessionsTest.java
+++ b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/DestroySessionsTest.java
@@ -20,6 +20,8 @@ package net.shibboleth.idp.session.impl;
import java.time.Duration;
import java.util.Collections;
+import javax.annotation.Nonnull;
+
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.storage.StorageSerializer;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -62,6 +64,7 @@ public class DestroySessionsTest extends SessionManagerBaseTestCase {
prc = new WebflowRequestContextProfileRequestContextLookup().apply(src);
action = new DestroySessions();
+ assert sessionManager != null;
action.setSessionManager(sessionManager);
action.initialize();
}
@@ -95,19 +98,20 @@ public class DestroySessionsTest extends SessionManagerBaseTestCase {
final Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
IdPSession session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
- Assert.assertNotNull(session);
+ assert session != null;
final String sessionId = session.getId();
+ assert sessionId != null;
- prc.getSubcontext(LogoutContext.class, true).getIdPSessions().add(session);
+ prc.getOrCreateSubcontext(LogoutContext.class).getIdPSessions().add(session);
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
final LogoutContext logoutCtx = prc.getSubcontext(LogoutContext.class);
- Assert.assertNotNull(logoutCtx);
+ assert logoutCtx!= null;
Assert.assertTrue(logoutCtx.getIdPSessions().isEmpty());
session = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(sessionId)));
@@ -118,20 +122,21 @@ public class DestroySessionsTest extends SessionManagerBaseTestCase {
final Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
IdPSession session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
- Assert.assertNotNull(session);
+ assert session!= null;
final String sessionId = session.getId();
-
- prc.getSubcontext(LogoutContext.class, true).getIdPSessions().add(session);
- prc.getSubcontext(SessionContext.class, true).setIdPSession(session);
+ assert sessionId != null;
+
+ prc.getOrCreateSubcontext(LogoutContext.class).getIdPSessions().add(session);
+ prc.getOrCreateSubcontext(SessionContext.class).setIdPSession(session);
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
final LogoutContext logoutCtx = prc.getSubcontext(LogoutContext.class);
- Assert.assertNotNull(logoutCtx);
+ assert logoutCtx!= null;
Assert.assertTrue(logoutCtx.getIdPSessions().isEmpty());
final SessionContext sessionCtx = prc.getSubcontext(SessionContext.class);
@@ -145,32 +150,32 @@ public class DestroySessionsTest extends SessionManagerBaseTestCase {
Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
IdPSession session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
- Assert.assertNotNull(session);
+ assert session!= null;
- prc.getSubcontext(LogoutContext.class, true).getIdPSessions().add(session);
+ prc.getOrCreateSubcontext(LogoutContext.class).getIdPSessions().add(session);
cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
- Assert.assertNotNull(session);
+ assert session!= null;
- prc.getSubcontext(SessionContext.class, true).setIdPSession(session);
+ prc.getOrCreateSubcontext(SessionContext.class).setIdPSession(session);
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
final LogoutContext logoutCtx = prc.getSubcontext(LogoutContext.class);
- Assert.assertNotNull(logoutCtx);
+ assert logoutCtx!= null;
Assert.assertTrue(logoutCtx.getIdPSessions().isEmpty());
final SessionContext sessionCtx = prc.getSubcontext(SessionContext.class);
- Assert.assertNotNull(sessionCtx);
+ assert sessionCtx != null;
Assert.assertNotNull(sessionCtx.getIdPSession());
}
@@ -178,29 +183,29 @@ public class DestroySessionsTest extends SessionManagerBaseTestCase {
Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
IdPSession session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
- Assert.assertNotNull(session);
+ assert session!= null;
- prc.getSubcontext(LogoutContext.class, true).getIdPSessions().add(session);
+ prc.getOrCreateSubcontext(LogoutContext.class).getIdPSessions().add(session);
cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
Assert.assertNotNull(session);
- prc.getSubcontext(LogoutContext.class, true).getIdPSessions().add(session);
- prc.getSubcontext(SessionContext.class, true).setIdPSession(session);
+ prc.getOrCreateSubcontext(LogoutContext.class).getIdPSessions().add(session);
+ prc.getOrCreateSubcontext(SessionContext.class).setIdPSession(session);
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
final LogoutContext logoutCtx = prc.getSubcontext(LogoutContext.class);
- Assert.assertNotNull(logoutCtx);
+ assert logoutCtx!= null;
Assert.assertTrue(logoutCtx.getIdPSessions().isEmpty());
final SessionContext sessionCtx = prc.getSubcontext(SessionContext.class);
diff --git a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/PopulateSessionContextTest.java b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/PopulateSessionContextTest.java
index a022c50ca..f0909b7a8 100644
--- a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/PopulateSessionContextTest.java
+++ b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/PopulateSessionContextTest.java
@@ -27,9 +27,11 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import jakarta.servlet.http.Cookie;
+import jakarta.servlet.http.HttpServletRequest;
import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.idp.profile.testing.RequestContextBuilder;
+import net.shibboleth.idp.session.IdPSession;
import net.shibboleth.idp.session.SessionException;
import net.shibboleth.idp.session.context.SessionContext;
import net.shibboleth.shared.component.ComponentInitializationException;
@@ -54,6 +56,7 @@ public class PopulateSessionContextTest extends SessionManagerBaseTestCase {
action = new PopulateSessionContext();
action.setHttpServletRequestSupplier(new ThreadLocalHttpServletRequestSupplier());
action.setHttpServletResponseSupplier(new ThreadLocalHttpServletResponseSupplier());
+ assert sessionManager != null;
action.setSessionResolver(sessionManager);
action.initialize();
}
@@ -69,37 +72,41 @@ public class PopulateSessionContextTest extends SessionManagerBaseTestCase {
Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
SessionContext sessionCtx = prc.getSubcontext(SessionContext.class, false);
- Assert.assertNotNull(sessionCtx);
+ assert sessionCtx != null;
+ final IdPSession session = sessionCtx.getIdPSession();
+ assert session != null;
- Assert.assertEquals(sessionCtx.getIdPSession().getPrincipalName(), "joe");
+ Assert.assertEquals(session.getPrincipalName(), "joe");
}
@Test public void testAddressRebind() throws SessionException {
Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setRemoteAddr("::1");
+ getRequest().setCookies(cookie);
+ getRequest().setRemoteAddr("::1");
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
SessionContext sessionCtx = prc.getSubcontext(SessionContext.class, false);
- Assert.assertNotNull(sessionCtx);
-
- Assert.assertEquals(sessionCtx.getIdPSession().getPrincipalName(), "joe");
+ assert sessionCtx != null;
+ final IdPSession session = sessionCtx.getIdPSession();
+ assert session != null;
+
+ Assert.assertEquals(session.getPrincipalName(), "joe");
}
@Test public void testAddressMismatch() throws SessionException {
Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setRemoteAddr("192.168.1.1");
+ getRequest().setCookies(cookie);
+ getRequest().setRemoteAddr("192.168.1.1");
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
@@ -110,7 +117,7 @@ public class PopulateSessionContextTest extends SessionManagerBaseTestCase {
Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
Thread.sleep(16000);
@@ -124,22 +131,26 @@ public class PopulateSessionContextTest extends SessionManagerBaseTestCase {
action.setHttpServletRequestSupplier(new ThreadLocalHttpServletRequestSupplier());
action.setHttpServletResponseSupplier(new ThreadLocalHttpServletResponseSupplier());
action.setSessionResolver(sessionManager);
- action.setAddressLookupStrategy(input -> action.getHttpServletRequest().getHeader("User-Agent"));
+ final HttpServletRequest req = action.getHttpServletRequest();
+ assert req != null;
+ action.setAddressLookupStrategy(input -> req.getHeader("User-Agent"));
action.initialize();
Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).addHeader("User-Agent", "UnitTest-Client");
+ getRequest().setCookies(cookie);
+ getRequest().addHeader("User-Agent", "UnitTest-Client");
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
SessionContext sessionCtx = prc.getSubcontext(SessionContext.class, false);
- Assert.assertNotNull(sessionCtx);
+ assert sessionCtx != null;
- Assert.assertEquals(sessionCtx.getIdPSession().getPrincipalName(), "joe");
- Assert.assertTrue(sessionCtx.getIdPSession().checkAddress("UnitTest-Client"));
+ final IdPSession idpSession =sessionCtx.getIdPSession();
+ assert idpSession!= null;
+ Assert.assertEquals(idpSession.getPrincipalName(), "joe");
+ Assert.assertTrue(idpSession.checkAddress("UnitTest-Client"));
}
}
diff --git a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/ProcessLogoutTest.java b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/ProcessLogoutTest.java
index 5e0d4e2f7..2d3c2d905 100644
--- a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/ProcessLogoutTest.java
+++ b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/ProcessLogoutTest.java
@@ -19,6 +19,7 @@ package net.shibboleth.idp.session.impl;
import java.time.Duration;
import java.time.Instant;
+import java.util.Collection;
import java.util.Collections;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -32,6 +33,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import jakarta.servlet.http.Cookie;
+import jakarta.servlet.http.HttpServletRequest;
import net.shibboleth.idp.authn.context.SubjectContext;
import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
import net.shibboleth.idp.profile.testing.ActionTestingSupport;
@@ -97,47 +99,49 @@ public class ProcessLogoutTest extends SessionManagerBaseTestCase {
final Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
final IdPSession session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
- Assert.assertNotNull(session);
-
+ assert session!= null;
+
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
final SubjectContext subjectCtx = prc.getSubcontext(SubjectContext.class);
- Assert.assertNotNull(subjectCtx);
+ assert subjectCtx!= null;
Assert.assertEquals(subjectCtx.getPrincipalName(), "joe");
final LogoutContext logoutCtx = prc.getSubcontext(LogoutContext.class);
- Assert.assertNotNull(logoutCtx);
- Assert.assertEquals(logoutCtx.getIdPSessions().size(), 1);
- Assert.assertEquals(logoutCtx.getIdPSessions().iterator().next().getId(), session.getId());
+ assert logoutCtx!= null;
+ final Collection<IdPSession> sessions = logoutCtx.getIdPSessions();
+ Assert.assertEquals(sessions.size(), 1);
+ Assert.assertEquals(sessions.iterator().next().getId(), session.getId());
Assert.assertTrue(logoutCtx.getSessionMap().isEmpty());
-
- sessionManager.destroySession(session.getId(), false);
+ final String id = session.getId();
+ assert id != null;
+ sessionManager.destroySession(id, false);
}
@Test public void testSessionSPSessions() throws SessionException, ResolverException {
final Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
+ getRequest().setCookies(cookie);
// Limit granularity to milliseconds for storage roundtrip.
final Instant creation = Instant.ofEpochMilli(System.currentTimeMillis());
final Instant expiration = creation.plusSeconds(3600);
final IdPSession session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
- Assert.assertNotNull(session);
+ assert session != null;
session.addSPSession(new BasicSPSession("https://sp.example.org", creation, expiration));
session.addSPSession(new BasicSPSession("https://sp2.example.org", creation, expiration));
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
final SubjectContext subjectCtx = prc.getSubcontext(SubjectContext.class);
- Assert.assertNotNull(subjectCtx);
+ assert subjectCtx!= null;
Assert.assertEquals(subjectCtx.getPrincipalName(), "joe");
final LogoutContext logoutCtx = prc.getSubcontext(LogoutContext.class);
- Assert.assertNotNull(logoutCtx);
+ assert logoutCtx!= null;
Assert.assertEquals(logoutCtx.getIdPSessions().size(), 1);
Assert.assertEquals(logoutCtx.getIdPSessions().iterator().next().getId(), session.getId());
@@ -151,34 +155,38 @@ public class ProcessLogoutTest extends SessionManagerBaseTestCase {
Assert.assertEquals(sp.getCreationInstant(), creation);
Assert.assertEquals(sp.getExpirationInstant(), expiration);
- sessionManager.destroySession(session.getId(), false);
+ final String id = session.getId();
+ assert id != null;
+ sessionManager.destroySession(id, false);
}
@Test public void testAddressRebind() throws SessionException, ResolverException {
final Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setRemoteAddr("::1");
+ getRequest().setCookies(cookie);
+ getRequest().setRemoteAddr("::1");
final IdPSession session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
- Assert.assertNotNull(session);
-
+ assert session != null;
+
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
final SubjectContext subjectCtx = prc.getSubcontext(SubjectContext.class);
- Assert.assertNotNull(subjectCtx);
+ assert subjectCtx!= null;
Assert.assertEquals(subjectCtx.getPrincipalName(), "joe");
- sessionManager.destroySession(session.getId(), false);
+ final String id = session.getId();
+ assert id != null;
+ sessionManager.destroySession(id, false);
}
@Test public void testAddressMismatch() throws SessionException {
final Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setRemoteAddr("192.168.1.1");
+ getRequest().setCookies(cookie);
+ getRequest().setRemoteAddr("192.168.1.1");
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
@@ -191,26 +199,31 @@ public class ProcessLogoutTest extends SessionManagerBaseTestCase {
action.setHttpServletRequestSupplier(new ThreadLocalHttpServletRequestSupplier());
action.setHttpServletResponseSupplier(new ThreadLocalHttpServletResponseSupplier());
action.setSessionResolver(sessionManager);
- action.setAddressLookupStrategy(input -> action.getHttpServletRequest().getHeader("User-Agent"));
+ action.setAddressLookupStrategy(input -> {
+ final HttpServletRequest req = action.getHttpServletRequest();
+ assert req != null;
+ return req.getHeader("User-Agent");});
action.initialize();
Cookie cookie = createSession("joe");
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).setCookies(cookie);
- ((MockHttpServletRequest) HttpServletRequestResponseContext.getRequest()).addHeader("User-Agent", "UnitTest-Client");
+ getRequest().setCookies(cookie);
+ getRequest().addHeader("User-Agent", "UnitTest-Client");
final IdPSession session = sessionManager.resolveSingle(new CriteriaSet(new HttpServletRequestCriterion()));
- Assert.assertNotNull(session);
+ assert session != null;
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
final SubjectContext subjectCtx = prc.getSubcontext(SubjectContext.class);
- Assert.assertNotNull(subjectCtx);
+ assert subjectCtx!=null;
Assert.assertEquals(subjectCtx.getPrincipalName(), "joe");
Assert.assertTrue(session.checkAddress("UnitTest-Client"));
- sessionManager.destroySession(session.getId(), false);
+ final String id = session.getId();
+ assert id != null;
+ sessionManager.destroySession(id, false);
}
}
diff --git a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/SessionManagerBaseTestCase.java b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/SessionManagerBaseTestCase.java
index fe7411e65..6774153c1 100644
--- a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/SessionManagerBaseTestCase.java
+++ b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/SessionManagerBaseTestCase.java
@@ -57,6 +57,7 @@ public class SessionManagerBaseTestCase extends OpenSAMLInitBaseTestCase {
sessionManager = new StorageBackedSessionManager();
sessionManager.setSessionTimeout(Duration.ofSeconds(15));
+ assert storageService != null;
sessionManager.setStorageService(storageService);
sessionManager.setIDGenerator(IdentifierGenerationStrategy.getInstance(ProviderType.SECURE));
sessionManager.setHttpServletRequestSupplier(new ThreadLocalHttpServletRequestSupplier());
@@ -93,11 +94,31 @@ public class SessionManagerBaseTestCase extends OpenSAMLInitBaseTestCase {
*
* @throws SessionException ...
*/
- protected Cookie createSession(@Nonnull @NotEmpty final String principalName) throws SessionException {
+ @Nonnull protected Cookie createSession(@Nonnull @NotEmpty final String principalName) throws SessionException {
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
sessionManager.createSession(principalName);
- Cookie cookie = ((MockHttpServletResponse) HttpServletRequestResponseContext.getResponse()).getCookies()[0];
+ Cookie cookie = getResponse().getCookies()[0];
HttpServletRequestResponseContext.clearCurrent();
return cookie;
}
+
+
+ /** return a null safe {@link MockHttpServletRequest}.
+ * @return the request
+ */
+ @Nonnull protected MockHttpServletRequest getRequest() {
+ final MockHttpServletRequest result = (MockHttpServletRequest) HttpServletRequestResponseContext.getRequest();
+ assert result != null;
+ return result;
+ }
+
+ /** return a null safe {@link MockHttpServletResponse}.
+ * @return the response
+ */
+ @Nonnull protected MockHttpServletResponse getResponse() {
+ final MockHttpServletResponse result = (MockHttpServletResponse) HttpServletRequestResponseContext.getResponse();
+ assert result != null;
+ return result;
+ }
+
}
diff --git a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/StorageBackedSessionManagerTest.java b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/StorageBackedSessionManagerTest.java
index 6bd46f6e1..1604c78d0 100644
--- a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/StorageBackedSessionManagerTest.java
+++ b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/StorageBackedSessionManagerTest.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nonnull;
import javax.json.JsonObject;
import javax.json.stream.JsonGenerator;
import jakarta.servlet.http.Cookie;
@@ -71,6 +72,8 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
private SPSessionSerializerRegistry serializerRegistry;
+ private Object nullObj;
+
@BeforeClass public void setUp() throws ComponentInitializationException {
serializerRegistry = new SPSessionSerializerRegistry();
final Map<Class<? extends SPSession>,StorageSerializer<? extends SPSession>> map = new HashMap<>();
@@ -135,7 +138,7 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
// Username should be required.
try {
- sessionManager.createSession(null);
+ sessionManager.createSession((String) nullObj);
Assert.fail("A null username should not have worked");
} catch (ConstraintViolationException e) {
@@ -148,8 +151,9 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
Assert.assertEquals(session.getPrincipalName(), "joe");
Assert.assertTrue(session.getAuthenticationResults().isEmpty());
Assert.assertTrue(session.getSPSessions().isEmpty());
- Assert.assertEquals(mockResponse.getCookie(StorageBackedSessionManager.DEFAULT_COOKIE_NAME).getValue(),
- session.getId());
+ Cookie cookie = mockResponse.getCookie(StorageBackedSessionManager.DEFAULT_COOKIE_NAME);
+ assert cookie != null;
+ Assert.assertEquals(cookie.getValue(), session.getId());
log.trace("testSimpleSession({}): \n\tTime before sleep: {} \n\tCreation Instant: {}\n\t Last Activity : {} ",
Thread.currentThread().toString(),
@@ -172,9 +176,11 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
// Do a lookup and compare the results.
final Instant creation = session.getCreationInstant();
final Instant lastActivity = session.getLastActivityInstant();
+ assert session!=null;
String sessionId = session.getId();
+ assert sessionId!=null;
session = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(sessionId)));
- Assert.assertNotNull(session);
+ assert session !=null;
Assert.assertEquals(session.getPrincipalName(), "joe");
Assert.assertEquals(session.getCreationInstant(), creation.truncatedTo(ChronoUnit.MILLIS));
Assert.assertEquals(session.getLastActivityInstant(), lastActivity.truncatedTo(ChronoUnit.MILLIS));
@@ -205,8 +211,12 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
// Interleave manipulation of a session between two copies to check for resync.
IdPSession one = sessionManager.createSession("joe");
- IdPSession two = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(one.getId())));
-
+ assert one!=null;
+ String oneId = one.getId();
+ assert oneId!=null;
+ IdPSession two = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(oneId)));
+ assert two!=null;
+
Assert.assertTrue(one.checkAddress("192.168.1.1"));
Assert.assertFalse(two.checkAddress("192.168.1.2"));
Assert.assertTrue(two.checkAddress("fe80::ca2a:14ff:fe2a:3e04"));
@@ -214,7 +224,10 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
Assert.assertTrue(one.checkAddress("zorkmid"));
Assert.assertFalse(two.checkAddress("bugbear"));
- sessionManager.destroySession(session.getId(), true);
+ assert session!=null;
+ String sessionId = session.getId();
+ assert sessionId!=null;
+ sessionManager.destroySession(sessionId, true);
}
@Test(threadPoolSize = 10, invocationCount = 10, timeOut = 10000)
@@ -260,20 +273,25 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
session.updateAuthenticationResultActivity(foo);
// Load from storage and re-test.
- IdPSession session2 = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(session.getId())));
+ assert session!=null;
+ String sessionId = session.getId();
+ assert sessionId!=null;
+ IdPSession session2 = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(sessionId)));
+ assert session2 != null;
Assert.assertNull(session2.getAuthenticationResult("AuthenticationFlow/Bar"));
foo2 = session2.getAuthenticationResult("AuthenticationFlow/Foo");
- Assert.assertNotNull(foo2);
+ assert foo2!=null;
Assert.assertEquals(foo.getAuthenticationInstant().truncatedTo(ChronoUnit.MILLIS), foo2.getAuthenticationInstant());
Assert.assertEquals(foo.getLastActivityInstant(), foo2.getLastActivityInstant());
Assert.assertEquals(foo.getSubject(), foo2.getSubject());
// Test removal while multiple objects are active.
- session2 = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(session.getId())));
+ session2 = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(sessionId)));
Assert.assertTrue(session.removeAuthenticationResult(foo));
+ assert session2 != null;
Assert.assertNull(session2.getAuthenticationResult("AuthenticationFlow/Foo"));
- sessionManager.destroySession(session.getId(), true);
+ sessionManager.destroySession(sessionId, true);
}
@Test(threadPoolSize = 10, invocationCount = 10, timeOut = 10000)
@@ -304,24 +322,30 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
// Test access and compare to original.
Assert.assertNull(session.getSPSession("https://sp2.example.org/shibboleth"));
SPSession foo2 = session.getSPSession("https://sp.example.org/shibboleth");
- Assert.assertNotNull(foo2);
+ assert foo2!=null;
Assert.assertEquals(foo.getCreationInstant(), foo2.getCreationInstant());
Assert.assertEquals(foo.getExpirationInstant(), foo2.getExpirationInstant());
// Load from storage and re-test.
- IdPSession session2 = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(session.getId())));
+ assert session!=null;
+ String sessionId = session.getId();
+ assert sessionId!=null;
+ IdPSession session2 = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(sessionId)));
+
Assert.assertNull(session.getSPSession("https://sp2.example.org/shibboleth"));
+ assert session2!=null;
foo2 = session2.getSPSession("https://sp.example.org/shibboleth");
- Assert.assertNotNull(foo2);
+ assert foo2!=null;
Assert.assertEquals(foo.getCreationInstant().truncatedTo(ChronoUnit.MILLIS), foo2.getCreationInstant());
Assert.assertEquals(foo.getExpirationInstant().truncatedTo(ChronoUnit.MILLIS), foo2.getExpirationInstant());
// Test removal while multiple objects are active.
- session2 = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(session.getId())));
+ session2 = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(sessionId)));
Assert.assertTrue(session.removeSPSession(foo));
+ assert session2!=null;
Assert.assertNull(session2.getSPSession("https://sp.example.org/shibboleth"));
- sessionManager.destroySession(session.getId(), true);
+ sessionManager.destroySession(sessionId, true);
}
@Test
@@ -355,8 +379,10 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
sessions.add(s);
}
Assert.assertEquals(sessions.size(), 2);
-
- sessionManager.destroySession(session.getId(), true);
+ String sessionId = session.getId();
+ assert sessionId!=null;
+
+ sessionManager.destroySession(sessionId, true);
sessions.clear();
for (final IdPSession s : sessionManager.resolve(
@@ -365,8 +391,10 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
sessions.add(s);
}
Assert.assertEquals(sessions.size(), 1);
-
- sessionManager.destroySession(session2.getId(), true);
+ String session2Id = session2.getId();
+ assert session2Id!=null;
+
+ sessionManager.destroySession(session2Id, true);
sessions.clear();
for (final IdPSession s : sessionManager.resolve(
@@ -381,7 +409,7 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
public static final String SESSION_KEY = "PerSessionNameWouldGoHere";
- public ExtendedSPSession(String id, Instant creation, Instant expiration) {
+ public ExtendedSPSession(@Nonnull String id, @Nonnull Instant creation, @Nonnull Instant expiration) {
super(id, creation, expiration);
}
@@ -399,7 +427,7 @@ public class StorageBackedSessionManagerTest extends SessionManagerBaseTestCase
/** {@inheritDoc} */
@Override
- protected SPSession doDeserialize(JsonObject obj, String id, Instant creation, Instant expiration)
+ protected @Nonnull SPSession doDeserialize(JsonObject obj, String id, Instant creation, Instant expiration)
throws IOException {
// Check if field got serialized.
obj.getString("sk");
diff --git a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/UpdateSessionWithAuthenticationResultTest.java b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/UpdateSessionWithAuthenticationResultTest.java
index 1b21fc30a..fac192110 100644
--- a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/UpdateSessionWithAuthenticationResultTest.java
+++ b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/UpdateSessionWithAuthenticationResultTest.java
@@ -93,18 +93,20 @@ public class UpdateSessionWithAuthenticationResultTest extends SessionManagerBas
@Test public void testNoFlow() throws SessionException {
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- prc.getSubcontext(SubjectContext.class, true).setPrincipalName("joe");
+ prc.getOrCreateSubcontext(SubjectContext.class).setPrincipalName("joe");
ac.setAttemptedFlow(flowDescriptor);
ac.setAuthenticationResult(new AuthenticationResult("test2", new UsernamePrincipal("joe")));
final Event event = action.execute(src);
ActionTestingSupport.assertEvent(event, EventIds.IO_ERROR);
SessionContext sessionCtx = prc.getSubcontext(SessionContext.class, false);
- Assert.assertNotNull(sessionCtx);
+ assert sessionCtx!=null;
+ final IdPSession idpSession = sessionCtx.getIdPSession();
+ assert idpSession!=null;
- Assert.assertEquals(sessionCtx.getIdPSession().getPrincipalName(), "joe");
- Assert.assertEquals(sessionCtx.getIdPSession().getAuthenticationResults().size(), 0);
- Assert.assertNotNull((((MockHttpServletResponse) HttpServletRequestResponseContext.getResponse()).getCookies()[0]));
+ Assert.assertEquals(idpSession.getPrincipalName(), "joe");
+ Assert.assertEquals(idpSession.getAuthenticationResults().size(), 0);
+ Assert.assertNotNull(getResponse().getCookies()[0]);
}
@Test public void testNotCacheable() throws SessionException {
@@ -114,16 +116,20 @@ public class UpdateSessionWithAuthenticationResultTest extends SessionManagerBas
ac.setResultCacheable(false);
SessionContext sessionCtx = prc.getSubcontext(SessionContext.class, true);
+ assert sessionCtx!=null;
sessionCtx.setIdPSession(sessionManager.createSession("joe"));
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertEquals(sessionCtx.getIdPSession().getAuthenticationResults().size(), 0);
+ final IdPSession idpSession = sessionCtx.getIdPSession();
+ assert idpSession!=null;
+
+ Assert.assertEquals(idpSession.getAuthenticationResults().size(), 0);
}
@Test public void testNewSession() throws SessionException {
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
- prc.getSubcontext(SubjectContext.class, true).setPrincipalName("joe");
+ prc.getOrCreateSubcontext(SubjectContext.class).setPrincipalName("joe");
ac.setAttemptedFlow(flowDescriptor);
ac.setAuthenticationResult(new AuthenticationResult("test1", new UsernamePrincipal("joe")));
@@ -131,10 +137,13 @@ public class UpdateSessionWithAuthenticationResultTest extends SessionManagerBas
ActionTestingSupport.assertProceedEvent(event);
SessionContext sessionCtx = prc.getSubcontext(SessionContext.class, false);
Assert.assertNotNull(sessionCtx);
-
- Assert.assertEquals(sessionCtx.getIdPSession().getPrincipalName(), "joe");
- Assert.assertSame(sessionCtx.getIdPSession().getAuthenticationResult("test1"), ac.getAuthenticationResult());
- Assert.assertNotNull((((MockHttpServletResponse) HttpServletRequestResponseContext.getResponse()).getCookies()[0]));
+ assert sessionCtx!=null;
+ final IdPSession idpSession = sessionCtx.getIdPSession();
+ assert idpSession!=null;
+
+ Assert.assertEquals(idpSession.getPrincipalName(), "joe");
+ Assert.assertSame(idpSession.getAuthenticationResult("test1"), ac.getAuthenticationResult());
+ Assert.assertNotNull(getResponse().getCookies()[0]);
}
@Test public void testAddToSession() throws SessionException {
@@ -142,48 +151,58 @@ public class UpdateSessionWithAuthenticationResultTest extends SessionManagerBas
ac.setAttemptedFlow(flowDescriptor);
ac.setAuthenticationResult(new AuthenticationResult("test1", new UsernamePrincipal("joe")));
- SessionContext sessionCtx = prc.getSubcontext(SessionContext.class, true);
+ SessionContext sessionCtx = prc.getOrCreateSubcontext(SessionContext.class);
sessionCtx.setIdPSession(sessionManager.createSession("joe"));
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
-
- Assert.assertSame(sessionCtx.getIdPSession().getAuthenticationResult("test1"), ac.getAuthenticationResult());
+ final IdPSession idpSession = sessionCtx.getIdPSession();
+ assert idpSession!=null;
+
+ Assert.assertSame(idpSession.getAuthenticationResult("test1"), ac.getAuthenticationResult());
}
@Test public void testUpdateSessionNoResult() throws SessionException {
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
ac.setAuthenticationResult(new AuthenticationResult("test1", new UsernamePrincipal("joe")));
- SessionContext sessionCtx = prc.getSubcontext(SessionContext.class, true);
+ SessionContext sessionCtx = prc.getOrCreateSubcontext(SessionContext.class);
sessionCtx.setIdPSession(sessionManager.createSession("joe"));
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
-
- Assert.assertEquals(sessionCtx.getIdPSession().getAuthenticationResults().size(), 0);
+ final IdPSession idpSession = sessionCtx.getIdPSession();
+ assert idpSession!=null;
+
+ Assert.assertEquals(idpSession.getAuthenticationResults().size(), 0);
}
@Test public void testUpdateSession() throws SessionException, ResolverException {
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
ac.setAuthenticationResult(new AuthenticationResult("test1", new UsernamePrincipal("joe")));
- SessionContext sessionCtx = prc.getSubcontext(SessionContext.class, true);
+ final SessionContext sessionCtx = prc.getOrCreateSubcontext(SessionContext.class);
sessionCtx.setIdPSession(sessionManager.createSession("joe"));
- sessionCtx.getIdPSession().addAuthenticationResult(ac.getAuthenticationResult());
+ final IdPSession idpSession = sessionCtx.getIdPSession();
+ assert idpSession!=null;
+ final AuthenticationResult ar = ac.getAuthenticationResult();
+ assert ar != null;
+ idpSession.addAuthenticationResult(ar);
// Limit granularity to milliseconds for storage roundtrip.
final Instant ts = Instant.ofEpochMilli(System.currentTimeMillis()).plusSeconds(300);
- ac.getAuthenticationResult().setLastActivityInstant(ts);
+ ar.setLastActivityInstant(ts);
final Event event = action.execute(src);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertSame(sessionCtx.getIdPSession().getAuthenticationResult("test1"), ac.getAuthenticationResult());
+ Assert.assertSame(idpSession.getAuthenticationResult("test1"), ac.getAuthenticationResult());
- IdPSession session2 = sessionManager.resolveSingle(
- new CriteriaSet(new SessionIdCriterion(sessionCtx.getIdPSession().getId())));
+ final String idpSessionId = idpSession.getId();
+ assert idpSessionId!=null;
+ IdPSession session2 = sessionManager.resolveSingle(new CriteriaSet(new SessionIdCriterion(idpSessionId)));
+ assert session2!= null;
AuthenticationResult result = session2.getAuthenticationResult("test1");
- Assert.assertNotNull(result);
+ assert result!=null;
Assert.assertEquals(result.getLastActivityInstant(), ts);
}
diff --git a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/UpdateSessionWithSPSessionTest.java b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/UpdateSessionWithSPSessionTest.java
index 7a6f8524b..fa74e6179 100644
--- a/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/UpdateSessionWithSPSessionTest.java
+++ b/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/UpdateSessionWithSPSessionTest.java
@@ -89,7 +89,7 @@ public class UpdateSessionWithSPSessionTest extends SessionManagerBaseTestCase {
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
final IdPSession session = sessionManager.createSession("joe");
- prc.getSubcontext(SessionContext.class, true).setIdPSession(session);
+ prc.getOrCreateSubcontext(SessionContext.class).setIdPSession(session);
action.setSPSessionCreationStrategy(FunctionSupport.constant(null));
action.initialize();
@@ -102,7 +102,7 @@ public class UpdateSessionWithSPSessionTest extends SessionManagerBaseTestCase {
HttpServletRequestResponseContext.loadCurrent(new MockHttpServletRequest(), new MockHttpServletResponse());
final IdPSession session = sessionManager.createSession("joe");
- prc.getSubcontext(SessionContext.class, true).setIdPSession(session);
+ prc.getOrCreateSubcontext(SessionContext.class).setIdPSession(session);
final Instant creation = Instant.now();
final Instant expiration = creation.plusSeconds(3600);
@@ -113,7 +113,7 @@ public class UpdateSessionWithSPSessionTest extends SessionManagerBaseTestCase {
ActionTestingSupport.assertProceedEvent(event);
final SPSession spSession = session.getSPSession("https://sp.example.org");
- Assert.assertNotNull(spSession);
+ assert spSession!=null;
Assert.assertEquals(spSession.getCreationInstant(), creation);
Assert.assertEquals(spSession.getExpirationInstant(), expiration);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list