1- // -----------------------------------------------------------------------
1+ // -----------------------------------------------------------------------
22// Licensed to The .NET Foundation under one or more agreements.
33// The .NET Foundation licenses this file to you under the MIT license.
44// -----------------------------------------------------------------------
@@ -33,6 +33,69 @@ public class NdrTests : BaseTest
3333 "QpXsMxbf8OTdTpPUjM+YO15nLKpyU1OkLkPG2OotRgIp0NoeKcyaSBsTCBrqADAgEXooGmBIGj24IhfgqoJAvOcADQ4hEiN9rrnB1iG43jBJqvsZlPtiy60LMNDKQEiQrW5yNca11V8ZJP0iPG" +
3434 "xEmequOqPQvcSAk4I3EpzYH7wcdvBN/Cie0xUC6nrLJAoO1sScn7iiR2xKwBwOLWSvJzUa5XZ7OlelLQjYCp2r3+I6TMPf8OUEvuhzSfKm5rBiHpR9owA83+RsGtXTAQsFZ8bghEsO8Q9QRq9A==" ;
3535
36+
37+ [ TestMethod ]
38+ public void NdrClientClaimsEncoding ( )
39+ {
40+ byte [ ] encodedClientClaims =
41+ { 0x01 , 0x10 , 0x08 , 0x00 , 0xcc , 0xcc , 0xcc , 0xcc , 0x10 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
42+ 0x00 , 0x00 , 0x02 , 0x00 , 0xe8 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
43+ 0xe8 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
44+ 0xe8 , 0x00 , 0x00 , 0x00 , 0x01 , 0x10 , 0x08 , 0x00 , 0xcc , 0xcc , 0xcc , 0xcc , 0xd8 , 0x00 , 0x00 , 0x00 ,
45+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x02 , 0x00 ,
46+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 ,
47+ 0x01 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x08 , 0x00 , 0x02 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 ,
48+ 0x0c , 0x00 , 0x02 , 0x00 , 0x03 , 0x00 , 0x03 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x10 , 0x00 , 0x02 , 0x00 ,
49+ 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x31 , 0x00 , 0x32 , 0x00 ,
50+ 0x33 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x14 , 0x00 , 0x02 , 0x00 , 0x37 , 0x00 , 0x00 , 0x00 ,
51+ 0x00 , 0x00 , 0x00 , 0x00 , 0x37 , 0x00 , 0x00 , 0x00 , 0x65 , 0x00 , 0x79 , 0x00 , 0x4a , 0x00 , 0x30 , 0x00 ,
52+ 0x65 , 0x00 , 0x58 , 0x00 , 0x41 , 0x00 , 0x69 , 0x00 , 0x4f , 0x00 , 0x69 , 0x00 , 0x4a , 0x00 , 0x4b , 0x00 ,
53+ 0x56 , 0x00 , 0x31 , 0x00 , 0x51 , 0x00 , 0x69 , 0x00 , 0x4c , 0x00 , 0x43 , 0x00 , 0x4a , 0x00 , 0x68 , 0x00 ,
54+ 0x62 , 0x00 , 0x47 , 0x00 , 0x63 , 0x00 , 0x69 , 0x00 , 0x4f , 0x00 , 0x69 , 0x00 , 0x4a , 0x00 , 0x53 , 0x00 ,
55+ 0x55 , 0x00 , 0x7a , 0x00 , 0x49 , 0x00 , 0x31 , 0x00 , 0x4e , 0x00 , 0x69 , 0x00 , 0x49 , 0x00 , 0x73 , 0x00 ,
56+ 0x49 , 0x00 , 0x6e , 0x00 , 0x67 , 0x00 , 0x31 , 0x00 , 0x64 , 0x00 , 0x43 , 0x00 , 0x49 , 0x00 , 0x36 , 0x00 ,
57+ 0x49 , 0x00 , 0x6b , 0x00 , 0x31 , 0x00 , 0x48 , 0x00 , 0x54 , 0x00 , 0x48 , 0x00 , 0x46 , 0x00 , 0x71 , 0x00 ,
58+ 0x4f , 0x00 , 0x54 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 } ;
59+
60+ ClaimEntry entry = new ClaimEntry
61+ {
62+ Id = "123" ,
63+ Type = ClaimType . CLAIM_TYPE_STRING ,
64+ Values = new List < object > { "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1HTHFqOT" }
65+ } ;
66+
67+ entry . Count = entry . Values . Count ;
68+
69+ ClaimsArray array = new ClaimsArray
70+ {
71+ ClaimSource = ClaimSourceType . CLAIMS_SOURCE_TYPE_AD ,
72+ ClaimEntries = new List < ClaimEntry > { entry } ,
73+ Count = 1
74+ } ;
75+
76+ ClaimsSet claims = new ClaimsSet
77+ {
78+ ReservedType = 0 ,
79+ ClaimsArray = new List < ClaimsArray > { array } ,
80+ ReservedField = ReadOnlyMemory < byte > . Empty ,
81+ Count = 1 ,
82+ ReservedFieldSize = 0
83+ } ;
84+
85+ ClaimsSetMetadata ClientClaims = new ClaimsSetMetadata
86+ {
87+ ClaimsSet = claims ,
88+ CompressionFormat = CompressionFormat . COMPRESSION_FORMAT_NONE ,
89+ ReservedType = 0 ,
90+ ReservedField = ReadOnlyMemory < byte > . Empty ,
91+ ReservedFieldSize = 0
92+ } ;
93+
94+ var encoded = ClientClaims . Marshal ( ) ;
95+
96+ Assert . IsTrue ( encoded . Span . SequenceEqual ( encodedClientClaims ) ) ;
97+ }
98+
3699 private static async Task < PrivilegedAttributeCertificate > GeneratePac ( bool includeClaims )
37100 {
38101 DecryptedKrbApReq result = null ;
@@ -155,41 +218,41 @@ public async Task PacServerSignatureRoundtrip()
155218 Assert . IsTrue ( signature . Signature . Span . SequenceEqual ( signatureDecoded . Signature . Span ) ) ;
156219 }
157220
158- // [TestMethod]
159- // public async Task NdrClaimsRoundtrip()
160- // {
161- // var pac = await GeneratePac(true);
221+ [ TestMethod ]
222+ public async Task NdrClaimsRoundtrip ( )
223+ {
224+ var pac = await GeneratePac ( true ) ;
162225
163- // var claims = pac.ClientClaims;
226+ var claims = pac . ClientClaims ;
164227
165- // var claimsDecoded = TestPacEncoding(claims);
228+ var claimsDecoded = TestPacEncoding ( claims ) ;
166229
167- // Assert.IsNotNull(claimsDecoded);
230+ Assert . IsNotNull ( claimsDecoded ) ;
168231
169- // Assert.AreEqual(claims.ClaimsSet.ClaimsArray.Count(), claimsDecoded.ClaimsSet.ClaimsArray.Count());
232+ Assert . AreEqual ( claims . ClaimsSet . ClaimsArray . Count ( ) , claimsDecoded . ClaimsSet . ClaimsArray . Count ( ) ) ;
170233
171- // for (var i = 0; i < claims.ClaimsSet.ClaimsArray.Count(); i++)
172- // {
173- // var left = claims.ClaimsSet.ClaimsArray.ElementAt(i);
174- // var right = claimsDecoded.ClaimsSet.ClaimsArray.ElementAt(i);
234+ for ( var i = 0 ; i < claims . ClaimsSet . ClaimsArray . Count ( ) ; i ++ )
235+ {
236+ var left = claims . ClaimsSet . ClaimsArray . ElementAt ( i ) ;
237+ var right = claimsDecoded . ClaimsSet . ClaimsArray . ElementAt ( i ) ;
175238
176- // Assert.AreEqual(left.ClaimSource, right.ClaimSource);
239+ Assert . AreEqual ( left . ClaimSource , right . ClaimSource ) ;
177240
178- // Assert.AreEqual(left.ClaimEntries.Count(), right.ClaimEntries.Count());
241+ Assert . AreEqual ( left . ClaimEntries . Count ( ) , right . ClaimEntries . Count ( ) ) ;
179242
180- // for (var c = 0; c < left.ClaimEntries.Count(); c++)
181- // {
182- // var claimLeft = left.ClaimEntries.ElementAt(c);
183- // var claimRight = right.ClaimEntries.ElementAt(c);
243+ for ( var c = 0 ; c < left . ClaimEntries . Count ( ) ; c ++ )
244+ {
245+ var claimLeft = left . ClaimEntries . ElementAt ( c ) ;
246+ var claimRight = right . ClaimEntries . ElementAt ( c ) ;
184247
185- // Assert.AreEqual(claimLeft.Type, claimRight.Type);
186- // Assert.AreEqual(claimLeft.Id, claimRight.Id);
187- // Assert.AreEqual(claimLeft.Values.Count(), claimRight.Values.Count());
248+ Assert . AreEqual ( claimLeft . Type , claimRight . Type ) ;
249+ Assert . AreEqual ( claimLeft . Id , claimRight . Id ) ;
250+ Assert . AreEqual ( claimLeft . Values . Count ( ) , claimRight . Values . Count ( ) ) ;
188251
189- // Assert.IsTrue(claimLeft.Values.SequenceEqual(claimRight.Values));
190- // }
191- // }
192- // }
252+ Assert . IsTrue ( claimLeft . Values . SequenceEqual ( claimRight . Values ) ) ;
253+ }
254+ }
255+ }
193256
194257 [ TestMethod ]
195258 public async Task NdrLogonInfoRoundtrip ( )
@@ -253,4 +316,4 @@ private static void AssertSidsAreEqual(SecurityIdentifier leftSid, SecurityIdent
253316 Assert . AreEqual ( leftSid . Attributes , rightSid . Attributes ) ;
254317 }
255318 }
256- }
319+ }
0 commit comments