|
9 | 9 | using System.Xml; |
10 | 10 | using Microsoft.IdentityModel.TestUtils; |
11 | 11 | using Microsoft.IdentityModel.Tokens; |
12 | | -using Microsoft.IdentityModel.Xml; |
13 | 12 | using Xunit; |
14 | 13 |
|
15 | 14 | #pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant |
@@ -166,6 +165,27 @@ public void ReadSignature(DSigSerializerTheoryData theoryData) |
166 | 165 | TestUtilities.AssertFailIfErrors(context); |
167 | 166 | } |
168 | 167 |
|
| 168 | + [Theory, MemberData(nameof(ReadSignatureTheoryDataTypeCapitalized), DisableDiscoveryEnumeration = true)] |
| 169 | + public void ReadSignatureTypeCapitalized(DSigSerializerTheoryData theoryData) |
| 170 | + { |
| 171 | + var context = TestUtilities.WriteHeader($"{this}.ReadSignature", theoryData); |
| 172 | + bool switchValue; |
| 173 | + AppContext.TryGetSwitch("Switch.Microsoft.IdentityModel.UseCapitalizedXMLTypeAttr", out switchValue); |
| 174 | + AppContext.SetSwitch("Switch.Microsoft.IdentityModel.UseCapitalizedXMLTypeAttr", true); |
| 175 | + try |
| 176 | + { |
| 177 | + var signature = theoryData.Serializer.ReadSignature(XmlUtilities.CreateDictionaryReader(theoryData.Xml)); |
| 178 | + theoryData.ExpectedException.ProcessNoException(context); |
| 179 | + IdentityComparer.AreEqual(signature, theoryData.Signature, context); |
| 180 | + } |
| 181 | + catch (Exception ex) |
| 182 | + { |
| 183 | + theoryData.ExpectedException.ProcessException(ex, context); |
| 184 | + } |
| 185 | + AppContext.SetSwitch("Switch.Microsoft.IdentityModel.UseCapitalizedXMLTypeAttr", switchValue); |
| 186 | + TestUtilities.AssertFailIfErrors(context); |
| 187 | + } |
| 188 | + |
169 | 189 | public static TheoryData<DSigSerializerTheoryData> ReadSignatureTheoryData |
170 | 190 | { |
171 | 191 | get |
@@ -236,6 +256,79 @@ public static TheoryData<DSigSerializerTheoryData> ReadSignatureTheoryData |
236 | 256 | } |
237 | 257 | } |
238 | 258 |
|
| 259 | + public static TheoryData<DSigSerializerTheoryData> ReadSignatureTheoryDataTypeCapitalized |
| 260 | + { |
| 261 | + get |
| 262 | + { |
| 263 | + bool switchValue; |
| 264 | + AppContext.TryGetSwitch("Switch.Microsoft.IdentityModel.UseCapitalizedXMLTypeAttr", out switchValue); |
| 265 | + AppContext.SetSwitch("Switch.Microsoft.IdentityModel.UseCapitalizedXMLTypeAttr", true); |
| 266 | + var signature = Default.Signature; |
| 267 | + signature.SignedInfo.References[0] = Default.ReferenceWithNullTokenStream; |
| 268 | + |
| 269 | + // uncomment to view exception displayed to user |
| 270 | + // ExpectedException.DefaultVerbose = true; |
| 271 | + var theoryData = new TheoryData<DSigSerializerTheoryData> |
| 272 | + { |
| 273 | + new DSigSerializerTheoryData |
| 274 | + { |
| 275 | + First = true, |
| 276 | + Signature = signature, |
| 277 | + TestId = nameof(Default.Signature), |
| 278 | + Xml = XmlGenerator.Generate(Default.Signature), |
| 279 | + } |
| 280 | + }; |
| 281 | + |
| 282 | + signature = Default.SignatureReferenceWithId; |
| 283 | + signature.SignedInfo.References[0] = Default.ReferenceWithNullTokenStreamAndId; |
| 284 | + theoryData.Add(new DSigSerializerTheoryData |
| 285 | + { |
| 286 | + Signature = signature, |
| 287 | + TestId = nameof(Default.SignatureReferenceWithId), |
| 288 | + Xml = XmlGenerator.Generate(Default.SignatureReferenceWithId), |
| 289 | + }); |
| 290 | + |
| 291 | + signature = Default.Signature; |
| 292 | + signature.SignedInfo.References[0] = Default.ReferenceWithNullTokenStream; |
| 293 | + theoryData.Add(new DSigSerializerTheoryData |
| 294 | + { |
| 295 | + Signature = signature, |
| 296 | + TestId = nameof(Default.Signature) + "ReferenceWithoutPrefix", |
| 297 | + Xml = XmlGenerator.Generate(Default.SignatureReferenceWithoutPrefix), |
| 298 | + }); |
| 299 | + |
| 300 | + signature = Default.Signature; |
| 301 | + signature.SignedInfo.References[0] = Default.ReferenceWithNullTokenStream; |
| 302 | + signature.SignedInfo.References[0].DigestMethod = $"_{SecurityAlgorithms.Sha256Digest}"; |
| 303 | + theoryData.Add(new DSigSerializerTheoryData |
| 304 | + { |
| 305 | + Signature = signature, |
| 306 | + TestId = "UnknownDigestAlgorithm", |
| 307 | + Xml = XmlGenerator.Generate(Default.Signature).Replace(SecurityAlgorithms.Sha256Digest, $"_{SecurityAlgorithms.Sha256Digest}") |
| 308 | + }); |
| 309 | + |
| 310 | + signature = Default.Signature; |
| 311 | + signature.SignedInfo.References[0] = Default.ReferenceWithNullTokenStream; |
| 312 | + signature.SignedInfo.SignatureMethod = $"_{SecurityAlgorithms.RsaSha256Signature}"; |
| 313 | + theoryData.Add(new DSigSerializerTheoryData |
| 314 | + { |
| 315 | + Signature = signature, |
| 316 | + TestId = "UnknownSignatureAlgorithm", |
| 317 | + Xml = XmlGenerator.Generate(Default.Signature).Replace(SecurityAlgorithms.RsaSha256Signature, $"_{SecurityAlgorithms.RsaSha256Signature}") |
| 318 | + }); |
| 319 | + |
| 320 | + theoryData.Add(new DSigSerializerTheoryData |
| 321 | + { |
| 322 | + ExpectedException = new ExpectedException(typeof(XmlReadException), "IDX30022:"), |
| 323 | + Signature = new Signature(), |
| 324 | + TestId = "EmptySignature", |
| 325 | + Xml = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"></Signature>" |
| 326 | + }); |
| 327 | + AppContext.SetSwitch("Switch.Microsoft.IdentityModel.UseCapitalizedXMLTypeAttr", switchValue); |
| 328 | + return theoryData; |
| 329 | + } |
| 330 | + } |
| 331 | + |
239 | 332 | [Theory, MemberData(nameof(WriteSignatureTheoryData), DisableDiscoveryEnumeration = true)] |
240 | 333 | public void WriteSignature(DSigSerializerTheoryData theoryData) |
241 | 334 | { |
|
0 commit comments