@@ -51,6 +51,7 @@ import com.yubico.webauthn.data.UserIdentity
51
51
import com .yubico .webauthn .data .UserVerificationRequirement
52
52
import com .yubico .webauthn .exception .InvalidSignatureCountException
53
53
import com .yubico .webauthn .extension .appid .AppId
54
+ import com .yubico .webauthn .test .Helpers
54
55
import com .yubico .webauthn .test .Util .toStepWithUtilities
55
56
import org .junit .runner .RunWith
56
57
import org .scalacheck .Gen
@@ -73,14 +74,6 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
73
74
private def sha256 (bytes : ByteArray ): ByteArray = crypto.hash(bytes)
74
75
private def sha256 (data : String ): ByteArray = sha256(new ByteArray (data.getBytes(Charset .forName(" UTF-8" ))))
75
76
76
- private val emptyCredentialRepository = new CredentialRepository {
77
- override def getCredentialIdsForUsername (username : String ): java.util.Set [PublicKeyCredentialDescriptor ] = Set .empty.asJava
78
- override def getUserHandleForUsername (username : String ): Optional [ByteArray ] = None .asJava
79
- override def getUsernameForUserHandle (userHandle : ByteArray ): Optional [String ] = None .asJava
80
- override def lookup (credentialId : ByteArray , userHandle : ByteArray ): Optional [RegisteredCredential ] = None .asJava
81
- override def lookupAll (credentialId : ByteArray ): java.util.Set [RegisteredCredential ] = Set .empty.asJava
82
- }
83
-
84
77
private object Defaults {
85
78
86
79
val rpId = RelyingPartyIdentity .builder().id(" localhost" ).name(" Test party" ).build()
@@ -123,29 +116,6 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
123
116
124
117
private def getPublicKeyBytes (credentialKey : KeyPair ): ByteArray = WebAuthnTestCodecs .ecPublicKeyToCose(credentialKey.getPublic.asInstanceOf [ECPublicKey ])
125
118
126
- private def credRepoWithUser (user : UserIdentity , credential : RegisteredCredential ): CredentialRepository = new CredentialRepository {
127
- override def getCredentialIdsForUsername (username : String ): java.util.Set [PublicKeyCredentialDescriptor ] =
128
- if (username == user.getName)
129
- Set (PublicKeyCredentialDescriptor .builder().id(credential.getCredentialId).build()).asJava
130
- else Set .empty.asJava
131
- override def getUserHandleForUsername (username : String ): Optional [ByteArray ] =
132
- if (username == user.getName)
133
- Some (user.getId).asJava
134
- else None .asJava
135
- override def getUsernameForUserHandle (userHandle : ByteArray ): Optional [String ] =
136
- if (userHandle == user.getId)
137
- Some (user.getName).asJava
138
- else None .asJava
139
- override def lookup (credentialId : ByteArray , userHandle : ByteArray ): Optional [RegisteredCredential ] =
140
- if (credentialId == credential.getCredentialId && userHandle == user.getId)
141
- Some (credential).asJava
142
- else None .asJava
143
- override def lookupAll (credentialId : ByteArray ): java.util.Set [RegisteredCredential ] =
144
- if (credentialId == credential.getCredentialId)
145
- Set (credential).asJava
146
- else Set .empty.asJava
147
- }
148
-
149
119
def finishAssertion (
150
120
allowCredentials : Option [java.util.List [PublicKeyCredentialDescriptor ]] = Some (List (PublicKeyCredentialDescriptor .builder().id(Defaults .credentialId).build()).asJava),
151
121
allowOriginPort : Boolean = false ,
@@ -242,7 +212,7 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
242
212
it(s " If the parameter is not set, or set to empty, the default of ${default} is used. " ) {
243
213
val rp = RelyingParty .builder()
244
214
.identity(Defaults .rpId)
245
- .credentialRepository(emptyCredentialRepository )
215
+ .credentialRepository(Helpers . CredentialRepository .empty )
246
216
.build()
247
217
val request1 = rp.startAssertion(StartAssertionOptions .builder().build())
248
218
val request2 = rp.startAssertion(StartAssertionOptions .builder().userVerification(Optional .empty[UserVerificationRequirement ]).build())
@@ -254,7 +224,7 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
254
224
it(s " If the parameter is set, that value is used. " ) {
255
225
val rp = RelyingParty .builder()
256
226
.identity(Defaults .rpId)
257
- .credentialRepository(emptyCredentialRepository )
227
+ .credentialRepository(Helpers . CredentialRepository .empty )
258
228
.build()
259
229
260
230
forAll { uv : UserVerificationRequirement =>
@@ -397,7 +367,7 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
397
367
describe(" 3. Using credential’s id attribute (or the corresponding rawId, if base64url encoding is inappropriate for your use case), look up the corresponding credential public key." ) {
398
368
it(" Fails if the credential ID is unknown." ) {
399
369
val steps = finishAssertion(
400
- credentialRepository = Some (emptyCredentialRepository )
370
+ credentialRepository = Some (Helpers . CredentialRepository .empty )
401
371
)
402
372
val step : steps.Step3 = new steps.Step3 (Defaults .username, Defaults .userHandle, Nil .asJava)
403
373
@@ -408,7 +378,7 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
408
378
409
379
it(" Succeeds if the credential ID is known." ) {
410
380
val steps = finishAssertion(
411
- credentialRepository = Some (credRepoWithUser (
381
+ credentialRepository = Some (Helpers . CredentialRepository .withUser (
412
382
Defaults .user,
413
383
RegisteredCredential .builder()
414
384
.credentialId(Defaults .credentialId)
@@ -1144,7 +1114,7 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
1144
1114
describe(" 17. If the signature counter value authData.signCount is nonzero or the value stored in conjunction with credential’s id attribute is nonzero, then run the following sub-step:" ) {
1145
1115
describe(" If the signature counter value authData.signCount is" ) {
1146
1116
def credentialRepository (signatureCount : Long ) =
1147
- credRepoWithUser (
1117
+ Helpers . CredentialRepository .withUser (
1148
1118
Defaults .user,
1149
1119
RegisteredCredential .builder()
1150
1120
.credentialId(Defaults .credentialId)
@@ -1304,7 +1274,7 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
1304
1274
new TypeReference [PublicKeyCredential [AuthenticatorAssertionResponse , ClientAssertionExtensionOutputs ]](){}
1305
1275
)
1306
1276
1307
- val credRepo = credRepoWithUser (
1277
+ val credRepo = Helpers . CredentialRepository .withUser (
1308
1278
testData.userId,
1309
1279
RegisteredCredential .builder()
1310
1280
.credentialId(testData.response.getId)
@@ -1413,7 +1383,7 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
1413
1383
val credId : ByteArray = credData.getCredentialId
1414
1384
val publicKeyBytes : ByteArray = credData.getCredentialPublicKey
1415
1385
1416
- val credRepo = credRepoWithUser (
1386
+ val credRepo = Helpers . CredentialRepository .withUser (
1417
1387
registrationRequest.getUser,
1418
1388
RegisteredCredential .builder()
1419
1389
.credentialId(registrationResponse.getId)
@@ -1448,7 +1418,7 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
1448
1418
1449
1419
val rp = RelyingParty .builder()
1450
1420
.identity(RelyingPartyIdentity .builder().id(" localhost" ).name(" Test RP" ).build())
1451
- .credentialRepository(credRepoWithUser (registrationTestData.userId, RegisteredCredential .builder()
1421
+ .credentialRepository(Helpers . CredentialRepository .withUser (registrationTestData.userId, RegisteredCredential .builder()
1452
1422
.credentialId(registrationTestData.response.getId)
1453
1423
.userHandle(registrationTestData.userId.getId)
1454
1424
.publicKeyCose(registrationTestData.response.getResponse.getParsedAuthenticatorData.getAttestedCredentialData.get.getCredentialPublicKey)
@@ -1474,7 +1444,7 @@ class RelyingPartyAssertionSpec extends FunSpec with Matchers with GeneratorDriv
1474
1444
1475
1445
val rp = RelyingParty .builder()
1476
1446
.identity(RelyingPartyIdentity .builder().id(" localhost" ).name(" Test RP" ).build())
1477
- .credentialRepository(credRepoWithUser (registrationTestData.userId, RegisteredCredential .builder()
1447
+ .credentialRepository(Helpers . CredentialRepository .withUser (registrationTestData.userId, RegisteredCredential .builder()
1478
1448
.credentialId(registrationTestData.response.getId)
1479
1449
.userHandle(registrationTestData.userId.getId)
1480
1450
.publicKeyCose(registrationTestData.response.getResponse.getParsedAuthenticatorData.getAttestedCredentialData.get.getCredentialPublicKey)
0 commit comments