test(jans-fido2): add JUnit 5 coverage for Fido2MetricsData DTO#14139
test(jans-fido2): add JUnit 5 coverage for Fido2MetricsData DTO#14139imran-ishaq wants to merge 1 commit into
Conversation
Signed-off-by: imran <imranishaq7071@gmail.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Prepare
Description
Adds JUnit 5 test coverage for
Fido2MetricsData, the transport DTO that carries every FIDO2 passkey operation event (registration, authentication, fallback) from the recording code path through to persistence and the REST analytics responses. The new test class locks the 12 snake_case JSON keys that form the REST API contract, the default constructor's UTC timestamp behavior, the@JsonIgnoreProperties(ignoreUnknown=true)forward-compatibility guarantee, the JSON serialize → deserialize roundtrip, and the nestedDeviceInfoinner-class mapping. Test-only change; no production code orpom.xmlchanges. Step 3 of the FIDO2 metrics test rollout.Target issue
Fido2MetricsData(jans-fido2/model/src/main/java/io/jans/fido2/model/metric/Fido2MetricsData.java) is the transport DTO that carries every passkey operation event — registration, authentication, fallback — from the recording code path through to persistence and through the REST analytics responses. It has 22 fields annotated with Jackson@JsonPropertysnake-case names (e.g.,operationType→"operation_type",durationMs→"duration_ms"), a default constructor that auto-stampstimestampto the current UTC time, and a nestedDeviceInfostatic inner class with its own 6 JSON-mapped fields. None of this is tested today.Two specific regressions would be silent failures:
@JsonPropertyvalue drifts, the REST API contract silently breaks for consumers and previously serialized payloads stop deserializing.This PR is step 3 of the FIDO2 metrics test rollout (steps 1 and 2 added
Fido2MetricTypeTestandFido2MetricsConstantsTest).closes #14123
Implementation Details
Adds a single new JUnit 5 test class —
jans-fido2/model/src/test/java/io/jans/fido2/model/metric/Fido2MetricsDataTest.java— with 7 grouped@Testmethods, one per spec'd behavior:testDefaultConstructorStampsUtcTimestamptestGetterSetterRoundtripCoversEachValueTypetestJsonSerializationUsesSnakeCaseKeystestJsonSerializationDeserializationRoundtrip@JsonIgnoreProperties(ignoreUnknown=true)honoredtestJsonDeserializationIgnoresUnknownFieldsDeviceInfogetter/setter roundtriptestDeviceInfoGetterSetterRoundtripDeviceInfosnake_case key mappingtestDeviceInfoJsonUsesSnakeCaseKeysDesign choices worth flagging:
String,Long,Integer,Double,LocalDateTime,Map, nested type) — the same wiring class of bugs is caught without adding 40+ near-identical methods.LocalDateTime.now(UTC)before and after construction and asserts the stampedtimestampfalls in the window. Robust against sub-millisecond clock jitter withoutThread.sleep.ObjectMapperis configured withJavaTimeModuleso theLocalDateTimeround-trip is meaningful. Jackson (jackson-databind+jackson-datatype-jsr310) is already available transitively on the test classpath viajans-auth-model→jans-core-util— no new direct dependencies were added.Scope:
src/test.src/main.pom.xmlchanges.Local verification:
mvn -pl model -am testfromjans-fido2/— 7 tests, 0 failures, 0 errors.Test and Document the changes
Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with
docs:to indicate documentation changes or if the below checklist is not selected.