Skip to content

Commit 84a80f8

Browse files
committed
Add tests for to/fromJson methods in PublicKeyCredentialCreationOptions and AssertionRequest
1 parent 08ca029 commit 84a80f8

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ public String toCredentialsGetJson() throws JsonProcessingException {
101101
return publicKeyCredentialRequestOptions.toCredentialsGetJson();
102102
}
103103

104+
public String toJson() throws JsonProcessingException {
105+
return "";
106+
}
107+
108+
public static AssertionRequest fromJson(String json) throws JsonProcessingException {
109+
return null;
110+
}
111+
104112
public static AssertionRequestBuilder.MandatoryStages builder() {
105113
return new AssertionRequestBuilder.MandatoryStages();
106114
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ public String toCredentialsCreateJson() throws JsonProcessingException {
169169
return json.writeValueAsString(result);
170170
}
171171

172+
public String toJson() throws JsonProcessingException {
173+
return "";
174+
}
175+
176+
public static PublicKeyCredentialCreationOptions fromJson(String json) throws JsonProcessingException {
177+
return null;
178+
}
179+
172180
public Optional<Long> getTimeout() {
173181
return Optional.ofNullable(timeout);
174182
}

webauthn-server-core/src/test/scala/com/yubico/webauthn/data/JsonIoSpec.scala

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,38 @@ class JsonIoSpec
384384
) should equal(pkcco)
385385
}
386386
}
387+
388+
describe("has a toJson() method and a fromJson(String) factory method") {
389+
it("which behave like a Jackson ObjectMapper.") {
390+
forAll { req: PublicKeyCredentialCreationOptions =>
391+
println(req)
392+
val json1 = req.toJson
393+
val json2 = JacksonCodecs.json.writeValueAsString(req)
394+
json1 should equal(json2)
395+
396+
val parsed1 = PublicKeyCredentialCreationOptions.fromJson(json1)
397+
val parsed2 = JacksonCodecs.json.readValue(
398+
json2,
399+
classOf[PublicKeyCredentialCreationOptions],
400+
)
401+
parsed1 should equal(parsed2)
402+
}
403+
}
404+
405+
it("which are stable over multiple serialization round-trips.") {
406+
forAll { req: PublicKeyCredentialCreationOptions =>
407+
println(req)
408+
val encoded = req.toJson
409+
val decoded = PublicKeyCredentialCreationOptions.fromJson(encoded)
410+
val reencoded = decoded.toJson
411+
val redecoded = PublicKeyCredentialCreationOptions.fromJson(reencoded)
412+
413+
decoded should equal(req)
414+
redecoded should equal(req)
415+
encoded should equal(reencoded)
416+
}
417+
}
418+
}
387419
}
388420

389421
describe("The class PublicKeyCredentialRequestOptions") {
@@ -413,6 +445,36 @@ class JsonIoSpec
413445
) should equal(req.getPublicKeyCredentialRequestOptions)
414446
}
415447
}
448+
449+
describe("has a toJson() method and a fromJson(String) factory method") {
450+
it("which behave like a Jackson ObjectMapper.") {
451+
forAll { req: AssertionRequest =>
452+
println(req)
453+
val json1 = req.toJson
454+
val json2 = JacksonCodecs.json.writeValueAsString(req)
455+
456+
val parsed1 = AssertionRequest.fromJson(json1)
457+
val parsed2 =
458+
JacksonCodecs.json.readValue(json2, classOf[AssertionRequest])
459+
json1 should equal(json2)
460+
parsed1 should equal(parsed2)
461+
}
462+
}
463+
464+
it("which are stable over multiple serialization round-trips.") {
465+
forAll { req: AssertionRequest =>
466+
println(req)
467+
val encoded = req.toJson
468+
val decoded = AssertionRequest.fromJson(encoded)
469+
val reencoded = decoded.toJson
470+
val redecoded = AssertionRequest.fromJson(reencoded)
471+
472+
decoded should equal(req)
473+
redecoded should equal(req)
474+
encoded should equal(reencoded)
475+
}
476+
}
477+
}
416478
}
417479

418480
}

0 commit comments

Comments
 (0)