Skip to content

[java]: Fix addCredential() in VirtualAuthenticator #15633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> map = new HashMap<>(credential.toMap());
map.put("authenticatorId", id);
execute(DriverCommand.ADD_CREDENTIAL, map);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want Map.copyOf(map) here to ensure immutability? Not certain it matters.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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.
Expand Down Expand Up @@ -265,6 +268,7 @@ void testAddResidentCredentialNotSupportedWhenAuthenticatorUsesU2FProtocol() {
Credential.createResidentCredential(
credentialId, "localhost", privateKey, userHandle, /* signCount= */ 0);
authenticator.addCredential(credential);
authenticator.getCredentials();
});
}

Expand Down
Loading