From 5255a43ce401bb28e0bcb59a5865c0e0b6901e05 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Thu, 17 Apr 2025 00:44:44 +0700 Subject: [PATCH 1/2] [java]: Fix getCredentials from VirtualAuthenticator Signed-off-by: Viet Nguyen Duc --- .../org/openqa/selenium/virtualauthenticator/Credential.java | 2 +- .../virtualauthenticator/VirtualAuthenticatorTest.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/java/src/org/openqa/selenium/virtualauthenticator/Credential.java b/java/src/org/openqa/selenium/virtualauthenticator/Credential.java index 486ff04b5d0cc..8e525d332a629 100644 --- a/java/src/org/openqa/selenium/virtualauthenticator/Credential.java +++ b/java/src/org/openqa/selenium/virtualauthenticator/Credential.java @@ -66,7 +66,7 @@ public static Credential fromMap(Map map) { Object credentialId = Require.nonNull("credentialId", map.get("credentialId")); Object isResidentCredential = Require.nonNull("isResidentCredential", map.get("isResidentCredential")); - Object rpId = Require.nonNull("rpId", map.get("rpId")); + Object rpId = map.get("rpId"); Object privateKey = Require.nonNull("privateKey", map.get("privateKey")); Object userHandle = map.get("userHandle"); Object signCount = Require.nonNull("signCount", map.get("signCount")); diff --git a/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java b/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java index b7759733956f9..90794ec2b8e9e 100644 --- a/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java +++ b/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java @@ -189,6 +189,7 @@ void testAddNonResidentCredential() { Credential.createNonResidentCredential( credentialId, "localhost", privateKey, /* signCount= */ 0); authenticator.addCredential(credential); + authenticator.getCredentials(); // Attempt to use the credential to generate an assertion. Object response = getAssertionFor(Arrays.asList(1, 2, 3, 4)); @@ -215,6 +216,7 @@ void testAddNonResidentCredentialWhenAuthenticatorUsesU2FProtocol() { Credential.createNonResidentCredential( credentialId, "localhost", privateKey, /* signCount= */ 0); authenticator.addCredential(credential); + authenticator.getCredentials(); // Attempt to use the credential to generate an assertion. Object response = getAssertionFor(Arrays.asList(1, 2, 3, 4)); @@ -231,6 +233,7 @@ void testAddResidentCredential() { Credential.createResidentCredential( credentialId, "localhost", privateKey, userHandle, /* signCount= */ 0); authenticator.addCredential(credential); + authenticator.getCredentials(); // Attempt to use the credential to generate an assertion. Notice we use an // empty allowCredentials array. @@ -265,6 +268,7 @@ void testAddResidentCredentialNotSupportedWhenAuthenticatorUsesU2FProtocol() { Credential.createResidentCredential( credentialId, "localhost", privateKey, userHandle, /* signCount= */ 0); authenticator.addCredential(credential); + authenticator.getCredentials(); }); } From aafd4a15e27ea86b9055f578fe04377f8e327dc3 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Fri, 18 Apr 2025 23:12:50 +0700 Subject: [PATCH 2/2] Fix method addCredential() --- .../org/openqa/selenium/remote/RemoteWebDriver.java | 10 ++++------ .../selenium/virtualauthenticator/Credential.java | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java index 332faa86d4c25..870f701bce5ca 100644 --- a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java +++ b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java @@ -32,6 +32,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -1248,12 +1249,9 @@ public String getId() { @Override public void addCredential(Credential credential) { - execute( - DriverCommand.ADD_CREDENTIAL, - Stream.concat( - credential.toMap().entrySet().stream(), - Stream.of(Map.entry("authenticatorId", id))) - .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue))); + Map map = new HashMap<>(credential.toMap()); + map.put("authenticatorId", id); + execute(DriverCommand.ADD_CREDENTIAL, map); } @Override diff --git a/java/src/org/openqa/selenium/virtualauthenticator/Credential.java b/java/src/org/openqa/selenium/virtualauthenticator/Credential.java index 8e525d332a629..486ff04b5d0cc 100644 --- a/java/src/org/openqa/selenium/virtualauthenticator/Credential.java +++ b/java/src/org/openqa/selenium/virtualauthenticator/Credential.java @@ -66,7 +66,7 @@ public static Credential fromMap(Map map) { Object credentialId = Require.nonNull("credentialId", map.get("credentialId")); Object isResidentCredential = Require.nonNull("isResidentCredential", map.get("isResidentCredential")); - Object rpId = map.get("rpId"); + Object rpId = Require.nonNull("rpId", map.get("rpId")); Object privateKey = Require.nonNull("privateKey", map.get("privateKey")); Object userHandle = map.get("userHandle"); Object signCount = Require.nonNull("signCount", map.get("signCount"));