[java-idp-plugin-webauthn] branch main updated: Fix tests

Phil Smart philip.smart at jisc.ac.uk
Wed May 8 09:14:21 UTC 2024


This is an automated email from the git hooks/post-receive script.

philsmart pushed a commit to branch main
in repository java-idp-plugin-webauthn.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-webauthn.git;a=commit;h=28b4a5d2674fef301bfa98ab345f2b81d78ef8a3

The following commit(s) were added to refs/heads/main by this push:
     new 28b4a5d  Fix tests
28b4a5d is described below

commit 28b4a5d2674fef301bfa98ab345f2b81d78ef8a3
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Wed May 8 10:14:19 2024 +0100

    Fix tests
---
 .../plugin/authn/webauthn/WebAuthnUserIdPrinicpal.java  |  4 ++--
 .../AbstractAttributeContextUserIdentityStrategy.java   |  2 +-
 .../AttributeContextByteArrayLookupStrategyTest.java    |  8 ++++----
 .../authn/webauthn/impl/ValidateWebAuthnAssertion.java  |  5 +++--
 .../plugin/authn/webauthn/admin/impl/AddUserIdTest.java | 17 ++++++++++-------
 .../authn/webauthn/client/impl/MockWebAuthnClient.java  |  3 ++-
 .../webauthn/impl/ValidateWebAuthnAssertionTest.java    |  2 ++
 7 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/WebAuthnUserIdPrinicpal.java b/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/WebAuthnUserIdPrinicpal.java
index 175c79a..3b6e772 100644
--- a/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/WebAuthnUserIdPrinicpal.java
+++ b/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/WebAuthnUserIdPrinicpal.java
@@ -35,7 +35,7 @@ public class WebAuthnUserIdPrinicpal implements CloneablePrincipal {
     /**
      * Constructor.
      * 
-     * @param name the user.id as raw bytes
+     * @param id the user.id as raw bytes
      */
     public WebAuthnUserIdPrinicpal(@Nonnull @NotEmpty @ParameterName(name="userId") final byte[] id) {
         Constraint.isNotNull(id, "User.id cannot be null or empty");
@@ -49,7 +49,7 @@ public class WebAuthnUserIdPrinicpal implements CloneablePrincipal {
     /**
      * Constructor.
      * 
-     * @param name the user.id base64 encoded
+     * @param idBase64 the user.id base64 encoded
      */
     public WebAuthnUserIdPrinicpal(@Nonnull @NotEmpty @ParameterName(name="userId") final String idBase64) {
         userIdBase64Encoded = Constraint.isNotNull(idBase64, "User.id cannot be null or empty");
diff --git a/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/context/navigate/AbstractAttributeContextUserIdentityStrategy.java b/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/context/navigate/AbstractAttributeContextUserIdentityStrategy.java
index e433137..8d7b596 100644
--- a/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/context/navigate/AbstractAttributeContextUserIdentityStrategy.java
+++ b/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/context/navigate/AbstractAttributeContextUserIdentityStrategy.java
@@ -52,7 +52,7 @@ public abstract class AbstractAttributeContextUserIdentityStrategy<T> extends Ab
     /** The attribute Id to extract the value from.*/
     @Nullable @NotEmpty private String attributeId;
     
-    /** Whether to look at filtered or unfiltered attributes. */
+    /** Whether to look at filtered or unfiltered attributes. Default is true.*/
     private boolean useUnfilteredAttributes;
     
     /** Constructor.*/
diff --git a/webauthn-api/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/context/navigate/AttributeContextByteArrayLookupStrategyTest.java b/webauthn-api/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/context/navigate/AttributeContextByteArrayLookupStrategyTest.java
index 9248e60..8da3091 100644
--- a/webauthn-api/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/context/navigate/AttributeContextByteArrayLookupStrategyTest.java
+++ b/webauthn-api/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/context/navigate/AttributeContextByteArrayLookupStrategyTest.java
@@ -64,7 +64,7 @@ public class AttributeContextByteArrayLookupStrategyTest {
         final var idpAttribute = new IdPAttribute("attributeOne");
         idpAttribute.setValues(CollectionSupport.listOf(new StringAttributeValue("value")));
 
-        attrCtx.setIdPAttributes(CollectionSupport.listOf(idpAttribute));
+        attrCtx.setUnfilteredIdPAttributes(CollectionSupport.listOf(idpAttribute));
         
         final byte[] attributeValue = strategy.apply(prc);
         assertEquals(new String(attributeValue, StandardCharsets.UTF_8), "value");
@@ -80,7 +80,7 @@ public class AttributeContextByteArrayLookupStrategyTest {
         final var idpAttribute = new IdPAttribute("attributeNotFound");
         idpAttribute.setValues(CollectionSupport.listOf(new StringAttributeValue("value")));
 
-        attrCtx.setIdPAttributes(CollectionSupport.listOf(idpAttribute));
+        attrCtx.setUnfilteredIdPAttributes(CollectionSupport.listOf(idpAttribute));
         
         final byte[] attributeValue = strategy.apply(prc);
         assertNotNull(attributeValue);
@@ -98,7 +98,7 @@ public class AttributeContextByteArrayLookupStrategyTest {
         idpAttribute.setValues(CollectionSupport.listOf(new StringAttributeValue("value"), 
                 new StringAttributeValue("valueTwo")));
 
-        attrCtx.setIdPAttributes(CollectionSupport.listOf(idpAttribute));
+        attrCtx.setUnfilteredIdPAttributes(CollectionSupport.listOf(idpAttribute));
         
         final byte[] attributeValue = strategy.apply(prc);
         assertNotNull(attributeValue);
@@ -119,7 +119,7 @@ public class AttributeContextByteArrayLookupStrategyTest {
         idpAttribute.setValues(CollectionSupport.listOf(new StringAttributeValue("value"), 
                 new StringAttributeValue("valueTwo")));
 
-        attrCtx.setIdPAttributes(CollectionSupport.listOf(idpAttribute));
+        attrCtx.setUnfilteredIdPAttributes(CollectionSupport.listOf(idpAttribute));
         
         final byte[] attributeValue = strategy.apply(prc);
         assertNotNull(attributeValue);
diff --git a/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ValidateWebAuthnAssertion.java b/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ValidateWebAuthnAssertion.java
index 833d35e..4830a42 100644
--- a/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ValidateWebAuthnAssertion.java
+++ b/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ValidateWebAuthnAssertion.java
@@ -209,8 +209,9 @@ public class ValidateWebAuthnAssertion extends AbstractValidationAction {
         
         // Add a WebAuthn specific user.id principal
         final byte[] userId = context.getUserId();
-        assert userId != null;
-        subject.getPrincipals().add(new WebAuthnUserIdPrinicpal(userId));
+        if (userId != null) {
+            subject.getPrincipals().add(new WebAuthnUserIdPrinicpal(userId));
+        }
         
         if (context.isSecondFactor()) {
             // If second factor, we already have a username principal and a canonical name, so do nothing
diff --git a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/admin/impl/AddUserIdTest.java b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/admin/impl/AddUserIdTest.java
index 93e43a8..08eb64e 100644
--- a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/admin/impl/AddUserIdTest.java
+++ b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/admin/impl/AddUserIdTest.java
@@ -37,6 +37,7 @@ import com.yubico.webauthn.data.ClientRegistrationExtensionOutputs;
 import com.yubico.webauthn.data.PublicKeyCredential;
 import com.yubico.webauthn.data.UserIdentity;
 
+import net.shibboleth.idp.plugin.authn.webauthn.admin.WebAuthnRegistrationEventIds;
 import net.shibboleth.idp.plugin.authn.webauthn.context.WebAuthnRegistrationContext;
 import net.shibboleth.idp.plugin.authn.webauthn.impl.AbstractWebAuthnTest;
 import net.shibboleth.idp.plugin.authn.webauthn.storage.CredentialRegistration;
@@ -103,6 +104,8 @@ public class AddUserIdTest extends AbstractWebAuthnTest {
         
         mockAuthenticator = new MockAuthenticator(RPID);
         
+        context.setUsername("jdoe");
+        
         final var user = UserIdentity.builder()
                 .name("jdoe")
                 .displayName("John Doe")
@@ -139,9 +142,7 @@ public class AddUserIdTest extends AbstractWebAuthnTest {
                  .build();
         
         credentialRepo.addRegistrationByUsername("jdoe", reg);
-        addAction.initialize();
-        
-        context.setUsername("jdoe");
+        addAction.initialize();      
         
         final Event result = addAction.execute(src);
         assertNull(result);
@@ -162,7 +163,7 @@ public class AddUserIdTest extends AbstractWebAuthnTest {
         final Event result = addAction.execute(src);
         assertNotNull(result);
         assert result != null;
-        assertEquals(result.getId(), "InvalidRegistration");
+        assertEquals(result.getId(), WebAuthnRegistrationEventIds.INVALID_REGISTRATION);
     }
     
     @Test
@@ -170,12 +171,13 @@ public class AddUserIdTest extends AbstractWebAuthnTest {
         addAction.setUserIdGeneratorStrategy(input -> new byte[] {(byte)0xFF});
         addAction.initialize();
         
-        context.setUsername(null);
+        // Do not set the username
+        //context.setUsername(null);
         
         final Event result = addAction.execute(src);
         assertNotNull(result);
         assert result != null;
-        assertEquals(result.getId(), "InvalidRegistrationContext");
+        assertEquals(result.getId(), WebAuthnRegistrationEventIds.INVALID_REGISTRATION_CTX);
     }
     
     @Test
@@ -186,11 +188,12 @@ public class AddUserIdTest extends AbstractWebAuthnTest {
             random.nextBytes(byteArray);
             return byteArray;
         });
+        context.setUsername("jdoe");
         addAction.initialize();
         final Event result = addAction.execute(src);
         assertNotNull(result);
         assert result != null;
-        assertEquals(result.getId(), "InvalidRegistrationContext");
+        assertEquals(result.getId(), WebAuthnRegistrationEventIds.INVALID_REGISTRATION);
     }
     
     
diff --git a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/client/impl/MockWebAuthnClient.java b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/client/impl/MockWebAuthnClient.java
index 54340c8..a97bdd9 100644
--- a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/client/impl/MockWebAuthnClient.java
+++ b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/client/impl/MockWebAuthnClient.java
@@ -152,9 +152,10 @@ public class MockWebAuthnClient implements WebAuthnAuthenticationClient {
             throws AssertionFailureException {
         
         final AssertionResult assertionResult = AssertionResult.builder()
-                .withSignatureCounterValid(signatureCount)
                 .withSuccess(assertionResponseSuccess)
                 .withUsername(username)
+                .withSignatureCounterValid(signatureCount)                
+                .withUserId(userId)
                 .build();
         assert assertionResult != null;
         return assertionResult;
diff --git a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ValidateWebAuthnAssertionTest.java b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ValidateWebAuthnAssertionTest.java
index 1dee29f..c1fa2ba 100644
--- a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ValidateWebAuthnAssertionTest.java
+++ b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ValidateWebAuthnAssertionTest.java
@@ -95,6 +95,7 @@ public class ValidateWebAuthnAssertionTest extends AbstractWebAuthnTest {
     @Test
     public void testValidAssertion() throws DecodingException, Exception {   
         context.setUsername(USERNAME);
+        context.setUserId(Base64Support.decode(USER_HANDLE_B64));
         action.initialize();
         
         final Map<String, String> clientDataGet = createClientData("webauthn.get", ORIGIN, CHALLENGE_B64);         
@@ -115,6 +116,7 @@ public class ValidateWebAuthnAssertionTest extends AbstractWebAuthnTest {
         action.setWebAuthnClient(new MockWebAuthnClient(rp, false, true));
         
         context.setUsername(USERNAME);
+        context.setUserId(Base64Support.decode(USER_HANDLE_B64));
         action.initialize();
         
         final Map<String, String> clientDataGet = createClientData("webauthn.get", ORIGIN, CHALLENGE_B64);         

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list