diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2005-05-04 20:24:37 +0400 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2005-05-04 20:24:37 +0400 |
commit | f748e671c86d5350f7562bcb55122e8e693e20e1 (patch) | |
tree | 34bdc77953cd9f0cdd4138a85158f25c36863112 /mcs/class/System.Security/Test | |
parent | 5faed2987bd5ffc8597d44d1a68fc6ad2edbf8b2 (diff) |
2005-05-04 Sebastien Pouliot <sebastien@ximian.com>
* AssertCrypto.cs: Added method to compare somewhat different but ok
XML fragments (when the xmlns for xmldsig is on a different element).
* KeyInfoTest.cs, KeyInfoRetrievalMethodTest.cs, ReferenceTest.cs,
SignedInfoTest.cs, SignatureTest.cs, SignedXmlTest.cs,
XmlDsigC14NTransformTest.cs, XmlDsigC14NWithCommentsTransformTest.cs,
XmlDsigXPathTransformTest.cs: Make all tests works under Fx 2.0 beta 2
svn path=/trunk/mcs/; revision=44035
Diffstat (limited to 'mcs/class/System.Security/Test')
11 files changed, 156 insertions, 50 deletions
diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/AssertCrypto.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/AssertCrypto.cs index 30536d5c38b..52086318e7d 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/AssertCrypto.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/AssertCrypto.cs @@ -2,9 +2,10 @@ // MonoTests.System.Security.Cryptography.Xml.AssertCrypto.cs // // Author: -// Sebastien Pouliot (spouliot@motus.com) +// Sebastien Pouliot <sebastien@ximian.com> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) // using System; @@ -39,5 +40,15 @@ namespace MonoTests.System.Security.Cryptography.Xml { msg += " is different than " + BitConverter.ToString (array2, 0); Assert (msg, a); } + + private const string xmldsig = " xmlns=\"http://www.w3.org/2000/09/xmldsig#\""; + + // not to be used to test C14N output + static public void AssertXmlEquals (string msg, string expected, string actual) + { + expected = expected.Replace (xmldsig, String.Empty); + actual = actual.Replace (xmldsig, String.Empty); + AssertEquals (msg, expected, actual); + } } } diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog index 16d4a2acc06..af6aaa0f8ed 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog @@ -1,3 +1,12 @@ +2005-05-04 Sebastien Pouliot <sebastien@ximian.com> + + * AssertCrypto.cs: Added method to compare somewhat different but ok + XML fragments (when the xmlns for xmldsig is on a different element). + * KeyInfoTest.cs, KeyInfoRetrievalMethodTest.cs, ReferenceTest.cs, + SignedInfoTest.cs, SignatureTest.cs, SignedXmlTest.cs, + XmlDsigC14NTransformTest.cs, XmlDsigC14NWithCommentsTransformTest.cs, + XmlDsigXPathTransformTest.cs: Make all tests works under Fx 2.0 beta 2 + 2005-05-02 Sebastien Pouliot <sebastien@ximian.com> * SignedXmlTest.cs: AddObject and AddReference now throws diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/KeyInfoRetrievalMethodTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/KeyInfoRetrievalMethodTest.cs index 3e970d19892..cdef016e07b 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/KeyInfoRetrievalMethodTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/KeyInfoRetrievalMethodTest.cs @@ -2,9 +2,10 @@ // KeyInfoRetrievalMethodTest.cs - NUnit Test Cases for KeyInfoRetrievalMethod // // Author: -// Sebastien Pouliot (spouliot@motus.com) +// Sebastien Pouliot <sebastien@ximian.com> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) // using System; @@ -85,11 +86,14 @@ namespace MonoTests.System.Security.Cryptography.Xml { KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod (); // no exception is thrown uri1.LoadXml (doc.DocumentElement); +#if NET_2_0 + AssertCrypto.AssertXmlEquals ("invalid", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml)); +#elif NET_1_1 // note that URI="" is present (unlike a empty Uri) -#if NET_1_0 - AssertEquals("invalid", "<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml)); -#else AssertEquals("invalid", "<RetrievalMethod URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml)); +#else + // Fx 1.0 misnamed the tag name + AssertEquals("invalid", "<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml)); #endif } } diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/KeyInfoTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/KeyInfoTest.cs index 77cf0efcdd9..96a3e31f118 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/KeyInfoTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/KeyInfoTest.cs @@ -5,7 +5,7 @@ // Sebastien Pouliot <sebastien@ximian.com> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2004 Novell (http://www.novell.com) +// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) // using System; @@ -68,7 +68,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { key.FromXmlString (xmlDSA); DSAKeyValue dsa = new DSAKeyValue (key); info.AddClause (dsa); - AssertEquals ("dsa", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + xmlDSA + "</KeyValue></KeyInfo>", (info.GetXml ().OuterXml)); + AssertCrypto.AssertXmlEquals ("dsa", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + xmlDSA + "</KeyValue></KeyInfo>", (info.GetXml ().OuterXml)); AssertEquals ("dsa count", 1, info.Count); } @@ -81,7 +81,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { key.FromXmlString (xmlRSA); RSAKeyValue rsa = new RSAKeyValue (key); info.AddClause (rsa); - AssertEquals ("rsa", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + xmlRSA + "</KeyValue></KeyInfo>", (info.GetXml ().OuterXml)); + AssertCrypto.AssertXmlEquals ("rsa", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + xmlRSA + "</KeyValue></KeyInfo>", (info.GetXml ().OuterXml)); AssertEquals ("rsa count", 1, info.Count); } @@ -112,7 +112,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { X509Certificate x509 = new X509Certificate (cert); KeyInfoX509Data x509data = new KeyInfoX509Data (x509); info.AddClause (x509data); - AssertEquals ("X509Data", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Certificate>MIICHTCCAYYCARQwDQYJKoZIhvcNAQEEBQAwWDELMAkGA1UEBhMCQ0ExHzAdBgNVBAMTFktleXdpdG5lc3MgQ2FuYWRhIEluYy4xKDAmBgorBgEEASoCCwIBExhrZXl3aXRuZXNzQGtleXdpdG5lc3MuY2EwHhcNOTYwNTA3MDAwMDAwWhcNOTkwNTA3MDAwMDAwWjBYMQswCQYDVQQGEwJDQTEfMB0GA1UEAxMWS2V5d2l0bmVzcyBDYW5hZGEgSW5jLjEoMCYGCisGAQQBKgILAgETGGtleXdpdG5lc3NAa2V5d2l0bmVzcy5jYTCBnTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEAzSP6KuHtmPTp0JM+13qAAkzMwQKvXLYff/pXQm8w0SDFtSEHQCyphsLzZISuPYUu7YW9VLAYKO9q+BvnCxYfkyVPx/iOw7nKmIQOVdAv73h3xXIoX2C/GSvRcqK32D/glzRaAb0EnMh4Rc2TjRXydhARq7hbLp5S3YE+nGTIKZMCAQMwDQYJKoZIhvcNAQEEBQADgYEAMho1ur9DJ9a01Lh25eObTWzAhsl3NbprFi0TRkqwMlOhW1rpmeIMhogXTg3+gqxOR+/7/zms7jXI+lI3CkmtWa3iiqkcxl8f+G9zfs2gMegMvvVN2bKrihK2MHhoEXwN8UlNo/2y6f8d8JH6VIX/M5Dowb+km6RiRr1hElmYQYk=</X509Certificate></X509Data></KeyInfo>", (info.GetXml ().OuterXml)); + AssertCrypto.AssertXmlEquals ("X509Data", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Certificate>MIICHTCCAYYCARQwDQYJKoZIhvcNAQEEBQAwWDELMAkGA1UEBhMCQ0ExHzAdBgNVBAMTFktleXdpdG5lc3MgQ2FuYWRhIEluYy4xKDAmBgorBgEEASoCCwIBExhrZXl3aXRuZXNzQGtleXdpdG5lc3MuY2EwHhcNOTYwNTA3MDAwMDAwWhcNOTkwNTA3MDAwMDAwWjBYMQswCQYDVQQGEwJDQTEfMB0GA1UEAxMWS2V5d2l0bmVzcyBDYW5hZGEgSW5jLjEoMCYGCisGAQQBKgILAgETGGtleXdpdG5lc3NAa2V5d2l0bmVzcy5jYTCBnTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEAzSP6KuHtmPTp0JM+13qAAkzMwQKvXLYff/pXQm8w0SDFtSEHQCyphsLzZISuPYUu7YW9VLAYKO9q+BvnCxYfkyVPx/iOw7nKmIQOVdAv73h3xXIoX2C/GSvRcqK32D/glzRaAb0EnMh4Rc2TjRXydhARq7hbLp5S3YE+nGTIKZMCAQMwDQYJKoZIhvcNAQEEBQADgYEAMho1ur9DJ9a01Lh25eObTWzAhsl3NbprFi0TRkqwMlOhW1rpmeIMhogXTg3+gqxOR+/7/zms7jXI+lI3CkmtWa3iiqkcxl8f+G9zfs2gMegMvvVN2bKrihK2MHhoEXwN8UlNo/2y6f8d8JH6VIX/M5Dowb+km6RiRr1hElmYQYk=</X509Certificate></X509Data></KeyInfo>", (info.GetXml ().OuterXml)); AssertEquals ("X509Data count", 1, info.Count); } @@ -150,7 +150,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { #endif s += "<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">"; s += "<X509Certificate>MIICHTCCAYYCARQwDQYJKoZIhvcNAQEEBQAwWDELMAkGA1UEBhMCQ0ExHzAdBgNVBAMTFktleXdpdG5lc3MgQ2FuYWRhIEluYy4xKDAmBgorBgEEASoCCwIBExhrZXl3aXRuZXNzQGtleXdpdG5lc3MuY2EwHhcNOTYwNTA3MDAwMDAwWhcNOTkwNTA3MDAwMDAwWjBYMQswCQYDVQQGEwJDQTEfMB0GA1UEAxMWS2V5d2l0bmVzcyBDYW5hZGEgSW5jLjEoMCYGCisGAQQBKgILAgETGGtleXdpdG5lc3NAa2V5d2l0bmVzcy5jYTCBnTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEAzSP6KuHtmPTp0JM+13qAAkzMwQKvXLYff/pXQm8w0SDFtSEHQCyphsLzZISuPYUu7YW9VLAYKO9q+BvnCxYfkyVPx/iOw7nKmIQOVdAv73h3xXIoX2C/GSvRcqK32D/glzRaAb0EnMh4Rc2TjRXydhARq7hbLp5S3YE+nGTIKZMCAQMwDQYJKoZIhvcNAQEEBQADgYEAMho1ur9DJ9a01Lh25eObTWzAhsl3NbprFi0TRkqwMlOhW1rpmeIMhogXTg3+gqxOR+/7/zms7jXI+lI3CkmtWa3iiqkcxl8f+G9zfs2gMegMvvVN2bKrihK2MHhoEXwN8UlNo/2y6f8d8JH6VIX/M5Dowb+km6RiRr1hElmYQYk=</X509Certificate></X509Data></KeyInfo>"; - AssertEquals ("Complex", s, (info.GetXml ().OuterXml)); + AssertCrypto.AssertXmlEquals ("Complex", s, (info.GetXml ().OuterXml)); AssertEquals ("RetrievalMethod count", 5, info.Count); } @@ -164,7 +164,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { doc.LoadXml (value); info.LoadXml (doc.DocumentElement); - AssertEquals ("Import", value, (info.GetXml ().OuterXml)); + AssertCrypto.AssertXmlEquals ("Import", value, (info.GetXml ().OuterXml)); AssertEquals ("Import count", 5, info.Count); } diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ReferenceTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ReferenceTest.cs index 937c7cd5113..495980f8478 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ReferenceTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ReferenceTest.cs @@ -158,13 +158,17 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] +#if NET_2_0 + [Ignore ("MS throws a NullReferenceException - reported as FDBK25886")]
+ // http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=3596d1e3-362b-40bd-bca9-2e8be75261ff +#endif public void AddAllTransforms () { // adding an empty hash value byte[] hash = new byte [20]; reference.DigestValue = hash; XmlElement xel = reference.GetXml (); - // this is the minimal Reference (DisestValue)! + // this is the minimal Reference (DigestValue)! AssertNotNull ("GetXml", xel); reference.AddTransform (new XmlDsigBase64Transform ()); diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignatureTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignatureTest.cs index 4d92d62c0dc..6a75e69bb87 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignatureTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignatureTest.cs @@ -5,7 +5,7 @@ // Sebastien Pouliot <sebastien@ximian.com> // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2004 Novell (http://www.novell.com) +// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
// using System; @@ -51,14 +51,12 @@ namespace MonoTests.System.Security.Cryptography.Xml { [Test] public void Load () { - string test1 = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" /><Reference URI=\"#MyObjectId\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>/Vvq6sXEVbtZC8GwNtLQnGOy/VI=</DigestValue></Reference></SignedInfo><SignatureValue>A6XuE8Cy9iOffRXaW9b0+dUcMUJQnlmwLsiqtQnADbCtZXnXAaeJ6nGnQ4Mm0IGi0AJc7/2CoJReXl7iW4hltmFguG1e3nl0VxCyCTHKGOCo1u8R3K+B1rTaenFbSxs42EM7/D9KETsPlzfYfis36yM3PqatiCUOsoMsAiMGzlc=</SignatureValue><KeyInfo><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>tI8QYIpbG/m6JLyvP+S3X8mzcaAIayxomyTimSh9UCpEucRnGvLw0P73uStNpiF7wltTZA1HEsv+Ha39dY/0j/Wiy3RAodGDRNuKQao1wu34aNybZ673brbsbHFUfw/o7nlKD2xO84fbajBZmKtBBDy63NHt+QL+grSrREPfCTM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo><Object Id=\"MyObjectId\"><MyElement xmlns=\"samples\">This is some text</MyElement></Object></Signature>"; - // Mono's result is XML equivalent but a little different from the original - string test2 = test1.Replace ("<Object Id=\"MyObjectId\">", "<Object Id=\"MyObjectId\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\">"); - XmlDocument doc = new XmlDocument (); - doc.LoadXml (test1); + string expected = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" /><Reference URI=\"#MyObjectId\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>/Vvq6sXEVbtZC8GwNtLQnGOy/VI=</DigestValue></Reference></SignedInfo><SignatureValue>A6XuE8Cy9iOffRXaW9b0+dUcMUJQnlmwLsiqtQnADbCtZXnXAaeJ6nGnQ4Mm0IGi0AJc7/2CoJReXl7iW4hltmFguG1e3nl0VxCyCTHKGOCo1u8R3K+B1rTaenFbSxs42EM7/D9KETsPlzfYfis36yM3PqatiCUOsoMsAiMGzlc=</SignatureValue><KeyInfo><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>tI8QYIpbG/m6JLyvP+S3X8mzcaAIayxomyTimSh9UCpEucRnGvLw0P73uStNpiF7wltTZA1HEsv+Ha39dY/0j/Wiy3RAodGDRNuKQao1wu34aNybZ673brbsbHFUfw/o7nlKD2xO84fbajBZmKtBBDy63NHt+QL+grSrREPfCTM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo><Object Id=\"MyObjectId\"><MyElement xmlns=\"samples\">This is some text</MyElement></Object></Signature>"; + XmlDocument doc = new XmlDocument ();
+ doc.LoadXml (expected); signature.LoadXml (doc.DocumentElement); - string result = signature.GetXml ().OuterXml; - Assert ("Load", ((test1 == result) || (test2 == result))); + string result = signature.GetXml ().OuterXml;
+ AssertCrypto.AssertXmlEquals ("Load", expected, result); } [Test] diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedInfoTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedInfoTest.cs index bc9123ac394..55bf56b82af 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedInfoTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedInfoTest.cs @@ -1,10 +1,11 @@ // // SignedInfoTest.cs - NUnit Test Cases for SignedInfo // -// Author: -// Sebastien Pouliot (spouliot@motus.com) +// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) +// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
// using System; @@ -146,6 +147,11 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] +#if NET_2_0
+ // urn:foo is'nt accepted when calling GetXml
+ [ExpectedException (typeof (CryptographicException))]
+ [Category ("NotWorking")]
+#endif public void GetXmlWithSetProperty () { XmlDocument doc = new XmlDocument (); diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedXmlTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedXmlTest.cs index b216bcf4cea..0b593631a6b 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedXmlTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedXmlTest.cs @@ -4,8 +4,8 @@ // Author: // Sebastien Pouliot <sebastien@ximian.com> // -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2004 Novell (http://www.novell.com) +// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
// using System; @@ -72,6 +72,10 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] +#if NET_2_0 + [Ignore ("2.0 throws a NullReferenceException - reported as FDBK25892")]
+ // http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=02dd9730-d1ad-4170-8c82-36858c55fbe2 +#endif [ExpectedException (typeof (ArgumentNullException))] public void Constructor_XmlDocument_Null () { @@ -93,7 +97,9 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] +#if !NET_2_0 [ExpectedException (typeof (CryptographicException))] +#endif public void Constructor_XmlElement_WithoutLoadXml () { XmlDocument doc = new XmlDocument (); @@ -102,7 +108,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { XmlElement xel = (XmlElement) xnl [0]; SignedXml sx = new SignedXml (doc.DocumentElement); - Assert ("!CheckSignature", sx.CheckSignature ()); + Assert ("!CheckSignature", !sx.CheckSignature ()); // SignedXml (XmlElement) != SignedXml () + LoadXml (XmlElement) } @@ -231,16 +237,23 @@ namespace MonoTests.System.Security.Cryptography.Xml { // Compute the signature. byte[] secretkey = Encoding.Default.GetBytes ("password"); HMACSHA1 hmac = new HMACSHA1 (secretkey); - +#if NET_2_0
+ AssertEquals ("KeyInfo", 0, signedXml.KeyInfo.Count); +#else AssertNull ("KeyInfo", signedXml.KeyInfo); +#endif AssertNull ("SignatureLength", signedXml.SignatureLength); AssertNull ("SignatureMethod", signedXml.SignatureMethod); AssertNull ("SignatureValue", signedXml.SignatureValue); AssertNull ("SigningKeyName", signedXml.SigningKeyName); - signedXml.ComputeSignature (hmac); - + signedXml.ComputeSignature (hmac);
+
+#if NET_2_0
+ AssertEquals ("KeyInfo", 0, signedXml.KeyInfo.Count);
+#else AssertNull ("KeyInfo", signedXml.KeyInfo); +#endif
AssertNull ("SignatureLength", signedXml.SignatureLength); AssertEquals ("SignatureMethod", SignedXml.XmlDsigHMACSHA1Url, signedXml.SignatureMethod); AssertEquals ("SignatureValue", 20, signedXml.SignatureValue.Length); @@ -365,10 +378,11 @@ namespace MonoTests.System.Security.Cryptography.Xml { } #if NET_2_0 [Test] - [ExpectedException (typeof (ArgumentNullException))] + // [ExpectedException (typeof (ArgumentNullException))] public void AddObject_Null () { - SignedXml sx = new SignedXml (); + SignedXml sx = new SignedXml ();
+ // still no ArgumentNullExceptions for this one
sx.AddObject (null); } @@ -435,11 +449,13 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] +#if !NET_2_0 [ExpectedException (typeof (CryptographicException))] +#endif public void CheckSignatureEmpty () { SignedXml sx = new SignedXml (); - sx.CheckSignature (); + Assert (!sx.CheckSignature ()); } } } diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs index e1cf3cb7596..5a59b45bd5f 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs @@ -138,6 +138,10 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] +#if NET_2_0 + [Category ("NotDotNet")]
+ // see LoadInputAsXmlNodeList2 description +#endif public void LoadInputAsXmlNodeList () { XmlDocument doc = GetDoc (); diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransformTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransformTest.cs index c7f5b802265..726fb7f9142 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransformTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransformTest.cs @@ -5,12 +5,13 @@ // Author: // Sebastien Pouliot <sebastien@ximian.com> // -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2004 Novell (http://www.novell.com) +// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
// using System; -using System.IO; +using System.IO;
+using System.Security;
using System.Security.Cryptography.Xml; using System.Text; using System.Xml; @@ -119,15 +120,34 @@ namespace MonoTests.System.Security.Cryptography.Xml { sw.Write ("<!-- presence, not content, required -->"); sw.Close (); } - string res = ExecuteXmlDSigC14NTransform (C14NSpecExample1Input); + string res = ExecuteXmlDSigC14NTransform (C14NSpecExample1Input, true); AssertEquals ("Example 1 from c14n spec - PIs, Comments, and Outside of Document Element (with comments)", C14NSpecExample1Output, res); - } + }
+
+ [Test]
+#if NET_2_0
+ [ExpectedException (typeof (SecurityException))]
+#endif
+ public void C14NSpecExample1_WithoutResolver ()
+ {
+ using (StreamWriter sw = new StreamWriter ("doc.dtd", false, Encoding.ASCII)) {
+ sw.Write ("<!-- presence, not content, required -->");
+ sw.Close ();
+ }
+#if NET_2_0
+ if (!SecurityManager.SecurityEnabled)
+ NUnit.Framework.Assert.Ignore ("SecurityManager isn't enabled.");
+#endif
+ string res = ExecuteXmlDSigC14NTransform (C14NSpecExample1Input, false);
+ AssertEquals ("Example 1 from c14n spec - PIs, Comments, and Outside of Document Element (with comments)",
+ C14NSpecExample1Output, res);
+ } [Test] public void C14NSpecExample2 () { - string res = ExecuteXmlDSigC14NTransform (C14NSpecExample2Input); + string res = ExecuteXmlDSigC14NTransform (C14NSpecExample2Input, false); AssertEquals ("Example 2 from c14n spec - Whitespace in Document Content (with comments)", C14NSpecExample2Output, res); } @@ -135,7 +155,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { [Test] public void C14NSpecExample3 () { - string res = ExecuteXmlDSigC14NTransform (C14NSpecExample3Input); + string res = ExecuteXmlDSigC14NTransform (C14NSpecExample3Input, false); AssertEquals ("Example 3 from c14n spec - Start and End Tags (with comments)", C14NSpecExample3Output, res); } @@ -143,7 +163,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { [Test] public void C14NSpecExample4 () { - string res = ExecuteXmlDSigC14NTransform (C14NSpecExample4Input); + string res = ExecuteXmlDSigC14NTransform (C14NSpecExample4Input, false); AssertEquals ("Example 4 from c14n spec - Character Modifications and Character References (with comments)", C14NSpecExample4Output, res); } @@ -157,7 +177,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { sw.Close (); } } - string res = ExecuteXmlDSigC14NTransform (C14NSpecExample5Input); + string res = ExecuteXmlDSigC14NTransform (C14NSpecExample5Input, false); AssertEquals ("Example 5 from c14n spec - Entity References (with comments)", C14NSpecExample5Output, res); } @@ -165,12 +185,12 @@ namespace MonoTests.System.Security.Cryptography.Xml { [Test] public void C14NSpecExample6 () { - string res = ExecuteXmlDSigC14NTransform (C14NSpecExample6Input); + string res = ExecuteXmlDSigC14NTransform (C14NSpecExample6Input, false); AssertEquals ("Example 6 from c14n spec - UTF-8 Encoding (with comments)", C14NSpecExample6Output, res); } - private string ExecuteXmlDSigC14NTransform (string InputXml) + private string ExecuteXmlDSigC14NTransform (string InputXml, bool resolver) { XmlDocument doc = new XmlDocument (); doc.PreserveWhitespace = true; @@ -186,7 +206,10 @@ namespace MonoTests.System.Security.Cryptography.Xml { vreader.ValidationType = ValidationType.None; vreader.EntityHandling = EntityHandling.ExpandCharEntities; doc.Load (vreader); - +#if NET_2_0
+ if (resolver)
+ transform.Resolver = new XmlUrlResolver (); +#endif transform.LoadInput (doc); return Stream2String ((Stream)transform.GetOutput ()); } diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigXPathTransformTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigXPathTransformTest.cs index a2a6ee4bc13..872aa161ab0 100755 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigXPathTransformTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigXPathTransformTest.cs @@ -4,8 +4,8 @@ // Author: // Sebastien Pouliot <sebastien@ximian.com> // -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2004 Novell (http://www.novell.com) +// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
// using System; @@ -14,7 +14,8 @@ using System.Security.Cryptography; using System.Security.Cryptography.Xml; using System.Text; using System.Xml; -using System.Xml.Xsl; +using System.Xml.Xsl;
+using System.Xml.XPath; using NUnit.Framework; @@ -85,6 +86,9 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] +#if NET_2_0 + [Ignore ("throws a NullReferenceException - but it's (kind of internal)")] +#endif public void GetInnerXml () { XmlNodeList xnl = transform.UnprotectedGetInnerXml (); @@ -123,6 +127,9 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] +#if NET_2_0 + [Category ("NotWorking")] +#endif public void LoadInputAsXmlDocument () { XmlDocument doc = GetDoc (); @@ -130,10 +137,17 @@ namespace MonoTests.System.Security.Cryptography.Xml { XmlNodeList inner = InnerXml ("//*/title"); transform.LoadInnerXml (inner); XmlNodeList xnl = (XmlNodeList) transform.GetOutput (); +#if NET_2_0 + AssertEquals (73, xnl.Count); +#else AssertEquals (47, xnl.Count); +#endif } - [Test] + [Test]
+#if NET_2_0
+ [ExpectedException (typeof (XPathException))]
+#endif
public void LoadInputAsXmlDocument_EmptyXPath () { XmlDocument doc = GetDoc (); @@ -155,7 +169,10 @@ namespace MonoTests.System.Security.Cryptography.Xml { AssertEquals (1, xnl.Count); } - [Test] + [Test]
+#if NET_2_0
+ [ExpectedException (typeof (XPathException))]
+#endif
public void LoadInputAsXmlNodeList_EmptyXPath () { XmlDocument doc = GetDoc (); @@ -166,6 +183,9 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] +#if NET_2_0 + [Category ("NotWorking")] +#endif public void LoadInputAsStream () { XmlDocument doc = GetDoc (); @@ -177,10 +197,17 @@ namespace MonoTests.System.Security.Cryptography.Xml { XmlNodeList inner = InnerXml ("//*/title"); transform.LoadInnerXml (inner); XmlNodeList xnl = (XmlNodeList) transform.GetOutput (); +#if NET_2_0
+ AssertEquals (73, xnl.Count);
+#else AssertEquals (47, xnl.Count); +#endif } [Test] +#if NET_2_0 + [ExpectedException (typeof (XPathException))] +#endif public void LoadInputAsStream_EmptyXPath () { XmlDocument doc = GetDoc (); @@ -247,7 +274,10 @@ namespace MonoTests.System.Security.Cryptography.Xml { [Test] [Category ("NotWorking")] - // MS.NET looks incorrect, or something incorrect in this test code; It turned out nothing to do with function here() + // MS.NET looks incorrect, or something incorrect in this test code; It turned out nothing to do with function here()
+#if NET_2_0
+ [ExpectedException (typeof (XPathException))]
+#endif
public void FunctionHereObsolete () { XmlDsigXPathTransform t = new XmlDsigXPathTransform (); @@ -261,6 +291,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { doc.LoadXml ("<element a='b'><foo><bar>test</bar></foo></element>"); t.LoadInput (doc); + // FX 2.0 throws at next line! XmlNodeList nl = (XmlNodeList) t.GetOutput (); AssertEquals (0, nl.Count); |