Skip to content

Commit fa5da9c

Browse files
committed
Extract slightly non-default test for YubiKey 5 NFC FIPS
1 parent 1bb72e2 commit fa5da9c

File tree

1 file changed

+92
-72
lines changed

1 file changed

+92
-72
lines changed

webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyCeremoniesSpec.scala

Lines changed: 92 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -53,81 +53,86 @@ class RelyingPartyCeremoniesSpec
5353
.credentialRepository(credentialRepo)
5454
.build()
5555

56-
testWithEachProvider { it =>
57-
describe("The default RelyingParty settings") {
56+
private def createCheck(
57+
modRp: RelyingParty => RelyingParty = identity
58+
)(testData: RealExamples.Example): Unit = {
59+
val registrationRp =
60+
modRp(newRp(testData, Helpers.CredentialRepository.empty))
5861

59-
describe("can register and then authenticate") {
60-
def check(testData: RealExamples.Example): Unit = {
61-
val registrationRp =
62-
newRp(testData, Helpers.CredentialRepository.empty)
63-
64-
val registrationResult = registrationRp.finishRegistration(
65-
FinishRegistrationOptions
66-
.builder()
67-
.request(
68-
PublicKeyCredentialCreationOptions
69-
.builder()
70-
.rp(testData.rp)
71-
.user(testData.user)
72-
.challenge(testData.attestation.challenge)
73-
.pubKeyCredParams(
74-
List(PublicKeyCredentialParameters.ES256).asJava
75-
)
76-
.build()
77-
)
78-
.response(testData.attestation.credential)
79-
.build()
80-
);
81-
82-
registrationResult.getKeyId.getId should equal(
83-
testData.attestation.credential.getId
84-
)
85-
registrationResult.isAttestationTrusted should be(false)
86-
registrationResult.getAttestationMetadata.isPresent should be(false)
87-
88-
val assertionRp = newRp(
89-
testData,
90-
Helpers.CredentialRepository.withUser(
91-
testData.user,
92-
Helpers.toRegisteredCredential(testData.user, registrationResult),
93-
),
94-
)
95-
96-
val assertionResult = assertionRp.finishAssertion(
97-
FinishAssertionOptions
98-
.builder()
99-
.request(
100-
AssertionRequest
101-
.builder()
102-
.publicKeyCredentialRequestOptions(
103-
PublicKeyCredentialRequestOptions
62+
val registrationResult = registrationRp.finishRegistration(
63+
FinishRegistrationOptions
64+
.builder()
65+
.request(
66+
PublicKeyCredentialCreationOptions
67+
.builder()
68+
.rp(testData.rp)
69+
.user(testData.user)
70+
.challenge(testData.attestation.challenge)
71+
.pubKeyCredParams(
72+
List(PublicKeyCredentialParameters.ES256).asJava
73+
)
74+
.build()
75+
)
76+
.response(testData.attestation.credential)
77+
.build()
78+
);
79+
80+
registrationResult.getKeyId.getId should equal(
81+
testData.attestation.credential.getId
82+
)
83+
registrationResult.isAttestationTrusted should be(false)
84+
registrationResult.getAttestationMetadata.isPresent should be(false)
85+
86+
val assertionRp = newRp(
87+
testData,
88+
Helpers.CredentialRepository.withUser(
89+
testData.user,
90+
Helpers.toRegisteredCredential(testData.user, registrationResult),
91+
),
92+
).toBuilder
93+
.allowUnrequestedExtensions(true)
94+
.build()
95+
96+
val assertionResult = assertionRp.finishAssertion(
97+
FinishAssertionOptions
98+
.builder()
99+
.request(
100+
AssertionRequest
101+
.builder()
102+
.publicKeyCredentialRequestOptions(
103+
PublicKeyCredentialRequestOptions
104+
.builder()
105+
.challenge(testData.assertion.challenge)
106+
.allowCredentials(
107+
List(
108+
PublicKeyCredentialDescriptor
104109
.builder()
105-
.challenge(testData.assertion.challenge)
106-
.allowCredentials(
107-
List(
108-
PublicKeyCredentialDescriptor
109-
.builder()
110-
.id(testData.assertion.id)
111-
.build()
112-
).asJava
113-
)
110+
.id(testData.assertion.id)
114111
.build()
115-
)
116-
.username(testData.user.getName)
117-
.build()
118-
)
119-
.response(testData.assertion.credential)
120-
.build()
121-
)
122-
123-
assertionResult.isSuccess should be(true)
124-
assertionResult.getCredentialId should equal(testData.assertion.id)
125-
assertionResult.getUserHandle should equal(testData.user.getId)
126-
assertionResult.getUsername should equal(testData.user.getName)
127-
assertionResult.getSignatureCount should be >= testData.attestation.authenticatorData.getSignatureCounter
128-
assertionResult.isSignatureCounterValid should be(true)
129-
}
112+
).asJava
113+
)
114+
.build()
115+
)
116+
.username(testData.user.getName)
117+
.build()
118+
)
119+
.response(testData.assertion.credential)
120+
.build()
121+
)
122+
123+
assertionResult.isSuccess should be(true)
124+
assertionResult.getCredentialId should equal(testData.assertion.id)
125+
assertionResult.getUserHandle should equal(testData.user.getId)
126+
assertionResult.getUsername should equal(testData.user.getName)
127+
assertionResult.getSignatureCount should be >= testData.attestation.authenticatorData.getSignatureCounter
128+
assertionResult.isSignatureCounterValid should be(true)
129+
}
130+
131+
testWithEachProvider { it =>
132+
describe("The default RelyingParty settings") {
133+
val check = createCheck()(_)
130134

135+
describe("can register and then authenticate") {
131136
it("a YubiKey NEO.") {
132137
check(RealExamples.YubiKeyNeo)
133138
}
@@ -161,9 +166,11 @@ class RelyingPartyCeremoniesSpec
161166
it("a Security Key NFC by Yubico.") {
162167
check(RealExamples.SecurityKeyNfc)
163168
}
164-
it("a YubiKey 5 NFC FIPS.") {
169+
170+
ignore("a YubiKey 5 NFC FIPS.") { // TODO Un-ignore when allowUnrequestedExtensions default changes to true
165171
check(RealExamples.YubikeyFips5Nfc)
166172
}
173+
167174
it("a YubiKey 5Ci FIPS.") {
168175
check(RealExamples.Yubikey5ciFips)
169176
}
@@ -176,5 +183,18 @@ class RelyingPartyCeremoniesSpec
176183
}
177184
}
178185
}
186+
187+
describe("The default RelyingParty settings, but with allowUnrequestedExtensions(true)") {
188+
189+
describe("can register and then authenticate") {
190+
val check = createCheck(rp =>
191+
rp.toBuilder.allowUnrequestedExtensions(true).build()
192+
)(_)
193+
194+
it("a YubiKey 5 NFC FIPS.") { // TODO Delete when allowUnrequestedExtensions default changes to true
195+
check(RealExamples.YubikeyFips5Nfc)
196+
}
197+
}
198+
}
179199
}
180200
}

0 commit comments

Comments
 (0)