@@ -417,6 +417,50 @@ public void TestStringIsSerializable()
417417 Assert . Equal ( z1 , z2 ) ;
418418 }
419419
420+ [ Fact ]
421+ public void AuthenticatorSelection_ResidentKeyPreferred_SurvivesJsonRoundTrip ( )
422+ {
423+ // Arrange: Create AuthenticatorSelection with ResidentKey = Preferred
424+ var original = new AuthenticatorSelection
425+ {
426+ ResidentKey = ResidentKeyRequirement . Preferred ,
427+ UserVerification = UserVerificationRequirement . Preferred
428+ } ;
429+
430+ // Act: Serialize to JSON and deserialize back
431+ var json = JsonSerializer . Serialize ( original ) ;
432+ var deserialized = JsonSerializer . Deserialize < AuthenticatorSelection > ( json ) ;
433+
434+ // Assert: ResidentKey should still be Preferred after round-trip
435+ Assert . Equal ( ResidentKeyRequirement . Preferred , deserialized . ResidentKey ) ;
436+ }
437+
438+ [ Fact ]
439+ public void CredentialCreateOptions_ResidentKeyPreferred_SurvivesJsonRoundTrip ( )
440+ {
441+ // Arrange: This JSON has residentKey: "preferred" which should be preserved
442+ const string json = """
443+ {
444+ "rp": { "id": "some.rp.id", "name": "Some name" },
445+ "user": { "name": "someuserid", "id": "NjVmZGNiOTJiZjQyZjZmZDE0YzViODVk", "displayName": "The User 1234" },
446+ "challenge": "kauVQPwQtf4BlhOFObDfTQ",
447+ "pubKeyCredParams": [ { "type": "public-key", "alg": -7 }, { "type": "public-key", "alg": -257 } ],
448+ "timeout": 60000,
449+ "attestation": "none",
450+ "attestationFormats": [],
451+ "authenticatorSelection": { "residentKey": "preferred", "requireResidentKey": false, "userVerification": "preferred" },
452+ "hints": [],
453+ "excludeCredentials": []
454+ }
455+ """ ;
456+
457+ // Act: Deserialize the JSON
458+ var options = CredentialCreateOptions . FromJson ( json ) ;
459+
460+ // Assert: ResidentKey should be Preferred, not Discouraged
461+ Assert . Equal ( ResidentKeyRequirement . Preferred , options . AuthenticatorSelection . ResidentKey ) ;
462+ }
463+
420464 [ Fact ]
421465 public async Task TestFido2AssertionAsync ( )
422466 {
0 commit comments