@@ -14,59 +14,10 @@ private static KeyCredential CreateSampleKey()
1414 {
1515 byte [ ] publicKey = "525341310008000003000000000100000000000000000000010001C1A78914457758B0B13C70C710C7F8548F3F9ED56AD4640B6E6A112655C98ECAC1CBD68A298F5686C08439428A97FE6FDF58D78EA481905182BAD684C2D9C5CDE1CDE34AA19742E8BBF58B953EAC4C562FCF598CC176B02DBE9FFFEF5937A65815C236F92892F7E511A1FEDD5483CB33F1EA715D68106180DED2432A293367114A6E325E62F93F73D7ECE4B6A2BCDB829D95C8645C3073B94BA7CB7515CD29042F0967201C6E24A77821E92A6C756DF79841ACBAAE11D90CA03B9FCD24EF9E304B5D35248A7BD70557399960277058AE3E99C7C7E2284858B7BF8B08CDD286964186A50A7FCBCC6A24F00FEE5B9698BBD3B1AEAD0CE81FEA461C0ABD716843A5" . HexToBinary ( ) ;
1616 Guid deviceId = Guid . Parse ( "47f577e3-d2d0-4a0a-8aca-e0501098bde4" ) ;
17- DateTime creationTime = new DateTime ( 2020 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
17+ DateTime creationTime = new ( 2020 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
1818 return new KeyCredential ( publicKey , deviceId , DummyDN , creationTime ) ;
1919 }
2020
21- [ TestMethod ]
22- public void KeyCredential_RoundTrip_DoubleQuoted ( )
23- {
24- KeyCredential key = CreateSampleKey ( ) ;
25- string json = key . ToJson ( ) ;
26- KeyCredential result = KeyCredential . ParseJson ( json ) ;
27- Assert . IsNotNull ( result ) ;
28- Assert . AreEqual ( key . Identifier , result . Identifier ) ;
29- Assert . AreEqual ( key . DeviceId , result . DeviceId ) ;
30- Assert . AreEqual ( key . CreationTime , result . CreationTime ) ;
31- }
32-
33- [ TestMethod ]
34- public void KeyCredential_Deserialize_SingleQuoted_Input ( )
35- {
36- KeyCredential key = CreateSampleKey ( ) ;
37- string json = key . ToJson ( ) . Replace ( '"' , '\' ' ) ;
38- KeyCredential result = KeyCredential . ParseJson ( json ) ;
39- Assert . IsNotNull ( result ) ;
40- Assert . AreEqual ( key . DeviceId , result . DeviceId ) ;
41- }
42-
43- [ TestMethod ]
44- public void KeyCredential_Deserialize_TrailingComma_And_Comments ( )
45- {
46- KeyCredential key = CreateSampleKey ( ) ;
47- string json = key . ToJson ( ) ;
48- string jsonWithComment = json . Insert ( 1 , "\n // comment\n " ) ;
49- jsonWithComment = jsonWithComment . Substring ( 0 , jsonWithComment . Length - 1 ) + ",\n }" ;
50- KeyCredential result = KeyCredential . ParseJson ( jsonWithComment ) ;
51- Assert . IsNotNull ( result ) ;
52- Assert . AreEqual ( key . DeviceId , result . DeviceId ) ;
53- }
54-
55- [ TestMethod ]
56- public void Parse_SingleQuoted_WithEscapedApostrophe_Works ( )
57- {
58- var jsonSingleQuoted = "{ 'OwnerDN':'CN=O\\ 'Connor,DC=contoso,DC=com', 'IsComputerKey': false }" ;
59- var obj = KeyCredential . ParseJson ( jsonSingleQuoted ) ;
60- Assert . IsNotNull ( obj ) ;
61- }
62-
63- [ TestMethod ]
64- public void Parse_BadJson_StillThrows ( )
65- {
66- var bad = "{ \" OwnerDN\" : \" CN=User,DC=contoso,DC=com\" " ;
67- Assert . ThrowsExactly < JsonException > ( ( ) => _ = KeyCredential . ParseJson ( bad ) ) ;
68- }
69-
7021 [ TestMethod ]
7122 public void KeyCredential_Parse_NonMFAKey ( )
7223 {
@@ -500,7 +451,7 @@ public void KeyCredential_Parse_DeviceKey_TPM()
500451 Assert . AreEqual ( KeyFlags . None , key . CustomKeyInfo . Flags ) ;
501452 Assert . AreEqual ( "OoYGWyO8xBkLx3x2d0QltMav9+41lY0sGxKIMPF9if0=" , key . Identifier ) ;
502453 Assert . AreEqual ( key . LastLogonTime , key . CreationTime ) ;
503- Assert . AreEqual ( "2019-08-02T18:11:37.5665512Z" , key . CreationTime . ToUniversalTime ( ) . ToString ( "o" ) ) ;
454+ Assert . AreEqual ( "2019-08-02T18:11:37.5665512Z" , key . CreationTime . Value . ToUniversalTime ( ) . ToString ( "o" ) ) ;
504455 Assert . AreEqual ( 0x304 , key . RawKeyMaterial . Length ) ;
505456
506457 // Serialize
@@ -542,7 +493,7 @@ public void KeyCredential_Parse_Impacket()
542493 Assert . AreEqual ( KeySource . AD , key . Source ) ;
543494
544495 // Bug in Impacket causes a time skew of 1600 years:
545- Assert . AreEqual ( 3625 , key . CreationTime . Year ) ;
496+ Assert . AreEqual ( 3625 , key . CreationTime . Value . Year ) ;
546497
547498 // Serialize
548499 byte [ ] serialized = key . ToByteArray ( ) ;
0 commit comments