Skip to content

Commit c59ce2f

Browse files
committed
Add tests for *V2 features
1 parent 515900a commit c59ce2f

File tree

10 files changed

+9626
-563
lines changed

10 files changed

+9626
-563
lines changed

webauthn-server-core/src/main/java/com/yubico/webauthn/CredentialRecord.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.yubico.webauthn;
22

3+
import com.yubico.webauthn.data.AuthenticatorTransport;
34
import com.yubico.webauthn.data.ByteArray;
45
import java.util.Optional;
6+
import java.util.Set;
57
import lombok.NonNull;
68

79
/**
@@ -20,8 +22,10 @@ public interface CredentialRecord {
2022

2123
long getSignatureCount();
2224

23-
// @NonNull
24-
// Set<AuthenticatorTransport> getTransports();
25+
@NonNull
26+
default Optional<Set<AuthenticatorTransport>> getTransports() {
27+
return Optional.empty();
28+
}
2529

2630
// boolean isUvInitialized();
2731

webauthn-server-core/src/main/java/com/yubico/webauthn/FinishAssertionSteps.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ public Step7 nextStep() {
230230

231231
@Override
232232
public void validate() {
233+
assertTrue(
234+
!(request.getUsername().isPresent() && !usernameRepository.isPresent()),
235+
"Cannot set request username when usernameRepository is not configured.");
236+
233237
assertTrue(
234238
finalUserHandle.isPresent(),
235239
"Could not identify user to authenticate: none of requested username, requested user handle or response user handle are set.");

webauthn-server-core/src/main/java/com/yubico/webauthn/RegisteredCredential.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.yubico.webauthn.data.AttestedCredentialData;
3333
import com.yubico.webauthn.data.AuthenticatorAssertionResponse;
3434
import com.yubico.webauthn.data.AuthenticatorData;
35+
import com.yubico.webauthn.data.AuthenticatorTransport;
3536
import com.yubico.webauthn.data.ByteArray;
3637
import com.yubico.webauthn.data.COSEAlgorithmIdentifier;
3738
import com.yubico.webauthn.data.PublicKeyCredentialDescriptor;
@@ -41,6 +42,7 @@
4142
import java.security.PublicKey;
4243
import java.security.spec.InvalidKeySpecException;
4344
import java.util.Optional;
45+
import java.util.Set;
4446
import lombok.AccessLevel;
4547
import lombok.Builder;
4648
import lombok.Getter;
@@ -118,6 +120,8 @@ public PublicKey getParsedPublicKey()
118120
*/
119121
@Builder.Default private final long signatureCount = 0;
120122

123+
@Builder.Default private final Set<AuthenticatorTransport> transports = null;
124+
121125
/**
122126
* The state of the <a href="https://w3c.github.io/webauthn/#authdata-flags-be">BE flag</a> when
123127
* this credential was registered, if known.
@@ -172,16 +176,23 @@ private RegisteredCredential(
172176
@NonNull @JsonProperty("userHandle") ByteArray userHandle,
173177
@NonNull @JsonProperty("publicKeyCose") ByteArray publicKeyCose,
174178
@JsonProperty("signatureCount") long signatureCount,
179+
@JsonProperty("transports") Set<AuthenticatorTransport> transports,
175180
@JsonProperty("backupEligible") Boolean backupEligible,
176181
@JsonProperty("backupState") @JsonAlias("backedUp") Boolean backupState) {
177182
this.credentialId = credentialId;
178183
this.userHandle = userHandle;
179184
this.publicKeyCose = publicKeyCose;
180185
this.signatureCount = signatureCount;
186+
this.transports = transports;
181187
this.backupEligible = backupEligible;
182188
this.backupState = backupState;
183189
}
184190

191+
@Override
192+
public Optional<Set<AuthenticatorTransport>> getTransports() {
193+
return Optional.ofNullable(transports);
194+
}
195+
185196
/**
186197
* The state of the <a href="https://w3c.github.io/webauthn/#authdata-flags-be">BE flag</a> when
187198
* this credential was registered, if known.

webauthn-server-core/src/main/java/com/yubico/webauthn/RelyingPartyV2.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ FinishRegistrationSteps _finishRegistration(FinishRegistrationOptions options) {
463463
}
464464

465465
public AssertionRequest startAssertion(StartAssertionOptions startAssertionOptions) {
466+
if (startAssertionOptions.getUsername().isPresent() && usernameRepository == null) {
467+
throw new IllegalArgumentException(
468+
"StartAssertionOptions.username must not be set when usernameRepository is not configured.");
469+
}
470+
466471
PublicKeyCredentialRequestOptionsBuilder pkcro =
467472
PublicKeyCredentialRequestOptions.builder()
468473
.challenge(generateChallenge())

0 commit comments

Comments
 (0)