[java-idp-plugin-webauthn] branch main updated: Add attestation validation test

Phil Smart philip.smart at jisc.ac.uk
Wed Jul 31 16:10:00 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=117ea866c62f1b0d342939d08a65f2b6eaed6b21

The following commit(s) were added to refs/heads/main by this push:
     new 117ea86  Add attestation validation test
117ea86 is described below

commit 117ea866c62f1b0d342939d08a65f2b6eaed6b21
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Wed Jul 31 17:09:57 2024 +0100

    Add attestation validation test
---
 ...lidateAuthenticatorAttestationResponseTest.java | 135 +++++++++++++++++++++
 .../webauthn/client/impl/MockWebAuthnClient.java   |   2 +-
 2 files changed, 136 insertions(+), 1 deletion(-)

diff --git a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/admin/impl/ValidateAuthenticatorAttestationResponseTest.java b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/admin/impl/ValidateAuthenticatorAttestationResponseTest.java
new file mode 100644
index 0000000..f2ba649
--- /dev/null
+++ b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/admin/impl/ValidateAuthenticatorAttestationResponseTest.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.plugin.authn.webauthn.admin.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+import org.springframework.webflow.execution.Event;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.yubico.webauthn.data.AuthenticatorAssertionResponse;
+import com.yubico.webauthn.data.AuthenticatorAttestationResponse;
+import com.yubico.webauthn.data.ClientAssertionExtensionOutputs;
+import com.yubico.webauthn.data.ClientRegistrationExtensionOutputs;
+import com.yubico.webauthn.data.PublicKeyCredential;
+import com.yubico.webauthn.data.PublicKeyCredentialCreationOptions;
+import com.yubico.webauthn.data.PublicKeyCredentialRequestOptions;
+
+import net.shibboleth.idp.plugin.authn.webauthn.admin.CredentialCreationOptionsParameters;
+import net.shibboleth.idp.plugin.authn.webauthn.admin.RegistrationResult;
+import net.shibboleth.idp.plugin.authn.webauthn.admin.WebAuthnRegistrationEventIds;
+import net.shibboleth.idp.plugin.authn.webauthn.authn.AssertionResult;
+import net.shibboleth.idp.plugin.authn.webauthn.authn.CredentialRequestOptionsParameters;
+import net.shibboleth.idp.plugin.authn.webauthn.client.WebAuthnAuthenticationClient;
+import net.shibboleth.idp.plugin.authn.webauthn.context.WebAuthnRegistrationContext;
+import net.shibboleth.idp.plugin.authn.webauthn.exception.AssertionFailureException;
+import net.shibboleth.idp.plugin.authn.webauthn.exception.RegistrationFailureException;
+import net.shibboleth.idp.plugin.authn.webauthn.exception.WebAuthnAuthenticationClientException;
+import net.shibboleth.idp.plugin.authn.webauthn.impl.AbstractWebAuthnTest;
+import net.shibboleth.shared.component.ComponentInitializationException;
+
+/**
+ * Tests for {@link ValidateAuthenticatorAttestationResponse}
+ */
+public class ValidateAuthenticatorAttestationResponseTest extends AbstractWebAuthnTest {
+    
+    private ValidateAuthenticatorAttestationResponse action;
+    private WebAuthnRegistrationContext regCtx;
+    
+    @Override
+    @BeforeMethod
+    public void setup() throws Exception {
+        super.setup();
+        action = new ValidateAuthenticatorAttestationResponse();
+        regCtx = addWebAuthnRegistrationContext();
+        action.setWebAuthnClient(client);
+        action.setCredentialRepository(credentialRepo);
+
+    }
+    
+    @Test
+    public void testValidateAttestationResponse() throws Exception {
+        action.initialize();
+        
+        final var attestationResponse = createAttestationReponse();
+        regCtx.setPublicKeyCredentialAttestationResponse(attestationResponse);
+        
+        final Event event = action.execute(src);
+        assertNull(event);        
+    }
+    
+    @Test
+    public void testValidateAttestationResponse_NullResponse() throws ComponentInitializationException {
+        action.initialize();
+        
+        final Event event = action.execute(src);
+        assertNotNull(event);
+        assert event != null;
+        assertEquals(event.getId(), WebAuthnRegistrationEventIds.INVALID_REGISTRATION);        
+    }
+    
+    @Test
+    public void testValidateAttestationResponse_InvalidResponse() throws Exception {
+        final var attestationResponse = createAttestationReponse();
+        regCtx.setPublicKeyCredentialAttestationResponse(attestationResponse);
+        
+        action.setWebAuthnClient(new WebAuthnAuthenticationClient() {
+            
+            @SuppressWarnings("null")
+            @Override
+            public RegistrationResult validateAuthenticatorAttestationResponse(
+                    final PublicKeyCredentialCreationOptions publicKeyCredentialCreationOptions,
+                    final PublicKeyCredential<AuthenticatorAttestationResponse, ClientRegistrationExtensionOutputs> publicKeyCredentialAttestationResponse)
+                    throws RegistrationFailureException {
+                throw new RegistrationFailureException("invalid attestation");
+            }
+            
+            @SuppressWarnings("null")
+            @Override
+            public AssertionResult validateAuthenticatorAssertionResponse(final String username, final byte[] userId,
+                    final PublicKeyCredentialRequestOptions publicKeyCredentialRequestOptions,
+                    final PublicKeyCredential<AuthenticatorAssertionResponse, ClientAssertionExtensionOutputs> publicKeyCredentialAssertionResponse)
+                    throws AssertionFailureException {
+
+                return null;
+            }
+            
+            @SuppressWarnings("null")
+            @Override
+            public PublicKeyCredentialCreationOptions createRegistrationRequest(
+                    final CredentialCreationOptionsParameters creationOptions) throws WebAuthnAuthenticationClientException {
+                return null;
+            }
+            
+            @SuppressWarnings("null")
+            @Override
+            public PublicKeyCredentialRequestOptions createAuthenticationRequest(
+                    final CredentialRequestOptionsParameters requestParams) throws WebAuthnAuthenticationClientException {
+                // TODO Auto-generated method stub
+                return null;
+            }
+        });
+        action.initialize();
+        
+        final Event event = action.execute(src);
+        assertNotNull(event);
+        assert event != null;
+        assertEquals(event.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 a97bdd9..5c0e239 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
@@ -48,7 +48,7 @@ import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.logic.Constraint;
 
 /**
- * A Mock WebAuthnClient 
+ * A Mock {@link WebAuthnAuthenticationClient} 
  */
 //TODO can we mock the options request etc? seems harder
 public class MockWebAuthnClient implements WebAuthnAuthenticationClient {

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


More information about the commits mailing list