[java-idp-plugin-webauthn] branch main updated: Add more tests
Phil Smart
philip.smart at jisc.ac.uk
Thu Aug 1 09:35:11 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=65d9ac8217e680eabc68b41190c48b99ba396fb8
The following commit(s) were added to refs/heads/main by this push:
new 65d9ac8 Add more tests
65d9ac8 is described below
commit 65d9ac8217e680eabc68b41190c48b99ba396fb8
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Thu Aug 1 10:35:08 2024 +0100
Add more tests
---
.../YubicoWebauthnAuthenticationClientTest.java | 2 +-
.../impl/EnsureAllowedCredentialsIsEmptyTest.java | 55 +++++++++++
.../webauthn/impl/ExtractUsernameFromFormTest.java | 91 ++++++++++++++++++
.../PopulateWebAuthnAuthenticationContextTest.java | 107 +++++++++++++++++++++
4 files changed, 254 insertions(+), 1 deletion(-)
diff --git a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/client/impl/YubicoWebauthnAuthenticationClientTest.java b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/client/impl/YubicoWebauthnAuthenticationClientTest.java
index 0e1a626..f621e00 100644
--- a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/client/impl/YubicoWebauthnAuthenticationClientTest.java
+++ b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/client/impl/YubicoWebauthnAuthenticationClientTest.java
@@ -52,7 +52,7 @@ import net.shibboleth.shared.codec.Base64Support;
import net.shibboleth.shared.collection.CollectionSupport;
/**
- * Tests for {@link YubicoWebAuthnAuthenticationClient}. To some extend this is testing the Yubico libraries work
+ * Tests for {@link YubicoWebAuthnAuthenticationClient}. To some extent this is testing the Yubico libraries work
* correctly. But it does ensure the client has been constructed to use those libraries correctly.
*/
public class YubicoWebauthnAuthenticationClientTest extends AbstractWebAuthnTest {
diff --git a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/EnsureAllowedCredentialsIsEmptyTest.java b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/EnsureAllowedCredentialsIsEmptyTest.java
new file mode 100644
index 0000000..65d7ead
--- /dev/null
+++ b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/EnsureAllowedCredentialsIsEmptyTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.impl;
+
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import org.springframework.webflow.execution.Event;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.plugin.authn.webauthn.context.WebAuthnAuthenticationContext;
+import net.shibboleth.shared.component.ComponentInitializationException;
+
+/**
+ * Tests for {@link EnsureAllowedCredentialsIsEmpty}.
+ */
+public class EnsureAllowedCredentialsIsEmptyTest extends AbstractWebAuthnTest {
+
+ private EnsureAllowedCredentialsIsEmpty addAction;
+
+ private WebAuthnAuthenticationContext context;
+
+ @Override
+ @BeforeMethod
+ public void setup() throws Exception {
+ super.setup();
+ context = addWebAuthnAuthenticationContext();
+ addAction = new EnsureAllowedCredentialsIsEmpty();
+ addAction.setWebAuthnClient(client);
+ addAction.setCredentialRepository(credentialRepo);
+ }
+
+ @Test
+ public void testCredentialsAreEmpty() throws ComponentInitializationException {
+ addAction.initialize();
+
+ final Event result = addAction.execute(src);
+ assertNull(result);
+ assertTrue(context.getExistingCredentials().isEmpty());
+ }
+
+}
diff --git a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ExtractUsernameFromFormTest.java b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ExtractUsernameFromFormTest.java
new file mode 100644
index 0000000..02c8fa1
--- /dev/null
+++ b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ExtractUsernameFromFormTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.webflow.execution.Event;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.authn.AuthnEventIds;
+import net.shibboleth.idp.plugin.authn.webauthn.context.BaseWebAuthnContext;
+import net.shibboleth.shared.testing.ConstantSupplier;
+
+/**
+ * Tests for {@link ExtractUsernameFromForm}
+ */
+public class ExtractUsernameFromFormTest extends AbstractWebAuthnTest {
+
+ private ExtractUsernameFromForm action;
+
+ private BaseWebAuthnContext context;
+
+ private MockHttpServletRequest request;
+
+ @Override
+ @BeforeMethod
+ public void setup() throws Exception {
+ super.setup();
+ context = addBaseWebAuthnRegistrationContext();
+ request = new MockHttpServletRequest();
+ action = new ExtractUsernameFromForm();
+ }
+
+ @Test
+ public void testExtraction() throws Exception {
+
+ request.addParameter("j_username", "jdoe");
+ action.setHttpServletRequestSupplier(new ConstantSupplier<>(request));
+ action.initialize();
+
+ final Event result = action.execute(src);
+ assertNull(result);
+ assertEquals(context.getUsername(), "jdoe");
+ assertTrue(ac.isResultCacheable());
+ }
+
+ @Test
+ public void testExtraction_WithSSOBypass() throws Exception {
+
+ request.addParameter("j_username", "jdoe");
+ request.addParameter("donotcache", "1");
+ action.setHttpServletRequestSupplier(new ConstantSupplier<>(request));
+ action.initialize();
+
+ final Event result = action.execute(src);
+ assertNull(result);
+ assertEquals(context.getUsername(), "jdoe");
+ assertFalse(ac.isResultCacheable());
+ }
+
+ @Test
+ public void testExtraction_NoUsername() throws Exception {
+
+ action.setHttpServletRequestSupplier(new ConstantSupplier<>(request));
+ action.initialize();
+
+ final Event result = action.execute(src);
+ assertNotNull(result);
+ assert result != null;
+ assertEquals(result.getId(), AuthnEventIds.UNKNOWN_USERNAME);
+ }
+
+}
diff --git a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/PopulateWebAuthnAuthenticationContextTest.java b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/PopulateWebAuthnAuthenticationContextTest.java
new file mode 100644
index 0000000..6ed6fc9
--- /dev/null
+++ b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/impl/PopulateWebAuthnAuthenticationContextTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import org.opensaml.profile.action.EventIds;
+import org.springframework.webflow.execution.Event;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.authn.context.AuthenticationContext;
+import net.shibboleth.idp.plugin.authn.webauthn.context.WebAuthnAuthenticationContext;
+import net.shibboleth.shared.component.ComponentInitializationException;
+
+/**
+ * Tests for {@link PopulateWebAuthnAuthenticationContext}
+ */
+public class PopulateWebAuthnAuthenticationContextTest extends AbstractWebAuthnTest {
+
+ private PopulateWebAuthnAuthenticationContext action;
+
+ @Override
+ @BeforeMethod
+ public void setup() throws Exception {
+ super.setup();
+ action = new PopulateWebAuthnAuthenticationContext();
+
+ }
+
+ @Test
+ public void testPopulateContext() throws ComponentInitializationException {
+ action.setUsernameLookupStrategy(prc -> "jdoe");
+ action.initialize();
+
+ final Event result = action.execute(src);
+ assertNull(result);
+ final var authnCtxt = ac.getSubcontext(WebAuthnAuthenticationContext.class);
+ assertNotNull(authnCtxt);
+ assert authnCtxt != null;
+ assertEquals(authnCtxt.getUsername(), "jdoe");
+ }
+
+ @Test
+ public void testPopulateContext_WithUpdateConsumer() throws ComponentInitializationException {
+ action.setUsernameLookupStrategy(prc -> "jdoe");
+ action.setContextUpdateConsumer(prc ->
+ prc.ensureSubcontext(AuthenticationContext.class)
+ .ensureSubcontext(WebAuthnAuthenticationContext.class)
+ .setUsernameless(true));
+ action.initialize();
+
+ final Event result = action.execute(src);
+ assertNull(result);
+ final var authnCtxt = ac.getSubcontext(WebAuthnAuthenticationContext.class);
+ assertNotNull(authnCtxt);
+ assert authnCtxt != null;
+ assertEquals(authnCtxt.getUsername(), "jdoe");
+ assertTrue(authnCtxt.isUsernameless());
+ }
+
+ @Test
+ public void testPopulateContext_NullUsername_Required() throws ComponentInitializationException {
+ action.setUsernameRequired(true);
+ action.setUsernameLookupStrategy(prc -> null);
+ action.initialize();
+
+ final Event result = action.execute(src);
+ assertNotNull(result);
+ final var authnCtxt = ac.getSubcontext(WebAuthnAuthenticationContext.class);
+ assertNull(authnCtxt);
+ assert result != null;
+ assertEquals(result.getId(),EventIds.INVALID_PROFILE_CTX);
+ }
+
+ @Test
+ public void testPopulateContext_NullUsername_NotRequired() throws ComponentInitializationException {
+ action.setUsernameRequired(false);
+ action.setUsernameLookupStrategy(prc -> null);
+ action.initialize();
+
+ final Event result = action.execute(src);
+ assertNull(result);
+ final var authnCtxt = ac.getSubcontext(WebAuthnAuthenticationContext.class);
+ assertNotNull(authnCtxt);
+ assert authnCtxt != null;
+ assertNull(authnCtxt.getUsername());
+ }
+
+
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list