Skip to content

Commit 51d922d

Browse files
committed
Fix test initialization errors
This fixes test errors like the following: ``` Exception com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot find a (Map) Key deserializer for type [simple type, class com.yubico.webauthn.data.PublicKeyCredentialDescriptor] [in thread "Test worker"] ``` which also by extension means even if we fix the deserializer resolution, `JsonIoSpec` will fail with `PublicKeyCredentialDescriptor` as keys because input/output JSON will not be identical after deserializing from just the credential ID. Therefore let's change the map key type to `ByteArray`. We can keep the `PublicKeyCredentialDescriptor` key type in setters, but transform to `ByteArray` keys during construction of the `PrfAuthenticationInput` value.
1 parent 8762c82 commit 51d922d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

webauthn-server-core/src/main/java/com/yubico/webauthn/data/AssertionExtensionInputs.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import com.yubico.webauthn.RelyingParty;
3131
import com.yubico.webauthn.StartAssertionOptions;
3232
import com.yubico.webauthn.extension.appid.AppId;
33-
import java.util.HashMap;
3433
import java.util.HashSet;
34+
import java.util.Map;
3535
import java.util.Optional;
3636
import java.util.Set;
3737
import lombok.Builder;
@@ -195,8 +195,10 @@ public AssertionExtensionInputsBuilder largeBlob(
195195
*/
196196
public AssertionExtensionInputsBuilder prf(
197197
Extensions.Prf.PrfValues eval,
198-
HashMap<PublicKeyCredentialDescriptor, Extensions.Prf.PrfValues> evalByCredential) {
199-
this.prf = new Extensions.Prf.PrfAuthenticationInput(eval, evalByCredential);
198+
Map<PublicKeyCredentialDescriptor, Extensions.Prf.PrfValues> evalByCredential) {
199+
this.prf =
200+
new Extensions.Prf.PrfAuthenticationInput(
201+
eval, Extensions.Prf.PrfAuthenticationInput.descriptorsToIds(evalByCredential));
200202
return this;
201203
}
202204

webauthn-server-core/src/main/java/com/yubico/webauthn/data/Extensions.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Arrays;
1818
import java.util.HashMap;
1919
import java.util.List;
20+
import java.util.Map;
2021
import java.util.Optional;
2122
import java.util.Set;
2223
import java.util.stream.Collectors;
@@ -800,14 +801,12 @@ public static class PrfAuthenticationInput {
800801
/** */
801802
@JsonProperty private final PrfValues eval;
802803

803-
@JsonProperty
804-
private final HashMap<PublicKeyCredentialDescriptor, PrfValues> evalByCredential;
804+
@JsonProperty private final Map<ByteArray, PrfValues> evalByCredential;
805805

806806
@JsonCreator
807807
public PrfAuthenticationInput(
808808
@JsonProperty("eval") PrfValues eval,
809-
@JsonProperty("evalByCredential")
810-
HashMap<PublicKeyCredentialDescriptor, PrfValues> evalByCredential) {
809+
@JsonProperty("evalByCredential") Map<ByteArray, PrfValues> evalByCredential) {
811810
this.eval = eval;
812811
this.evalByCredential = evalByCredential;
813812
}
@@ -816,9 +815,24 @@ public Optional<PrfValues> getEval() {
816815
return Optional.ofNullable(eval);
817816
}
818817

819-
public Optional<HashMap<PublicKeyCredentialDescriptor, PrfValues>> getEvalByCredential() {
818+
public Optional<Map<ByteArray, PrfValues>> getEvalByCredential() {
820819
return Optional.ofNullable(evalByCredential);
821820
}
821+
822+
static HashMap<ByteArray, PrfValues> descriptorsToIds(
823+
Map<PublicKeyCredentialDescriptor, PrfValues> evalByCredential) {
824+
return evalByCredential.entrySet().stream()
825+
.reduce(
826+
new HashMap<>(),
827+
(ebc, entry) -> {
828+
ebc.put(entry.getKey().getId(), entry.getValue());
829+
return ebc;
830+
},
831+
(a, b) -> {
832+
a.putAll(b);
833+
return a;
834+
});
835+
}
822836
}
823837

824838
/**

0 commit comments

Comments
 (0)