@@ -32,6 +32,7 @@ import com.yubico.webauthn.data.AuthenticatorAttachment
32
32
import com .yubico .webauthn .data .AuthenticatorSelectionCriteria
33
33
import com .yubico .webauthn .data .AuthenticatorTransport
34
34
import com .yubico .webauthn .data .ByteArray
35
+ import com .yubico .webauthn .data .Generators .Extensions .registrationExtensionInputs
35
36
import com .yubico .webauthn .data .Generators ._
36
37
import com .yubico .webauthn .data .PublicKeyCredentialDescriptor
37
38
import com .yubico .webauthn .data .PublicKeyCredentialParameters
@@ -296,21 +297,84 @@ class RelyingPartyStartOperationSpec
296
297
result.getExtensions.getAppidExclude.asScala should equal(None )
297
298
}
298
299
299
- it(" by default always sets the credProps extension." ) {
300
- forAll { extensions : RegistrationExtensionInputs =>
301
- println(extensions.getExtensionIds)
302
- println(extensions)
303
-
304
- val rp = relyingParty(userId = userId)
300
+ it(" does not override the appidExclude extension with an empty value if already non-null in StartRegistrationOptions." ) {
301
+ forAll { requestAppId : AppId =>
302
+ val rp = relyingParty(appId = None , userId = userId)
305
303
val result = rp.startRegistration(
306
304
StartRegistrationOptions
307
305
.builder()
308
306
.user(userId)
309
- .extensions(extensions)
307
+ .extensions(
308
+ RegistrationExtensionInputs
309
+ .builder()
310
+ .appidExclude(requestAppId)
311
+ .build()
312
+ )
310
313
.build()
311
314
)
312
315
313
- result.getExtensions.getCredProps should be(true )
316
+ result.getExtensions.getAppidExclude.asScala should equal(
317
+ Some (requestAppId)
318
+ )
319
+ }
320
+ }
321
+
322
+ it(" does not override the appidExclude extension if already non-null in StartRegistrationOptions." ) {
323
+ forAll { (requestAppId : AppId , rpAppId : AppId ) =>
324
+ whenever(requestAppId != rpAppId) {
325
+ val rp = relyingParty(appId = Some (rpAppId), userId = userId)
326
+ val result = rp.startRegistration(
327
+ StartRegistrationOptions
328
+ .builder()
329
+ .user(userId)
330
+ .extensions(
331
+ RegistrationExtensionInputs
332
+ .builder()
333
+ .appidExclude(requestAppId)
334
+ .build()
335
+ )
336
+ .build()
337
+ )
338
+
339
+ result.getExtensions.getAppidExclude.asScala should equal(
340
+ Some (requestAppId)
341
+ )
342
+ }
343
+ }
344
+ }
345
+
346
+ it(" by default sets the credProps extension." ) {
347
+ forAll(registrationExtensionInputs(credPropsGen = None )) {
348
+ extensions : RegistrationExtensionInputs =>
349
+ println(extensions.getExtensionIds)
350
+ println(extensions)
351
+
352
+ val rp = relyingParty(userId = userId)
353
+ val result = rp.startRegistration(
354
+ StartRegistrationOptions
355
+ .builder()
356
+ .user(userId)
357
+ .extensions(extensions)
358
+ .build()
359
+ )
360
+
361
+ result.getExtensions.getCredProps should be(true )
362
+ }
363
+ }
364
+
365
+ it(" does not override the credProps extension if explicitly set to false in StartRegistrationOptions." ) {
366
+ forAll(registrationExtensionInputs(credPropsGen = Some (false ))) {
367
+ extensions : RegistrationExtensionInputs =>
368
+ val rp = relyingParty(userId = userId)
369
+ val result = rp.startRegistration(
370
+ StartRegistrationOptions
371
+ .builder()
372
+ .user(userId)
373
+ .extensions(extensions)
374
+ .build()
375
+ )
376
+
377
+ result.getExtensions.getCredProps should be(false )
314
378
}
315
379
}
316
380
@@ -629,6 +693,52 @@ class RelyingPartyStartOperationSpec
629
693
)
630
694
}
631
695
696
+ it(" does not override the appid extension with an empty value if already non-null in StartAssertionOptions." ) {
697
+ forAll { requestAppId : AppId =>
698
+ val rp = relyingParty(appId = None , userId = userId)
699
+ val result = rp.startAssertion(
700
+ StartAssertionOptions
701
+ .builder()
702
+ .username(userId.getName)
703
+ .extensions(
704
+ AssertionExtensionInputs
705
+ .builder()
706
+ .appid(requestAppId)
707
+ .build()
708
+ )
709
+ .build()
710
+ )
711
+
712
+ result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.asScala should equal(
713
+ Some (requestAppId)
714
+ )
715
+ }
716
+ }
717
+
718
+ it(" does not override the appid extension if already non-null in StartAssertionOptions." ) {
719
+ forAll { (requestAppId : AppId , rpAppId : AppId ) =>
720
+ whenever(requestAppId != rpAppId) {
721
+ val rp = relyingParty(appId = Some (rpAppId), userId = userId)
722
+ val result = rp.startAssertion(
723
+ StartAssertionOptions
724
+ .builder()
725
+ .username(userId.getName)
726
+ .extensions(
727
+ AssertionExtensionInputs
728
+ .builder()
729
+ .appid(requestAppId)
730
+ .build()
731
+ )
732
+ .build()
733
+ )
734
+
735
+ result.getPublicKeyCredentialRequestOptions.getExtensions.getAppid.asScala should equal(
736
+ Some (requestAppId)
737
+ )
738
+ }
739
+ }
740
+ }
741
+
632
742
it(" allows setting the timeout to empty." ) {
633
743
val req = relyingParty(userId = userId).startAssertion(
634
744
StartAssertionOptions
0 commit comments