[java-idp-oidc] branch master updated: Test needs a consistent "favored" default principal.
Scott Cantor
cantor.2 at osu.edu
Mon Jan 13 12:31:54 EST 2020
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-idp-oidc.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-oidc.git;a=commit;h=722db19c5612a344f2ccc7448899c649f08ef596
The following commit(s) were added to refs/heads/master by this push:
new 722db19 Test needs a consistent "favored" default principal.
722db19 is described below
commit 722db19c5612a344f2ccc7448899c649f08ef596
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Jan 13 12:31:51 2020 -0500
Test needs a consistent "favored" default principal.
---
...ContextClassReferenceToResponseContextTest.java | 39 +++++++++++++---------
1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/idp-oidc-extension-impl/src/test/java/org/geant/idpextension/oidc/profile/impl/SetAuthenticationContextClassReferenceToResponseContextTest.java b/idp-oidc-extension-impl/src/test/java/org/geant/idpextension/oidc/profile/impl/SetAuthenticationContextClassReferenceToResponseContextTest.java
index 64f5d59..3dc207c 100644
--- a/idp-oidc-extension-impl/src/test/java/org/geant/idpextension/oidc/profile/impl/SetAuthenticationContextClassReferenceToResponseContextTest.java
+++ b/idp-oidc-extension-impl/src/test/java/org/geant/idpextension/oidc/profile/impl/SetAuthenticationContextClassReferenceToResponseContextTest.java
@@ -16,24 +16,27 @@
package org.geant.idpextension.oidc.profile.impl;
+import net.shibboleth.idp.authn.AuthenticationFlowDescriptor;
import net.shibboleth.idp.authn.AuthenticationResult;
import net.shibboleth.idp.authn.AuthnEventIds;
import net.shibboleth.idp.authn.context.AuthenticationContext;
import net.shibboleth.idp.authn.context.PreferredPrincipalContext;
import net.shibboleth.idp.authn.context.RequestedPrincipalContext;
+import net.shibboleth.idp.authn.impl.DefaultAuthenticationResultSerializer;
import net.shibboleth.idp.profile.ActionTestingSupport;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import java.security.Principal;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.security.auth.Subject;
import org.geant.idpextension.oidc.authn.principal.AuthenticationContextClassReferencePrincipal;
-import org.opensaml.profile.action.EventIds;
import org.opensaml.saml.saml2.core.AuthnContextComparisonTypeEnumeration;
import org.springframework.webflow.execution.Event;
import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.openid.connect.sdk.claims.ACR;
@@ -45,31 +48,42 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
private List<Principal> principals;
+ @BeforeMethod
private void init() throws ComponentInitializationException {
action = new SetAuthenticationContextClassReferenceToResponseContext();
action.initialize();
profileRequestCtx.addSubcontext(new AuthenticationContext());
+
principals = new ArrayList<>();
principals.add(new AuthenticationContextClassReferencePrincipal("1"));
principals.add(new AuthenticationContextClassReferencePrincipal("2"));
principals.add(new AuthenticationContextClassReferencePrincipal("3"));
+
final RequestedPrincipalContext rpCtx = new RequestedPrincipalContext();
rpCtx.setOperator(AuthnContextComparisonTypeEnumeration.EXACT.toString());
rpCtx.setRequestedPrincipals(principals);
profileRequestCtx.getSubcontext(AuthenticationContext.class, true).addSubcontext(rpCtx, true);
- Subject authSubject = new Subject();
+
+ final Subject authSubject = new Subject();
authSubject.getPrincipals().add(new AuthenticationContextClassReferencePrincipal("2"));
authSubject.getPrincipals().add(new AuthenticationContextClassReferencePrincipal("4"));
- AuthenticationResult result = new AuthenticationResult("flowId", authSubject);
+ final AuthenticationResult result = new AuthenticationResult("flowId", authSubject);
profileRequestCtx.getSubcontext(AuthenticationContext.class).setAuthenticationResult(result);
+
+ final AuthenticationFlowDescriptor descriptor = new AuthenticationFlowDescriptor();
+ descriptor.setId("flowId");
+ descriptor.setPrincipalWeightMap(Collections.singletonMap(new AuthenticationContextClassReferencePrincipal("2"), 10));
+ descriptor.setResultSerializer(new DefaultAuthenticationResultSerializer());
+ descriptor.initialize();
+
+ profileRequestCtx.getSubcontext(AuthenticationContext.class).getAvailableFlows().put("flowId", descriptor);
}
/**
* Test that action handles case of requested acr of 1,2 and 3 while the result contains 2 and 4.
*/
@Test
- public void testSuccessRequestedACR() throws ComponentInitializationException {
- init();
+ public void testSuccessRequestedACR() {
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
Assert.assertEquals(respCtx.getAcr(), new ACR("2"));
@@ -79,8 +93,7 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
* Test that action handles case of preferred acr of 1,2 and 3 while the result contains 2 and 4.
*/
@Test
- public void testSuccessPrefereddedACR() throws ComponentInitializationException {
- init();
+ public void testSuccessPreferredACR() {
profileRequestCtx.getSubcontext(AuthenticationContext.class).removeSubcontext(RequestedPrincipalContext.class);
final PreferredPrincipalContext ppCtx = new PreferredPrincipalContext();
ppCtx.setPreferredPrincipals(principals);
@@ -94,8 +107,7 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
* Test that action handles case of preferred acr of 1 while the result contains 2 and 4.
*/
@Test
- public void testSuccessPrefereddedACRNotMatching() throws ComponentInitializationException {
- init();
+ public void testSuccessPreferredACRNotMatching() {
profileRequestCtx.getSubcontext(AuthenticationContext.class).removeSubcontext(RequestedPrincipalContext.class);
final PreferredPrincipalContext ppCtx = new PreferredPrincipalContext();
principals.clear();
@@ -104,15 +116,14 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
profileRequestCtx.getSubcontext(AuthenticationContext.class, true).addSubcontext(ppCtx, true);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertProceedEvent(event);
- Assert.assertTrue(respCtx.getAcr().equals(new ACR("2")) || respCtx.getAcr().equals(new ACR("4")));
+ Assert.assertTrue(respCtx.getAcr().equals(new ACR("2")));
}
/**
* Test that action handles case of preferred acr of 1 while the result contains none.
*/
@Test
- public void testSuccessPrefereddedACRNotMatching2() throws ComponentInitializationException {
- init();
+ public void testSuccessPreferredACRNotMatching2() {
profileRequestCtx.getSubcontext(AuthenticationContext.class).removeSubcontext(RequestedPrincipalContext.class);
final PreferredPrincipalContext ppCtx = new PreferredPrincipalContext();
principals.clear();
@@ -130,12 +141,10 @@ public class SetAuthenticationContextClassReferenceToResponseContextTest extends
* Test that action handles case of missing auth context.
*/
@Test
- public void testFailNoAuthContext() throws ComponentInitializationException {
- init();
+ public void testFailNoAuthContext() {
profileRequestCtx.removeSubcontext(AuthenticationContext.class);
final Event event = action.execute(requestCtx);
ActionTestingSupport.assertEvent(event, AuthnEventIds.INVALID_AUTHN_CTX);
-
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list