From c435f41c5dd9019657a415b7874e5edc313e2be1 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Thu, 2 Mar 2017 16:37:48 -0800 Subject: [PATCH 01/26] fix tests trying to create SHA1CryptoServiceProvider --- .../tests/SignedXmlTest.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs index 27e4c978285d..90be976c355f 100644 --- a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs @@ -357,13 +357,13 @@ public void SymmetricHMACSHA1Signature() Assert.True(vrfy.CheckSignature(hmac), "HMACSHA1-Compute/Verify"); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "recheck this test with mono original code")] public void SymmetricMACTripleDESSignature() { SignedXml signedXml = MSDNSample(); // Compute the signature. byte[] secretkey = Encoding.Default.GetBytes("password"); - using (HMAC hmac = HMACSHA256.Create()) + using (HMAC hmac = new HMACSHA256()) { hmac.Key = secretkey; Assert.Throws(() => signedXml.ComputeSignature(hmac)); @@ -646,7 +646,7 @@ public void GetIdElement_Null() Assert.Null(sign.GetIdElement(new XmlDocument(), null)); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void DigestValue_CRLF() { XmlDocument doc = CreateSomeXml("\r\n"); @@ -658,7 +658,7 @@ public void DigestValue_CRLF() s.Position = 0; - HashAlgorithm hash = HashAlgorithm.Create("System.Security.Cryptography.SHA1CryptoServiceProvider"); + HashAlgorithm hash = SHA1.Create(); byte[] digest = hash.ComputeHash(s); Assert.Equal("IKbfdK2/DMfXyezCf5QggVCXfk8=", Convert.ToBase64String(digest)); @@ -699,7 +699,7 @@ public void DigestValue_CRLF() + "", signedXml.SignedInfo.GetXml().OuterXml); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void DigestValue_LF() { XmlDocument doc = CreateSomeXml("\n"); @@ -711,7 +711,7 @@ public void DigestValue_LF() s.Position = 0; - HashAlgorithm hash = HashAlgorithm.Create("System.Security.Cryptography.SHA1CryptoServiceProvider"); + HashAlgorithm hash = SHA1.Create(); byte[] digest = hash.ComputeHash(s); Assert.Equal("e3dsi1xK8FAx1vsug7J203JbEAU=", Convert.ToBase64String(digest)); From 32ab581a450dbe5f423c82798ce20a1a163d266c Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 11:22:46 -0800 Subject: [PATCH 02/26] disable MAC3DES test, add DSASignatureDescription --- .../System.Security.Cryptography.Xml.csproj | 1 + .../Cryptography/Xml/CryptoHelpers.cs | 3 +- .../Xml/DSASignatureDescription.cs | 47 +++++++++++++++++++ .../tests/SignedXmlTest.cs | 15 +----- 4 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DSASignatureDescription.cs diff --git a/src/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj b/src/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj index b44485bbe7a1..d17abed40b77 100644 --- a/src/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj +++ b/src/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj @@ -34,6 +34,7 @@ + diff --git a/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs index c53df46b88e1..9e54fe59ac26 100644 --- a/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs +++ b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs @@ -53,8 +53,7 @@ public static object CreateFromName(string name) throw new NotImplementedException(name); //return new System.Security.Cryptography.HMACRIPEMD160(); case "http://www.w3.org/2000/09/xmldsig#dsa-sha1": - throw new NotImplementedException(name); - //return new DSASignatureDescription(); + return new DSASignatureDescription(); case "System.Security.Cryptography.DSASignatureDescription": throw new NotImplementedException(name); //return new DSASignatureDescription(); diff --git a/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DSASignatureDescription.cs b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DSASignatureDescription.cs new file mode 100644 index 000000000000..8e90939cec71 --- /dev/null +++ b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DSASignatureDescription.cs @@ -0,0 +1,47 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace System.Security.Cryptography.Xml +{ + internal class DSASignatureDescription : SignatureDescription + { + const string HashAlgorithm = "SHA1"; + + public DSASignatureDescription() + { + KeyAlgorithm = typeof(System.Security.Cryptography.DSA).AssemblyQualifiedName; + FormatterAlgorithm = typeof(System.Security.Cryptography.DSASignatureFormatter).AssemblyQualifiedName; + DeformatterAlgorithm = typeof(System.Security.Cryptography.DSASignatureDeformatter).AssemblyQualifiedName; + DigestAlgorithm = "SHA1"; + } + + public sealed override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) + { + var item = (AsymmetricSignatureDeformatter)CryptoHelpers.CreateFromName(DeformatterAlgorithm); + item.SetKey(key); + item.SetHashAlgorithm(HashAlgorithm); + return item; + } + + public sealed override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) + { + var item = (AsymmetricSignatureFormatter)CryptoHelpers.CreateFromName(FormatterAlgorithm); + item.SetKey(key); + item.SetHashAlgorithm(HashAlgorithm); + return item; + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5350", Justification = "SHA1 needed for compat.")] + public sealed override HashAlgorithm CreateDigest() + { + return SHA1.Create(); + } + } +} diff --git a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs index 90be976c355f..eeff4947ffc9 100644 --- a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs @@ -357,19 +357,6 @@ public void SymmetricHMACSHA1Signature() Assert.True(vrfy.CheckSignature(hmac), "HMACSHA1-Compute/Verify"); } - [Fact(Skip = "recheck this test with mono original code")] - public void SymmetricMACTripleDESSignature() - { - SignedXml signedXml = MSDNSample(); - // Compute the signature. - byte[] secretkey = Encoding.Default.GetBytes("password"); - using (HMAC hmac = new HMACSHA256()) - { - hmac.Key = secretkey; - Assert.Throws(() => signedXml.ComputeSignature(hmac)); - } - } - // Using empty constructor // LAMESPEC: The two other constructors don't seems to apply in verifying signatures [Fact] @@ -396,7 +383,7 @@ public void AsymmetricRSAVerify() // Using empty constructor // LAMESPEC: The two other constructors don't seems to apply in verifying signatures - [Fact(Skip = "TODO: fix me")] + [Fact] public void AsymmetricDSAVerify() { string value = "/Vvq6sXEVbtZC8GwNtLQnGOy/VI=BYz/qRGjGsN1yMFPxWa3awUZm1y4I/IxOQroMxkOteRGgk1HIwhRYw==

iglVaZ+LsSL8Y0aDXmFMBwva3xHqIypr3l/LtqBH9ziV2Sh1M4JVasAiKqytWIWt/s/Uk8Ckf2tO2Ww1vsNi1NL+Kg9T7FE52sn380/rF0miwGkZeidzm74OWhykb3J+wCTXaIwOzAWI1yN7FoeoN7wzF12jjlSXAXeqPMlViqk=

u4sowiJMHilNRojtdmIuQY2YnB8=SdnN7d+wn1n+HH4Hr8MIryIRYgcXdbZ5TH7jAnuWc1koqRc1AZfcYAZ6RDf+orx6Lzn055FTFiN+1NHQfGUtXJCWW0zz0FVV1NJux7WRj8vGTldjJ5ef0oCenkpwDjcIxWsZgVobve4GPoyN1sAc1scnkJB59oupibklmF4y72A=XejzS8Z51yfl0zbYnxSYYbHqreSLjNCoGPB/KjM1TOyV5sMjz0StKtGrFWryTWc7EgvFY7kUth4e04VKf9HbK8z/FifHTXj8+Tszbjzw8GfInnBwLN+vJgbpnjtypmiI5Bm2nLiRbfkdAHP+OrKtr/EauM9GQfYuaxm3/Vj8B84=vGwGg9wqwwWP9xsoPoXu6kHArJtadiNKe9azBiUx5Ob883gd5wlKfEcGuKkBmBySGbgwxyOsIBovd9Kk48hF01ymfQzAAuHR0EdJECSsTsTTKVTLQNBU32O+PRbLYpv4E8kt6rNL83JLJCBYsqzn8J6fd2gtEyq6YOqiUSHgPE8=sQ==
This is some text
"; From fd114f9469b15ad5aee116d561b19f036cad6150 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 15:10:45 -0800 Subject: [PATCH 03/26] fix or better reason for test failure --- .../tests/SignedXmlTest.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs index eeff4947ffc9..6976434f041b 100644 --- a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs @@ -164,7 +164,7 @@ public void SignatureMethodMismatch() Assert.Throws(() => signedXml.ComputeSignature()); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void AsymmetricRSASignature() { SignedXml signedXml = MSDNSample(); @@ -188,7 +188,7 @@ public void AsymmetricRSASignature() Assert.Null(signedXml.SigningKeyName); Assert.Equal(SignedXml.XmlDsigRSASHA1Url, signedXml.SignatureMethod); - Assert.Equal(128, signedXml.SignatureValue.Length); + Assert.Equal(key.KeySize / 8, signedXml.SignatureValue.Length); Assert.Null(signedXml.SigningKeyName); // Get the XML representation of the signature. @@ -284,7 +284,7 @@ public void AsymmetricRSAMixedCaseAttributesVerifyWindows() Assert.True(v1.CheckSignature()); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void AsymmetricDSASignature() { SignedXml signedXml = MSDNSample(); @@ -552,7 +552,7 @@ public void ComputeSignatureMissingReferencedObject() Assert.Throws(() => signedXml.ComputeSignature()); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void DataReferenceToNonDataObject() { XmlDocument doc = new XmlDocument(); @@ -625,7 +625,7 @@ string SignWithHMACSHA1(string input, byte[] key, Transform transform) return sw.ToString(); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void GetIdElement_Null() { SignedXml sign = new SignedXml(); @@ -1347,7 +1347,7 @@ private void HmacMustBeMultipleOfEightBits(int bits) sign.CheckSignature(new HMACSHA1(Encoding.ASCII.GetBytes("secret"))); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void HmacMustBeMultipleOfEightBits() { for (int i = 1; i < 160; i++) @@ -1360,7 +1360,7 @@ public void HmacMustBeMultipleOfEightBits() } } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void VerifyHMAC_ZeroLength() { string xml = @" @@ -1388,7 +1388,7 @@ public void VerifyHMAC_ZeroLength() CheckErratum(sign, new HMACSHA1(Encoding.ASCII.GetBytes("secret")), "4"); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void VerifyHMAC_SmallerThanMinimumLength() { // 72 is a multiple of 8 but smaller than the minimum of 80 bits @@ -1397,7 +1397,7 @@ public void VerifyHMAC_SmallerThanMinimumLength() CheckErratum(sign, new HMACSHA1(Encoding.ASCII.GetBytes("secret")), "72"); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void VerifyHMAC_MinimumLength() { // 80 bits is the minimum (and the half-size of HMACSHA1) @@ -1406,7 +1406,7 @@ public void VerifyHMAC_MinimumLength() Assert.True(sign.CheckSignature(new HMACSHA1(Encoding.ASCII.GetBytes("secret")))); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void VerifyHMAC_SmallerHalfLength() { // 80bits is smaller than the half-size of HMACSHA256 @@ -1415,7 +1415,7 @@ public void VerifyHMAC_SmallerHalfLength() CheckErratum(sign, new HMACSHA256(Encoding.ASCII.GetBytes("secret")), "80"); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void VerifyHMAC_HalfLength() { // 128 is the half-size of HMACSHA256 @@ -1432,7 +1432,7 @@ public void VerifyHMAC_FullLength() Assert.True(sign.CheckSignature(new HMACSHA1(Encoding.ASCII.GetBytes("secret")))); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void VerifyHMAC_HMACOutputLength_Signature_Mismatch() { string xml = @" @@ -1456,7 +1456,7 @@ public void VerifyHMAC_HMACOutputLength_Signature_Mismatch() Assert.Throws(() => sign.CheckSignature(new HMACSHA1(Encoding.ASCII.GetBytes("no clue")))); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void VerifyHMAC_HMACOutputLength_Invalid() { string xml = @" From ff688442f378527fe1f5c0f78a13cc2455a37238 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 15:32:50 -0800 Subject: [PATCH 04/26] disable AsymmetricDSASignature test with different reason --- src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs index 6976434f041b..1a36a60362a7 100644 --- a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs @@ -284,7 +284,7 @@ public void AsymmetricRSAMixedCaseAttributesVerifyWindows() Assert.True(v1.CheckSignature()); } - [Fact] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16691")] public void AsymmetricDSASignature() { SignedXml signedXml = MSDNSample(); From 8de1a2a3ea817049e0dc0a70c2c37d15850bdec9 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 15:54:44 -0800 Subject: [PATCH 05/26] fix improperly wrapped Assert.Throws (verified with Mono) --- .../tests/XmlDsigXsltTransformTest.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs index 806f21364563..8f53aec318e2 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs @@ -169,7 +169,7 @@ public void InvalidXslt() } } - [Fact(Skip = "TODO: fix me")] + [Fact] public void OnlyInner() { string test = ""; @@ -182,8 +182,11 @@ public void OnlyInner() doc.LoadXml(test); transform.LoadInnerXml(doc.ChildNodes); - Stream s = (Stream)transform.GetOutput(); - Assert.Throws(() => Stream2Array(s)); + Assert.Throws(() => + { + Stream s = (Stream)transform.GetOutput(); + Stream2Array(s); + }); } private XmlDocument GetXslDoc() From 41864db3aa0717525fc39ebf46e54ae01d6beadf Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 15:55:06 -0800 Subject: [PATCH 06/26] fix reverse condition --- .../tests/XmlDsigExcC14NWithCommentsTransformTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NWithCommentsTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NWithCommentsTransformTest.cs index 5b6b13296296..5454d6fcd920 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NWithCommentsTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NWithCommentsTransformTest.cs @@ -99,7 +99,7 @@ void CheckProperties(XmlDsigExcC14NWithCommentsTransform transform) Assert.Equal(typeof(Stream), output[0]); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void InputTypes() { Type[] input = transform.InputTypes; @@ -107,7 +107,7 @@ public void InputTypes() input[1] = null; input[2] = null; // property does not return a clone - Assert.All(transform.InputTypes, Assert.NotNull); + Assert.All(transform.InputTypes, Assert.Null); // it's not a static array transform = new UnprotectedXmlDsigExcC14NWithCommentsTransform(); From d5f73357dbf6e9b2be179d090f0f58e424932d0b Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 16:06:37 -0800 Subject: [PATCH 07/26] disable few more tests with better issue --- .../tests/XmlDsigExcC14NTransformTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs index 68a423af1e4f..48ac3c0b50b6 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs @@ -236,7 +236,7 @@ public void LoadInputAsXmlDocument() Assert.Equal(c14xml3, output); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] // see LoadInputAsXmlNodeList2 description public void LoadInputAsXmlNodeList() { @@ -248,7 +248,7 @@ public void LoadInputAsXmlNodeList() Assert.Equal("", output); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] // MS has a bug that those namespace declaration nodes in // the node-set are written to output. Related spec section is: // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel From efb71507e73c9f3f24a0f18a36bf460d7b4b68dc Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 16:07:15 -0800 Subject: [PATCH 08/26] expect exception on unsupported output --- .../tests/XmlDsigExcC14NTransformTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs index 48ac3c0b50b6..a147390bc155 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs @@ -275,11 +275,11 @@ public void LoadInputAsStream() Assert.Equal(c14xml2, output); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void LoadInputWithUnsupportedType() { byte[] bad = { 0xBA, 0xD }; - transform.LoadInput(bad); + Assert.Throws(() => transform.LoadInput(bad)); } [Fact] From 5b4dddfc080202e3684b61775a9c5cee0003e093 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 16:40:01 -0800 Subject: [PATCH 09/26] fix few more tests --- .../XmlDsigC14NWithCommentsTransformTest.cs | 13 +++++----- .../tests/XmlDsigExcC14NTransformTest.cs | 24 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs index bc3be94dae9b..f960daffeefd 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs @@ -102,10 +102,11 @@ public void C14NSpecExample(string input, string expectedOutput) public void C14NSpecExample5() { string testName = GetType().Name + "." + nameof(C14NSpecExample5); - using (TestHelpers.CreateTestTextFile(testName, "world")) + using (TempFile tempFile = TestHelpers.CreateTestTextFile(testName, "world")) { - string result = ExecuteXmlDSigC14NTransform(C14NSpecExample5Input(testName), Encoding.UTF8, new XmlUrlResolver()); - string expectedResult = C14NSpecExample5Output(testName); + string input = C14NSpecExample5Input(tempFile.Path); + string result = ExecuteXmlDSigC14NTransform(input, Encoding.UTF8, new XmlUrlResolver()); + string expectedResult = C14NSpecExample5Output(tempFile.Path); Assert.Equal(expectedResult, result); } } @@ -274,11 +275,11 @@ static string C14NSpecExample1Input(string testName) => // Example 5 from C14N spec - Entity References: // http://www.w3.org/TR/xml-c14n#Example-Entities // - static string C14NSpecExample5Input(string worldName) => + static string C14NSpecExample5Input(string path) => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -286,7 +287,7 @@ static string C14NSpecExample5Input(string worldName) => " &ent1;, &ent2;!\n" + "\n" + "\n" + - $"\n"; + $"\n"; static string C14NSpecExample5Output(string worldName) => "\n" + " Hello, world!\n" + diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs index a147390bc155..4b2f3b93a2cd 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs @@ -322,13 +322,14 @@ public void ExcC14NSpecExample4() Assert.Equal(ExcC14NSpecExample4Output, res); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void ExcC14NSpecExample5() { string testName = GetType().Name + "." + nameof(ExcC14NSpecExample5); - using (TestHelpers.CreateTestTextFile(testName, "world")) + using (TempFile tempFile = TestHelpers.CreateTestTextFile(testName, "world")) { - string res = ExecuteXmlDSigExcC14NTransform(ExcC14NSpecExample5Input(testName)); + string input = ExcC14NSpecExample5Input(tempFile.Path); + string res = ExecuteXmlDSigExcC14NTransform(input, new XmlUrlResolver()); Assert.Equal(ExcC14NSpecExample5Output, res); } } @@ -340,9 +341,10 @@ public void ExcC14NSpecExample6() Assert.Equal(ExcC14NSpecExample6Output, res); } - private string ExecuteXmlDSigExcC14NTransform(string InputXml) + private string ExecuteXmlDSigExcC14NTransform(string InputXml, XmlResolver resolver = null) { XmlDocument doc = new XmlDocument(); + doc.XmlResolver = resolver; doc.PreserveWhitespace = true; doc.LoadXml(InputXml); @@ -352,7 +354,13 @@ private string ExecuteXmlDSigExcC14NTransform(string InputXml) UTF8Encoding utf8 = new UTF8Encoding(); byte[] data = utf8.GetBytes(InputXml.ToString()); Stream stream = new MemoryStream(data); - using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings {ValidationType = ValidationType.None, DtdProcessing = DtdProcessing.Parse })) + var settings = new XmlReaderSettings + { + ValidationType = ValidationType.None, + DtdProcessing = DtdProcessing.Parse, + XmlResolver = resolver + }; + using (XmlReader reader = XmlReader.Create(stream, settings)) { doc.Load(reader); transform.LoadInput(doc); @@ -491,11 +499,11 @@ private string ExecuteXmlDSigExcC14NTransform(string InputXml) // Example 5 from ExcC14N spec - Entity References: // http://www.w3.org/TR/xml-c14n#Example-Entities // - static string ExcC14NSpecExample5Input(string worldName) => + static string ExcC14NSpecExample5Input(string path) => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -503,7 +511,7 @@ static string ExcC14NSpecExample5Input(string worldName) => " &ent1;, &ent2;!\n" + "\n" + "\n" + - $"\n"; + $"\n"; static string ExcC14NSpecExample5Output = "\n" + " Hello, world!\n" + From 4ed24288d94275c4366b71224a90134e05a2889f Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 17:09:18 -0800 Subject: [PATCH 10/26] attempt to fix escaping issue --- src/System.Security.Cryptography.Xml/tests/TestHelpers.cs | 5 +++++ .../tests/XmlDsigC14NWithCommentsTransformTest.cs | 8 ++++---- .../tests/XmlDsigExcC14NTransformTest.cs | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs index 0abffb415d63..8c052f8c10f6 100644 --- a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs +++ b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs @@ -38,5 +38,10 @@ public static TempFile CreateTestTextFile(string testName, string content) return file; } + + public static string EscapePath(string path) + { + return path.Replace("-", "©"); + } } } diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs index f960daffeefd..15247d71169b 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs @@ -279,7 +279,7 @@ static string C14NSpecExample5Input(string path) => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -287,12 +287,12 @@ static string C14NSpecExample5Input(string path) => " &ent1;, &ent2;!\n" + "\n" + "\n" + - $"\n"; - static string C14NSpecExample5Output(string worldName) => + $"\n"; + static string C14NSpecExample5Output(string path) => "\n" + " Hello, world!\n" + "\n" + - $""; + $""; // // Example 6 from C14N spec - UTF-8 Encoding: diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs index 4b2f3b93a2cd..b4a5eb230fe3 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs @@ -503,7 +503,7 @@ static string ExcC14NSpecExample5Input(string path) => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -511,7 +511,7 @@ static string ExcC14NSpecExample5Input(string path) => " &ent1;, &ent2;!\n" + "\n" + "\n" + - $"\n"; + $"\n"; static string ExcC14NSpecExample5Output = "\n" + " Hello, world!\n" + From a556ced9b07f18e328cc311b1688ccd09055e547 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 3 Mar 2017 17:12:49 -0800 Subject: [PATCH 11/26] fix replacement char --- src/System.Security.Cryptography.Xml/tests/TestHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs index 8c052f8c10f6..aedbca01861a 100644 --- a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs +++ b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs @@ -41,7 +41,7 @@ public static TempFile CreateTestTextFile(string testName, string content) public static string EscapePath(string path) { - return path.Replace("-", "©"); + return path.Replace("-", "D;"); } } } From bde5d64488b0981ec3d6448b96d9c826367270ce Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sat, 4 Mar 2017 21:45:00 +1100 Subject: [PATCH 12/26] Use XmlPreloadedResolver to remove file dependencies --- .../XmlDsigC14NWithCommentsTransformTest.cs | 16 ++++++++-------- .../tests/XmlDsigExcC14NTransformTest.cs | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs index 15247d71169b..b78072c362f5 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs @@ -14,6 +14,7 @@ using System.IO; using System.Text; using System.Xml; +using System.Xml.Resolvers; using Xunit; namespace System.Security.Cryptography.Xml.Tests @@ -101,14 +102,13 @@ public void C14NSpecExample(string input, string expectedOutput) [Fact] public void C14NSpecExample5() { - string testName = GetType().Name + "." + nameof(C14NSpecExample5); - using (TempFile tempFile = TestHelpers.CreateTestTextFile(testName, "world")) - { - string input = C14NSpecExample5Input(tempFile.Path); - string result = ExecuteXmlDSigC14NTransform(input, Encoding.UTF8, new XmlUrlResolver()); - string expectedResult = C14NSpecExample5Output(tempFile.Path); - Assert.Equal(expectedResult, result); - } + string entityPath = "file://doc.txt"; + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(new Uri(entityPath), "world"); + string input = C14NSpecExample5Input(entityPath); + string result = ExecuteXmlDSigC14NTransform(input, Encoding.UTF8, resolver); + string expectedResult = C14NSpecExample5Output(entityPath); + Assert.Equal(expectedResult, result); } [Fact] diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs index b4a5eb230fe3..5b5128f93fb3 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs @@ -19,6 +19,7 @@ using System.IO; using System.Text; using System.Xml; +using System.Xml.Resolvers; using Xunit; namespace System.Security.Cryptography.Xml.Tests @@ -325,13 +326,12 @@ public void ExcC14NSpecExample4() [Fact] public void ExcC14NSpecExample5() { - string testName = GetType().Name + "." + nameof(ExcC14NSpecExample5); - using (TempFile tempFile = TestHelpers.CreateTestTextFile(testName, "world")) - { - string input = ExcC14NSpecExample5Input(tempFile.Path); - string res = ExecuteXmlDSigExcC14NTransform(input, new XmlUrlResolver()); - Assert.Equal(ExcC14NSpecExample5Output, res); - } + string entityPath = "file://doc.txt"; + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(new Uri(entityPath), "world"); + string input = ExcC14NSpecExample5Input(entityPath); + string res = ExecuteXmlDSigExcC14NTransform(input, resolver); + Assert.Equal(ExcC14NSpecExample5Output, res); } [Fact] From c742452c45a0e6df82664cf35dccaa4453870c50 Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sat, 4 Mar 2017 22:20:43 +1100 Subject: [PATCH 13/26] Move String2Stream and ExecuteTransform into TestHelpers --- ...tem.Security.Cryptography.Xml.Tests.csproj | 5 +- .../tests/TestHelpers.cs | 109 ++++++++++++++++++ .../tests/XmlDsigC14NTransformTest.cs | 60 ++++------ .../XmlDsigC14NWithCommentsTransformTest.cs | 10 +- 4 files changed, 135 insertions(+), 49 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/System.Security.Cryptography.Xml.Tests.csproj b/src/System.Security.Cryptography.Xml/tests/System.Security.Cryptography.Xml.Tests.csproj index 3de190a9a7bb..d2a1ead69baa 100644 --- a/src/System.Security.Cryptography.Xml/tests/System.Security.Cryptography.Xml.Tests.csproj +++ b/src/System.Security.Cryptography.Xml/tests/System.Security.Cryptography.Xml.Tests.csproj @@ -43,9 +43,6 @@ - - - @@ -57,4 +54,4 @@ - + \ No newline at end of file diff --git a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs index aedbca01861a..2938eab1cfc4 100644 --- a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs +++ b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs @@ -2,10 +2,28 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.IO; +using System.Text; +using System.Xml; namespace System.Security.Cryptography.Xml.Tests { + public class TempFile : IDisposable + { + public TempFile(string fileName) + { + Path = fileName; + } + + public string Path { get; } + + public void Dispose() + { + + } + } + internal static class TestHelpers { public static TempFile CreateTestDtdFile(string testName) @@ -43,5 +61,96 @@ public static string EscapePath(string path) { return path.Replace("-", "D;"); } + + /// + /// Convert a to a using the given . + /// + /// + /// The to read from. This cannot be null. + /// + /// + /// The to use. This cannot be null. + /// + /// + /// The stream as a string. + /// + /// + /// No argument can be null. + /// + public static string StreamToString(Stream stream, Encoding encoding) + { + if (stream == null) + { + throw new ArgumentNullException(nameof(stream)); + } + if (encoding == null) + { + throw new ArgumentNullException(nameof(encoding)); + } + + using (StreamReader streamReader = new StreamReader(stream, encoding)) + { + return streamReader.ReadToEnd(); + } + } + + /// + /// Perform + /// + /// + /// The XML to transform. This cannot be null, empty or whitespace. + /// + /// + /// The to perform on + /// . This cannot be null. + /// + /// + /// An optional to use when serializing or + /// deserializing . This should match the + /// encoding specified in . If omitted or + /// null, is used. + /// + /// + /// An optional to use. If omitted or null, + /// no resolver is used. + /// + /// + /// The transformed . + /// + /// + /// cannot be null. + /// + /// + /// cannot be null, empty or whitespace. + /// + /// + /// is not valid XML. + /// + public static string ExecuteTransform(string inputXml, Transform transform, Encoding encoding = null, XmlResolver resolver = null) + { + if (string.IsNullOrEmpty(inputXml)) + { + throw new ArgumentException("Cannot be null, empty or whitespace", nameof(inputXml)); + } + if (transform == null) + { + throw new ArgumentNullException(nameof(Transform)); + } + + XmlDocument doc = new XmlDocument(); + doc.XmlResolver = resolver; + doc.PreserveWhitespace = true; + doc.LoadXml(inputXml); + + Encoding actualEncoding = encoding ?? Encoding.UTF8; + byte[] data = actualEncoding.GetBytes(inputXml); + using (Stream stream = new MemoryStream(data)) + using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings { ValidationType = ValidationType.None, DtdProcessing = DtdProcessing.Parse, XmlResolver = resolver })) + { + doc.Load(reader); + transform.LoadInput(doc); + return StreamToString((Stream)transform.GetOutput(), actualEncoding); + } + } } } diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index 52e2489c97de..a06b8b1c9d1e 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -15,6 +15,7 @@ using System.IO; using System.Text; using System.Xml; +using System.Xml.Resolvers; using Xunit; namespace System.Security.Cryptography.Xml.Tests @@ -108,18 +109,6 @@ public void GetInnerXml() Assert.Null(xnl); } - private string Stream2String(Stream s) - { - StringBuilder sb = new StringBuilder(); - int b = s.ReadByte(); - while (b != -1) - { - sb.Append(Convert.ToChar(b)); - b = s.ReadByte(); - } - return sb.ToString(); - } - static string xml = " \r\n text & "; // GOOD for Stream input static string c14xml2 = " \n text & "; @@ -142,7 +131,7 @@ public void LoadInputAsXmlDocument() XmlDocument doc = GetDoc(); transform.LoadInput(doc); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); + string output = TestHelpers.StreamToString(s, Encoding.UTF8); Assert.Equal(c14xml3, output); } @@ -154,7 +143,7 @@ public void LoadInputAsXmlNodeList() // Argument list just contains element Test. transform.LoadInput(doc.ChildNodes); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); + string output = TestHelpers.StreamToString(s, Encoding.UTF8); Assert.Equal("", output); } @@ -167,7 +156,7 @@ public void LoadInputAsXmlNodeList2() XmlDocument doc = GetDoc(); transform.LoadInput(doc.SelectNodes("//*")); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); + string output = TestHelpers.StreamToString(s, Encoding.UTF8); string expected = @""; Assert.Equal(expected, output); } @@ -181,7 +170,7 @@ public void LoadInputAsStream() ms.Position = 0; transform.LoadInput(ms); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); + string output = TestHelpers.StreamToString(s, Encoding.UTF8); Assert.Equal(c14xml2, output); } @@ -202,11 +191,10 @@ public void UnsupportedOutput() [Fact] public void C14NSpecExample1() { - using (TestHelpers.CreateTestDtdFile(GetType().Name + "." + nameof(C14NSpecExample1))) - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample1Input); - Assert.Equal(C14NSpecExample1Output, res); - } + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(new Uri("doc.xsl", UriKind.Relative), ""); + string res = ExecuteXmlDSigC14NTransform(C14NSpecExample1Input, resolver); + Assert.Equal(C14NSpecExample1Output, res); } [Fact] @@ -224,22 +212,22 @@ public void C14NSpecExample3() } [Fact] - // [Ignore ("This test should be fine, but it does not pass under MS.NET")] public void C14NSpecExample4() { string res = ExecuteXmlDSigC14NTransform(C14NSpecExample4Input); Assert.Equal(C14NSpecExample4Output, res); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void C14NSpecExample5() { - string testName = GetType().Name + "." + nameof(C14NSpecExample5); - using (TestHelpers.CreateTestTextFile(testName, "world")) - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample5Input(testName)); - Assert.Equal(C14NSpecExample5Output, res); - } + //string testName = GetType().Name + "." + nameof(C14NSpecExample5); + //using (TestHelpers.CreateTestTextFile(testName, "world")) + //{ + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(new Uri("file://doc.txt"), "world"); + string res = ExecuteXmlDSigC14NTransform(C14NSpecExample5Input, resolver); + Assert.Equal(C14NSpecExample5Output, res); } [Fact] @@ -249,10 +237,11 @@ public void C14NSpecExample6() Assert.Equal(C14NSpecExample6Output, res); } - private string ExecuteXmlDSigC14NTransform(string InputXml) + private string ExecuteXmlDSigC14NTransform(string InputXml, XmlResolver resolver = null) { XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; + doc.XmlResolver = resolver; doc.LoadXml(InputXml); // Testing default attribute support with @@ -261,12 +250,12 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) UTF8Encoding utf8 = new UTF8Encoding(); byte[] data = utf8.GetBytes(InputXml.ToString()); Stream stream = new MemoryStream(data); - using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings { ValidationType = ValidationType.None, DtdProcessing = DtdProcessing.Parse })) + using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings { ValidationType = ValidationType.None, DtdProcessing = DtdProcessing.Parse, XmlResolver = resolver})) { doc.Load(reader); transform.LoadInput(doc); - return Stream2String((Stream)transform.GetOutput()); + return TestHelpers.StreamToString((Stream)transform.GetOutput(), utf8); } } @@ -283,7 +272,6 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) "\n" + "\n" + - // "\n" + "\n" + "Hello, world!\n" + "\n" + @@ -401,11 +389,11 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) // Example 5 from C14N spec - Entity References: // http://www.w3.org/TR/xml-c14n#Example-Entities // - static string C14NSpecExample5Input(string worldName) => + static string C14NSpecExample5Input => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -453,7 +441,7 @@ public void OrdinalSortForAttributes() transform.LoadInput(doc); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); + string output = TestHelpers.StreamToString(s, Encoding.UTF8); Assert.Equal(xml, output); } diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs index b78072c362f5..ddd3c3be6dfa 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs @@ -133,15 +133,7 @@ private string ExecuteXmlDSigC14NTransform(string inputXml, Encoding encoding = doc.Load(reader); XmlDsigC14NWithCommentsTransform transform = new XmlDsigC14NWithCommentsTransform(); transform.LoadInput(doc); - return Stream2String((Stream) transform.GetOutput(), actualEncoding); - } - } - - private string Stream2String(Stream stream, Encoding encoding) - { - using (StreamReader streamReader = new StreamReader(stream, encoding)) - { - return streamReader.ReadToEnd(); + return TestHelpers.StreamToString((Stream) transform.GetOutput(), actualEncoding); } } From 8f8cb744c5a263cd4ed29ab7f0e0a28e689f5954 Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sat, 4 Mar 2017 22:35:57 +1100 Subject: [PATCH 14/26] Consolidate and fix up tests --- .../tests/XmlDsigC14NTransformTest.cs | 129 ++++++------------ 1 file changed, 40 insertions(+), 89 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index a06b8b1c9d1e..f897a202bca4 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -25,15 +25,6 @@ namespace System.Security.Cryptography.Xml.Tests // difficult to test properly. This class "open it up" :-) public class UnprotectedXmlDsigC14NTransform : XmlDsigC14NTransform { - public UnprotectedXmlDsigC14NTransform() - { - } - - public UnprotectedXmlDsigC14NTransform(bool includeComments) - : base(includeComments) - { - } - public XmlNodeList UnprotectedGetInnerXml() { return base.GetInnerXml(); @@ -42,69 +33,35 @@ public XmlNodeList UnprotectedGetInnerXml() public class XmlDsigC14NTransformTest { - - protected UnprotectedXmlDsigC14NTransform transform; - - public XmlDsigC14NTransformTest() - { - transform = new UnprotectedXmlDsigC14NTransform(); - } - - [Fact] // ctor () - public void Constructor1() + [Fact] + public void Constructor_Empty() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); Assert.Equal("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", transform.Algorithm); CheckProperties(transform); } - [Fact] // ctor (Boolean) - public void Constructor2() + [Theory] + [InlineData(true, "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments")] + [InlineData(false, "http://www.w3.org/TR/2001/REC-xml-c14n-20010315")] + public void Constructor_Bool(bool includeComments, string expectedAlgorithm) { - transform = new UnprotectedXmlDsigC14NTransform(true); - Assert.Equal("http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", transform.Algorithm); - CheckProperties(transform); - - transform = new UnprotectedXmlDsigC14NTransform(false); - Assert.Equal("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", transform.Algorithm); + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(includeComments); + Assert.Equal(expectedAlgorithm, transform.Algorithm); CheckProperties(transform); } - void CheckProperties(XmlDsigC14NTransform transform) + public void CheckProperties(XmlDsigC14NTransform transform) { - Type[] input = transform.InputTypes; - Assert.True((input.Length == 3), "Input #"); - // check presence of every supported input types - bool istream = false; - bool ixmldoc = false; - bool ixmlnl = false; - foreach (Type t in input) - { - if (t.ToString() == "System.IO.Stream") - istream = true; - if (t.ToString() == "System.Xml.XmlDocument") - ixmldoc = true; - if (t.ToString() == "System.Xml.XmlNodeList") - ixmlnl = true; - } - Assert.True(istream, "Input Stream"); - Assert.True(ixmldoc, "Input XmlDocument"); - Assert.True(ixmlnl, "Input XmlNodeList"); - - Type[] output = transform.OutputTypes; - Assert.True((output.Length == 1), "Output #"); - // check presence of every supported output types - bool ostream = false; - foreach (Type t in output) - { - if (t.ToString() == "System.IO.Stream") - ostream = true; - } - Assert.True(ostream, "Output Stream"); + Assert.Null(transform.Context); + Assert.Equal(new[] { typeof(Stream), typeof(XmlDocument), typeof(XmlNodeList) }, transform.InputTypes); + Assert.Equal(new[] { typeof(Stream) }, transform.OutputTypes); } [Fact] public void GetInnerXml() { + UnprotectedXmlDsigC14NTransform transform = new UnprotectedXmlDsigC14NTransform(); XmlNodeList xnl = transform.UnprotectedGetInnerXml(); Assert.Null(xnl); } @@ -128,6 +85,7 @@ private XmlDocument GetDoc() [Fact] public void LoadInputAsXmlDocument() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = GetDoc(); transform.LoadInput(doc); Stream s = (Stream)transform.GetOutput(); @@ -135,35 +93,38 @@ public void LoadInputAsXmlDocument() Assert.Equal(c14xml3, output); } - [Fact(Skip = "TODO: fix me")] + [Fact()] // see LoadInputAsXmlNodeList2 description public void LoadInputAsXmlNodeList() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = GetDoc(); // Argument list just contains element Test. transform.LoadInput(doc.ChildNodes); Stream s = (Stream)transform.GetOutput(); string output = TestHelpers.StreamToString(s, Encoding.UTF8); - Assert.Equal("", output); + Assert.Equal(@"", output); } - [Fact(Skip = "TODO: fix me")] + [Fact()] // MS has a bug that those namespace declaration nodes in // the node-set are written to output. Related spec section is: // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel public void LoadInputAsXmlNodeList2() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = GetDoc(); transform.LoadInput(doc.SelectNodes("//*")); Stream s = (Stream)transform.GetOutput(); string output = TestHelpers.StreamToString(s, Encoding.UTF8); - string expected = @""; + string expected = @""; Assert.Equal(expected, output); } [Fact] public void LoadInputAsStream() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); MemoryStream ms = new MemoryStream(); byte[] x = Encoding.ASCII.GetBytes(xml); ms.Write(x, 0, x.Length); @@ -177,6 +138,7 @@ public void LoadInputAsStream() [Fact] public void LoadInputWithUnsupportedType() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); byte[] bad = { 0xBA, 0xD }; Assert.Throws(() => transform.LoadInput(bad)); } @@ -184,6 +146,7 @@ public void LoadInputWithUnsupportedType() [Fact] public void UnsupportedOutput() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = new XmlDocument(); Assert.Throws(() => transform.GetOutput(doc.GetType())); } @@ -197,33 +160,19 @@ public void C14NSpecExample1() Assert.Equal(C14NSpecExample1Output, res); } - [Fact] - public void C14NSpecExample2() - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample2Input); - Assert.Equal(C14NSpecExample2Output, res); - } - - [Fact] - public void C14NSpecExample3() - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample3Input); - Assert.Equal(C14NSpecExample3Output, res); - } - - [Fact] - public void C14NSpecExample4() + [Theory] + [InlineData(C14NSpecExample2Input, C14NSpecExample2Output)] + [InlineData(C14NSpecExample3Input, C14NSpecExample3Output)] + [InlineData(C14NSpecExample4Input, C14NSpecExample4Output)] + public void C14NSpecExample(string input, string expectedOutput) { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample4Input); - Assert.Equal(C14NSpecExample4Output, res); + string result = ExecuteXmlDSigC14NTransform(input); + Assert.Equal(expectedOutput, result); } [Fact] public void C14NSpecExample5() { - //string testName = GetType().Name + "." + nameof(C14NSpecExample5); - //using (TestHelpers.CreateTestTextFile(testName, "world")) - //{ XmlPreloadedResolver resolver = new XmlPreloadedResolver(); resolver.Add(new Uri("file://doc.txt"), "world"); string res = ExecuteXmlDSigC14NTransform(C14NSpecExample5Input, resolver); @@ -233,12 +182,13 @@ public void C14NSpecExample5() [Fact] public void C14NSpecExample6() { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample6Input); + string res = TestHelpers.ExecuteTransform(C14NSpecExample6Input, new XmlDsigC14NTransform(), Encoding.GetEncoding("ISO-8859-1")); Assert.Equal(C14NSpecExample6Output, res); } private string ExecuteXmlDSigC14NTransform(string InputXml, XmlResolver resolver = null) { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.XmlResolver = resolver; @@ -288,7 +238,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml, XmlResolver resolver // Example 2 from C14N spec - Whitespace in Document Content: // http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent // - static string C14NSpecExample2Input = + const string C14NSpecExample2Input = "\n" + " \n" + " A B \n" + @@ -300,7 +250,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml, XmlResolver resolver " C\n" + " \n" + "\n"; - static string C14NSpecExample2Output = + const string C14NSpecExample2Output = "\n" + " \n" + " A B \n" + @@ -317,7 +267,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml, XmlResolver resolver // Example 3 from C14N spec - Start and End Tags: // http://www.w3.org/TR/xml-c14n#Example-SETags // - static string C14NSpecExample3Input = + const string C14NSpecExample3Input = "]>\n" + "\n" + " \n" + @@ -336,7 +286,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml, XmlResolver resolver " \n" + " \n" + "\n"; - static string C14NSpecExample3Output = + const string C14NSpecExample3Output = "\n" + " \n" + " \n" + @@ -364,7 +314,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml, XmlResolver resolver // should be normalized by XML parser. Currently Mono // does not support this (see comment after this example // in the spec). - static string C14NSpecExample4Input = + const string C14NSpecExample4Input = "]>\n" + "\n" + " First line Second line\n" + @@ -374,7 +324,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml, XmlResolver resolver " \n" + // " \n" + "\n"; - static string C14NSpecExample4Output = + const string C14NSpecExample4Output = "\n" + " First line \n" + "Second line\n" + @@ -435,6 +385,7 @@ public void SimpleNamespacePrefixes() [Fact] public void OrdinalSortForAttributes() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = new XmlDocument(); string xml = ""; doc.LoadXml(xml); From 088b6d585f0997ff5975434829a8e7923588a33c Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sat, 4 Mar 2017 22:42:32 +1100 Subject: [PATCH 15/26] Use TestHelpers version of ExecuteTransform --- .../tests/XmlDsigC14NTransformTest.cs | 37 ++++--------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index f897a202bca4..ab64214ee9fe 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -156,8 +156,8 @@ public void C14NSpecExample1() { XmlPreloadedResolver resolver = new XmlPreloadedResolver(); resolver.Add(new Uri("doc.xsl", UriKind.Relative), ""); - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample1Input, resolver); - Assert.Equal(C14NSpecExample1Output, res); + string result = TestHelpers.ExecuteTransform(C14NSpecExample1Input, new XmlDsigC14NTransform()); + Assert.Equal(C14NSpecExample1Output, result); } [Theory] @@ -166,7 +166,7 @@ public void C14NSpecExample1() [InlineData(C14NSpecExample4Input, C14NSpecExample4Output)] public void C14NSpecExample(string input, string expectedOutput) { - string result = ExecuteXmlDSigC14NTransform(input); + string result = TestHelpers.ExecuteTransform(input, new XmlDsigC14NTransform()); Assert.Equal(expectedOutput, result); } @@ -175,38 +175,15 @@ public void C14NSpecExample5() { XmlPreloadedResolver resolver = new XmlPreloadedResolver(); resolver.Add(new Uri("file://doc.txt"), "world"); - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample5Input, resolver); - Assert.Equal(C14NSpecExample5Output, res); + string result = TestHelpers.ExecuteTransform(C14NSpecExample5Input, new XmlDsigC14NTransform(), Encoding.UTF8, resolver); + Assert.Equal(C14NSpecExample5Output, result); } [Fact] public void C14NSpecExample6() { - string res = TestHelpers.ExecuteTransform(C14NSpecExample6Input, new XmlDsigC14NTransform(), Encoding.GetEncoding("ISO-8859-1")); - Assert.Equal(C14NSpecExample6Output, res); - } - - private string ExecuteXmlDSigC14NTransform(string InputXml, XmlResolver resolver = null) - { - XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); - XmlDocument doc = new XmlDocument(); - doc.PreserveWhitespace = true; - doc.XmlResolver = resolver; - doc.LoadXml(InputXml); - - // Testing default attribute support with - // vreader.ValidationType = ValidationType.None. - // - UTF8Encoding utf8 = new UTF8Encoding(); - byte[] data = utf8.GetBytes(InputXml.ToString()); - Stream stream = new MemoryStream(data); - using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings { ValidationType = ValidationType.None, DtdProcessing = DtdProcessing.Parse, XmlResolver = resolver})) - { - doc.Load(reader); - - transform.LoadInput(doc); - return TestHelpers.StreamToString((Stream)transform.GetOutput(), utf8); - } + string result = TestHelpers.ExecuteTransform(C14NSpecExample6Input, new XmlDsigC14NTransform(), Encoding.GetEncoding("ISO-8859-1")); + Assert.Equal(C14NSpecExample6Output, result); } // From 9c2e262d65ce1fcb8dcf072294c27ab88dcb22f4 Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sat, 4 Mar 2017 23:19:03 +1100 Subject: [PATCH 16/26] Correct file:// reference to ensure examples are verbatim --- .../tests/TestHelpers.cs | 16 +++++++ .../tests/XmlDsigC14NTransformTest.cs | 4 +- .../XmlDsigC14NWithCommentsTransformTest.cs | 42 +++++++------------ .../tests/XmlDsigExcC14NTransformTest.cs | 11 +++-- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs index 2938eab1cfc4..f5df018c4c91 100644 --- a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs +++ b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs @@ -6,6 +6,7 @@ using System.IO; using System.Text; using System.Xml; +using System.Xml.Resolvers; namespace System.Security.Cryptography.Xml.Tests { @@ -152,5 +153,20 @@ public static string ExecuteTransform(string inputXml, Transform transform, Enco return StreamToString((Stream)transform.GetOutput(), actualEncoding); } } + + /// + /// Convert to a full URI for referencing + /// in an . + /// + /// + /// The file name. + /// + /// + /// The created . + /// + public static Uri ToUri(string fileName) + { + return new Uri("file:///" + Path.Combine(Directory.GetCurrentDirectory(), fileName)); + } } } diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index ab64214ee9fe..31c224a8a28c 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -174,7 +174,7 @@ public void C14NSpecExample(string input, string expectedOutput) public void C14NSpecExample5() { XmlPreloadedResolver resolver = new XmlPreloadedResolver(); - resolver.Add(new Uri("file://doc.txt"), "world"); + resolver.Add(TestHelpers.ToUri("doc.txt"), "world"); string result = TestHelpers.ExecuteTransform(C14NSpecExample5Input, new XmlDsigC14NTransform(), Encoding.UTF8, resolver); Assert.Equal(C14NSpecExample5Output, result); } @@ -320,7 +320,7 @@ public void C14NSpecExample6() "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs index ddd3c3be6dfa..f0b0257ae6f2 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs @@ -71,23 +71,10 @@ public void GetOutput_UnsupportedType(Type type) [Fact] public void C14NSpecExample1() { - string testName = GetType().Name + "." + nameof(C14NSpecExample1); - using (TestHelpers.CreateTestDtdFile(testName)) - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample1Input(testName), Encoding.UTF8, new XmlUrlResolver()); - Assert.Equal(C14NSpecExample1Output, res); - } - } - - [Fact] - public void C14NSpecExample1_WithoutResolver() - { - string testName = GetType().Name + "." + nameof(C14NSpecExample1_WithoutResolver); - using (TestHelpers.CreateTestDtdFile(testName)) - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample1Input(testName)); - Assert.Equal(C14NSpecExample1Output, res); - } + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(TestHelpers.ToUri("world.dtd"), ""); + string res = TestHelpers.ExecuteTransform(C14NSpecExample1Input, new XmlDsigC14NWithCommentsTransform(), Encoding.UTF8, resolver); + Assert.Equal(C14NSpecExample1Output, res); } [Theory] @@ -102,12 +89,11 @@ public void C14NSpecExample(string input, string expectedOutput) [Fact] public void C14NSpecExample5() { - string entityPath = "file://doc.txt"; XmlPreloadedResolver resolver = new XmlPreloadedResolver(); - resolver.Add(new Uri(entityPath), "world"); - string input = C14NSpecExample5Input(entityPath); + resolver.Add(TestHelpers.ToUri("doc.txt"), "world"); + string input = C14NSpecExample5Input; string result = ExecuteXmlDSigC14NTransform(input, Encoding.UTF8, resolver); - string expectedResult = C14NSpecExample5Output(entityPath); + string expectedResult = C14NSpecExample5Output; Assert.Equal(expectedResult, result); } @@ -141,13 +127,13 @@ private string ExecuteXmlDSigC14NTransform(string inputXml, Encoding encoding = // Example 1 from C14N spec - PIs, Comments, and Outside of Document Element: // http://www.w3.org/TR/xml-c14n#Example-OutsideDoc // - static string C14NSpecExample1Input(string testName) => + static string C14NSpecExample1Input => "\n" + "\n" + "\n" + "\n" + - $"\n" + + "\n" + "\n" + "Hello, world!\n" + "\n" + @@ -267,11 +253,11 @@ static string C14NSpecExample1Input(string testName) => // Example 5 from C14N spec - Entity References: // http://www.w3.org/TR/xml-c14n#Example-Entities // - static string C14NSpecExample5Input(string path) => + static string C14NSpecExample5Input => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -279,12 +265,12 @@ static string C14NSpecExample5Input(string path) => " &ent1;, &ent2;!\n" + "\n" + "\n" + - $"\n"; - static string C14NSpecExample5Output(string path) => + $"\n"; + static string C14NSpecExample5Output => "\n" + " Hello, world!\n" + "\n" + - $""; + $""; // // Example 6 from C14N spec - UTF-8 Encoding: diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs index 5b5128f93fb3..810886077f0d 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs @@ -326,10 +326,9 @@ public void ExcC14NSpecExample4() [Fact] public void ExcC14NSpecExample5() { - string entityPath = "file://doc.txt"; XmlPreloadedResolver resolver = new XmlPreloadedResolver(); - resolver.Add(new Uri(entityPath), "world"); - string input = ExcC14NSpecExample5Input(entityPath); + resolver.Add(TestHelpers.ToUri("doc.txt"), "world"); + string input = ExcC14NSpecExample5Input; string res = ExecuteXmlDSigExcC14NTransform(input, resolver); Assert.Equal(ExcC14NSpecExample5Output, res); } @@ -499,11 +498,11 @@ private string ExecuteXmlDSigExcC14NTransform(string InputXml, XmlResolver resol // Example 5 from ExcC14N spec - Entity References: // http://www.w3.org/TR/xml-c14n#Example-Entities // - static string ExcC14NSpecExample5Input(string path) => + static string ExcC14NSpecExample5Input => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -511,7 +510,7 @@ static string ExcC14NSpecExample5Input(string path) => " &ent1;, &ent2;!\n" + "\n" + "\n" + - $"\n"; + $"\n"; static string ExcC14NSpecExample5Output = "\n" + " Hello, world!\n" + From c66b24f1b406e831d4f8b0dc88b390c42485b1f8 Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sat, 4 Mar 2017 23:22:26 +1100 Subject: [PATCH 17/26] Remove final TestHelpers.Create* reference --- .../tests/XmlDsigExcC14NTransformTest.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs index 810886077f0d..c803d6c390e4 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs @@ -293,12 +293,10 @@ public void UnsupportedOutput() [Fact] public void ExcC14NSpecExample1() { - string testName = GetType().Name + "." + nameof(ExcC14NSpecExample1); - using (TestHelpers.CreateTestDtdFile(testName)) - { - string res = ExecuteXmlDSigExcC14NTransform(ExcC14NSpecExample1Input); - Assert.Equal(ExcC14NSpecExample1Output, res); - } + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(TestHelpers.ToUri("doc.dtd"), ""); + string res = ExecuteXmlDSigExcC14NTransform(ExcC14NSpecExample1Input); + Assert.Equal(ExcC14NSpecExample1Output, res); } [Fact] @@ -380,7 +378,7 @@ private string ExecuteXmlDSigExcC14NTransform(string InputXml, XmlResolver resol "\n" + "\n" + - // "\n" + + "\n" + "\n" + "Hello, world!\n" + "\n" + From 710775a27afa8617604999b500015e130a219fd6 Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sat, 4 Mar 2017 23:23:29 +1100 Subject: [PATCH 18/26] Remove TestHelpers.Create* --- .../tests/TestHelpers.cs | 51 ------------------- 1 file changed, 51 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs index f5df018c4c91..92bcef303020 100644 --- a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs +++ b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs @@ -10,59 +10,8 @@ namespace System.Security.Cryptography.Xml.Tests { - public class TempFile : IDisposable - { - public TempFile(string fileName) - { - Path = fileName; - } - - public string Path { get; } - - public void Dispose() - { - - } - } - internal static class TestHelpers { - public static TempFile CreateTestDtdFile(string testName) - { - if (testName == null) - throw new ArgumentNullException(nameof(testName)); - - var file = new TempFile( - Path.Combine(Directory.GetCurrentDirectory(), testName + ".dtd") - ); - - File.WriteAllText(file.Path, ""); - - return file; - } - - public static TempFile CreateTestTextFile(string testName, string content) - { - if (testName == null) - throw new ArgumentNullException(nameof(testName)); - - if (content == null) - throw new ArgumentNullException(nameof(content)); - - var file = new TempFile( - Path.Combine(Directory.GetCurrentDirectory(), testName + ".txt") - ); - - File.WriteAllText(file.Path, content); - - return file; - } - - public static string EscapePath(string path) - { - return path.Replace("-", "D;"); - } - /// /// Convert a to a using the given . /// From 55f4b8735835b9bb57db03cac31443d061c81cbe Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sun, 5 Mar 2017 00:02:29 +1100 Subject: [PATCH 19/26] Fix Transform.PropagatedNamespace and test --- .../System/Security/Cryptography/Xml/Transform.cs | 2 +- .../tests/XmlDsigC14NTransformTest.cs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs index 05a604b99cea..f8bbc6c9fc58 100644 --- a/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs +++ b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs @@ -204,7 +204,7 @@ public Hashtable PropagatedNamespaces CanonicalXmlNodeList namespaces = null; if (reference != null) namespaces = reference._namespaces; - else if (signedXml._context != null) + else if (signedXml?._context != null) namespaces = Utils.GetPropagatedAttributes(signedXml._context); // if no namespaces have been propagated, return an empty hashtable. diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index 31c224a8a28c..a6154ef305f8 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -387,7 +387,7 @@ public void PrefixlessNamespaceOutput() Assert.Equal("urn:foo", doc.DocumentElement.GetAttribute("xmlns")); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void PropagatedNamespaces() { XmlDocument doc = new XmlDocument(); @@ -397,12 +397,15 @@ public void PropagatedNamespaces() XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform(); t.LoadInput(doc); t.PropagatedNamespaces.Add("f", "urn:foo"); - t.PropagatedNamespaces.Add("f", "urn:foo"); - t.PropagatedNamespaces.Add("f", "urn:foo"); t.PropagatedNamespaces.Add("b", "urn:bar"); - Stream s = t.GetOutput() as Stream; - Assert.Equal(new StreamReader(s, Encoding.UTF8).ReadToEnd(), ""); - Assert.Equal("urn:foo", doc.DocumentElement.GetAttribute("xmlns:f")); + using (Stream s = t.GetOutput() as Stream) + using (StreamReader streamReader = new StreamReader(s, Encoding.UTF8)) + { + string result = streamReader.ReadToEnd(); + Assert.Equal(result, + ""); + Assert.Equal("urn:foo", doc.DocumentElement.NamespaceURI); + } } [Fact] From 258206f32994bb30d9cdf3710afe78768f1dc52d Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sun, 5 Mar 2017 21:26:22 +1100 Subject: [PATCH 20/26] Fix PropagatedNamespaces and test --- .../System/Security/Cryptography/Xml/Transform.cs | 2 +- .../tests/XmlDsigC14NTransformTest.cs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs index 05a604b99cea..f8bbc6c9fc58 100644 --- a/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs +++ b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs @@ -204,7 +204,7 @@ public Hashtable PropagatedNamespaces CanonicalXmlNodeList namespaces = null; if (reference != null) namespaces = reference._namespaces; - else if (signedXml._context != null) + else if (signedXml?._context != null) namespaces = Utils.GetPropagatedAttributes(signedXml._context); // if no namespaces have been propagated, return an empty hashtable. diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index 31c224a8a28c..a6154ef305f8 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -387,7 +387,7 @@ public void PrefixlessNamespaceOutput() Assert.Equal("urn:foo", doc.DocumentElement.GetAttribute("xmlns")); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void PropagatedNamespaces() { XmlDocument doc = new XmlDocument(); @@ -397,12 +397,15 @@ public void PropagatedNamespaces() XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform(); t.LoadInput(doc); t.PropagatedNamespaces.Add("f", "urn:foo"); - t.PropagatedNamespaces.Add("f", "urn:foo"); - t.PropagatedNamespaces.Add("f", "urn:foo"); t.PropagatedNamespaces.Add("b", "urn:bar"); - Stream s = t.GetOutput() as Stream; - Assert.Equal(new StreamReader(s, Encoding.UTF8).ReadToEnd(), ""); - Assert.Equal("urn:foo", doc.DocumentElement.GetAttribute("xmlns:f")); + using (Stream s = t.GetOutput() as Stream) + using (StreamReader streamReader = new StreamReader(s, Encoding.UTF8)) + { + string result = streamReader.ReadToEnd(); + Assert.Equal(result, + ""); + Assert.Equal("urn:foo", doc.DocumentElement.NamespaceURI); + } } [Fact] From 42612de36f3da27f02c0630c1d6e59d15c6347c7 Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Sun, 5 Mar 2017 21:30:08 +1100 Subject: [PATCH 21/26] [Fact()] to [Fact] --- .../tests/XmlDsigC14NTransformTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index a6154ef305f8..6cce3dfd981f 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -93,7 +93,7 @@ public void LoadInputAsXmlDocument() Assert.Equal(c14xml3, output); } - [Fact()] + [Fact] // see LoadInputAsXmlNodeList2 description public void LoadInputAsXmlNodeList() { @@ -106,7 +106,7 @@ public void LoadInputAsXmlNodeList() Assert.Equal(@"", output); } - [Fact()] + [Fact] // MS has a bug that those namespace declaration nodes in // the node-set are written to output. Related spec section is: // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel From fe36785068b4bc270e70f6b9e995debe69cbc8db Mon Sep 17 00:00:00 2001 From: Anthony Langsworth Date: Mon, 6 Mar 2017 23:19:05 +1100 Subject: [PATCH 22/26] Fix slash error in Un*x --- .../tests/TestHelpers.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs index 92bcef303020..11e04e72e725 100644 --- a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs +++ b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs @@ -78,7 +78,7 @@ public static string StreamToString(Stream stream, Encoding encoding) /// public static string ExecuteTransform(string inputXml, Transform transform, Encoding encoding = null, XmlResolver resolver = null) { - if (string.IsNullOrEmpty(inputXml)) + if (string.IsNullOrWhiteSpace(inputXml)) { throw new ArgumentException("Cannot be null, empty or whitespace", nameof(inputXml)); } @@ -108,14 +108,23 @@ public static string ExecuteTransform(string inputXml, Transform transform, Enco /// in an . /// /// - /// The file name. + /// The file name. This cannot be null, empty or whitespace. /// /// /// The created . /// + /// + /// cannot be null, empty or whitespace. + /// public static Uri ToUri(string fileName) { - return new Uri("file:///" + Path.Combine(Directory.GetCurrentDirectory(), fileName)); + if (string.IsNullOrWhiteSpace(fileName)) + { + throw new ArgumentException("Cannot be null, empty or whitespace", nameof(fileName)); + } + + string path = Path.Combine(Directory.GetCurrentDirectory(), fileName); + return new Uri("file://" + (path[0] == '/' ? path : '/' + path)); } } } From b079fd0aa07711527983f7b70d1210b078a2fd4f Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 6 Mar 2017 11:39:33 -0800 Subject: [PATCH 23/26] assign more concrete issues to disabled tests --- src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs | 2 +- .../tests/EncryptedXmlTest.cs | 4 ++-- src/System.Security.Cryptography.Xml/tests/KeyInfoTest.cs | 2 +- .../tests/KeyInfoX509DataTest.cs | 2 +- src/System.Security.Cryptography.Xml/tests/SignedInfoTest.cs | 2 +- .../tests/XmlDsigC14NTransformTest.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs b/src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs index aa528c6ed0be..f62fa196629f 100644 --- a/src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs @@ -88,7 +88,7 @@ public void GetXml_SameDsa() } } - [Fact(Skip = "TODO: fix me")] + [Fact] public void LoadXml() { const string pValue = "oDZlcdJA1Kf6UeNEIZqm4KDqA6zpX7CmEtAGWi9pgnBhWOUDVEfhswfsvTLR5BCbKfE6KoHvt5Hh8D1RcAko//iZkLZ+gds9y/5Oxape8tu3TUi1BnNPWu8ieXjMtdnpyudKFsCymssJked1rBeRePG23HTVwOV1DpopjRkjBEU="; diff --git a/src/System.Security.Cryptography.Xml/tests/EncryptedXmlTest.cs b/src/System.Security.Cryptography.Xml/tests/EncryptedXmlTest.cs index 3019f2068ebb..f496c0e6b55c 100644 --- a/src/System.Security.Cryptography.Xml/tests/EncryptedXmlTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/EncryptedXmlTest.cs @@ -89,7 +89,7 @@ public void Sample2() } } - [Fact(Skip = "TODO: fix me")] + [Fact] public void Sample3() { AssertDecryption1("System.Security.Cryptography.Xml.Tests.EncryptedXmlSample3.xml"); @@ -224,7 +224,7 @@ public void GetDecryptionIV_EncryptedDataNull() Assert.Throws(() => ex.GetDecryptionIV(null, EncryptedXml.XmlEncAES128Url)); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void GetDecryptionIV_StringNull() { // Added EncryptionMethod and CipherData to avoid a CryptographicException diff --git a/src/System.Security.Cryptography.Xml/tests/KeyInfoTest.cs b/src/System.Security.Cryptography.Xml/tests/KeyInfoTest.cs index c6f867d28fb1..451c25e59498 100644 --- a/src/System.Security.Cryptography.Xml/tests/KeyInfoTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/KeyInfoTest.cs @@ -195,7 +195,7 @@ public void Complex() } } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16779")] public void ImportKeyNode() { string value = "Mono::

rjxsMU368YOCTQejWkiuO9e/vUVwkLtq1jKiU3TtJ53hBJqjFRuTa228vZe+BH2su9RPn/vYFWfQDv6zgBYe3eNdu4Afw+Ny0FatX6dl3E77Ra6Tsd3MmLXBiGSQ1mMNd5G2XQGpbt9zsGlUaexXekeMLxIufgfZLwYp67M+2WM=

tf0K9rMyvUrU4cIkwbCrDRhQAJk=S8Z+1pGCed00w6DtVcqZLKjfqlCJ7JsugEFIgSy/Vxtu9YGCMclV4ijGEbPo/jU8YOSMuD7E9M7UaopMRcmKQjoKZzoJjkgVFP48Ohxl1f08lERnButsxanx3+OstFwUGQ8XNaGg3KrIoZt1FUnfxN3RHHTvVhjzNSHxMGULGaU=LnrxxRGLYeV2XLtK3SYz8RQHlHFZYrtznDZyMotuRfO5uC5YODhSFyLXvb1qB3WeGtF4h3Eo4KzHgMgfN2ZMlffxFRhJgTtH3ctbL8lfQoDkjeiPPnYGhspdJxr0tyZmiy0gkjJG3vwHYrLnvZWx9Wm/unqiOlGBPNuxJ+hOeP8=9RhE5TycDtdEIXxS3HfxFyXYgpy81zY5lVjwD6E9JP37MWEi80BlX6ab1YPm6xYSEoqReMPP9RgGiW6DuACpgI7+8vgCr4i/7VhzModJAA56PwvTu6UMt9xxKU/fT672v8ucREkMWoc7lEeyHxW3N4RHWVgqDQKuGg7iJTUTiCs=Asw=
"; diff --git a/src/System.Security.Cryptography.Xml/tests/KeyInfoX509DataTest.cs b/src/System.Security.Cryptography.Xml/tests/KeyInfoX509DataTest.cs index 1faca476974b..c90490113f9c 100644 --- a/src/System.Security.Cryptography.Xml/tests/KeyInfoX509DataTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/KeyInfoX509DataTest.cs @@ -182,7 +182,7 @@ public void AddSubjectKeyId_String_Null() Assert.Throws< NullReferenceException>(() => data1.AddSubjectKeyId((string)null)); } - [Fact(Skip = "TODO: fix me")] + [Fact] public void AddSubjectKeyId_String_BadHexData() { KeyInfoX509Data data = new KeyInfoX509Data(); diff --git a/src/System.Security.Cryptography.Xml/tests/SignedInfoTest.cs b/src/System.Security.Cryptography.Xml/tests/SignedInfoTest.cs index e9224f736906..f2d64dab4066 100644 --- a/src/System.Security.Cryptography.Xml/tests/SignedInfoTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/SignedInfoTest.cs @@ -138,7 +138,7 @@ public void GetXmlWithoutSetProperty() Assert.Equal(result, el.OuterXml); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")] public void GetXmlWithSetProperty() { XmlDocument doc = new XmlDocument(); diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index 6cce3dfd981f..aac0c5b1225e 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -373,7 +373,7 @@ public void OrdinalSortForAttributes() Assert.Equal(xml, output); } - [Fact(Skip = "TODO: fix me")] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16780")] public void PrefixlessNamespaceOutput() { XmlDocument doc = new XmlDocument(); From 2a5a8ebffabab1b7d672169b1b54ea4dc29e4723 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 6 Mar 2017 13:55:48 -0800 Subject: [PATCH 24/26] disable test failing on linux --- src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs b/src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs index f62fa196629f..dc939859b3cb 100644 --- a/src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/DSAKeyValueTest.cs @@ -88,7 +88,7 @@ public void GetXml_SameDsa() } } - [Fact] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16779")] public void LoadXml() { const string pValue = "oDZlcdJA1Kf6UeNEIZqm4KDqA6zpX7CmEtAGWi9pgnBhWOUDVEfhswfsvTLR5BCbKfE6KoHvt5Hh8D1RcAko//iZkLZ+gds9y/5Oxape8tu3TUi1BnNPWu8ieXjMtdnpyudKFsCymssJked1rBeRePG23HTVwOV1DpopjRkjBEU="; @@ -110,6 +110,7 @@ public void LoadXml() Assert.Equal(Convert.ToBase64String(parameters.Q), qValue); Assert.Equal(Convert.ToBase64String(parameters.G), gValue); Assert.Equal(Convert.ToBase64String(parameters.Y), yValue); + Assert.NotNull(parameters.Seed); Assert.Equal(Convert.ToBase64String(parameters.Seed), seedValue); Assert.Equal(BitConverter.GetBytes(parameters.Counter)[0], Convert.FromBase64String(pgenCounterValue)[0]); } From caf7de2d13ab0abf4e03f1e1d2dc7320b7241e79 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 6 Mar 2017 15:54:24 -0800 Subject: [PATCH 25/26] apply review feedback --- .../tests/SignedXmlTest.cs | 16 ++++++++++++---- .../tests/XmlDsigXsltTransformTest.cs | 6 +----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs index 1a36a60362a7..aa2b46efd7e3 100644 --- a/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs @@ -645,8 +645,12 @@ public void DigestValue_CRLF() s.Position = 0; - HashAlgorithm hash = SHA1.Create(); - byte[] digest = hash.ComputeHash(s); + byte[] digest; + using (HashAlgorithm hash = SHA1.Create()) + { + digest = hash.ComputeHash(s); + } + Assert.Equal("IKbfdK2/DMfXyezCf5QggVCXfk8=", Convert.ToBase64String(digest)); X509Certificate2 cert = new X509Certificate2(_pkcs12, "mono"); @@ -698,8 +702,12 @@ public void DigestValue_LF() s.Position = 0; - HashAlgorithm hash = SHA1.Create(); - byte[] digest = hash.ComputeHash(s); + byte[] digest; + using (HashAlgorithm hash = SHA1.Create()) + { + digest = hash.ComputeHash(s); + } + Assert.Equal("e3dsi1xK8FAx1vsug7J203JbEAU=", Convert.ToBase64String(digest)); X509Certificate2 cert = new X509Certificate2(_pkcs12, "mono"); diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs index 8f53aec318e2..702f3d6e78ae 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs @@ -182,11 +182,7 @@ public void OnlyInner() doc.LoadXml(test); transform.LoadInnerXml(doc.ChildNodes); - Assert.Throws(() => - { - Stream s = (Stream)transform.GetOutput(); - Stream2Array(s); - }); + Assert.Throws(() => transform.GetOutput()); } private XmlDocument GetXslDoc() From 4b01e4b59c08e3d791152a7fabc28985862c8b9a Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 6 Mar 2017 16:12:40 -0800 Subject: [PATCH 26/26] revert product fix and disable test --- .../src/System/Security/Cryptography/Xml/Transform.cs | 2 +- .../tests/XmlDsigC14NTransformTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs index f8bbc6c9fc58..05a604b99cea 100644 --- a/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs +++ b/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs @@ -204,7 +204,7 @@ public Hashtable PropagatedNamespaces CanonicalXmlNodeList namespaces = null; if (reference != null) namespaces = reference._namespaces; - else if (signedXml?._context != null) + else if (signedXml._context != null) namespaces = Utils.GetPropagatedAttributes(signedXml._context); // if no namespaces have been propagated, return an empty hashtable. diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index aac0c5b1225e..5277ceb49cd5 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -387,7 +387,7 @@ public void PrefixlessNamespaceOutput() Assert.Equal("urn:foo", doc.DocumentElement.GetAttribute("xmlns")); } - [Fact] + [Fact(Skip = "https://github.com/dotnet/corefx/issues/16798")] public void PropagatedNamespaces() { XmlDocument doc = new XmlDocument();