Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,17 @@
2010-03-06 Marek Habersack <mhabersack@novell.com>
* RequestValidatorTest.cs: added
2009-07-07 Raja R Harinath <harinath@hurrynot.org>
* UrlUtilsTest.cs: Use SystemWebTestShim.UriUtils.
2008-06-16 Marek Habersack <mhabersack@novell.com>
* UrlUtilsTest.cs: those tests can be ran only under the 2.0
runtime (System.Web.Util.UrlUtils is an internal class)
2005-09-11 Sebastien Pouliot <sebastien@ximian.com>
* TransactionsCas.cs: New. CAS unit for Transactions.
* WorkItemCas.cs: New. CAS unit for Transactions.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,325 @@
//
// Unit tests for MachineKeySectionUtils (internals)
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using System.Web.Configuration;
using System.Web.Util;
using NUnit.Framework;
namespace MonoTests.System.Web.Util {
[TestFixture]
public class MachineKeySectionUtilsTest {
static byte ChangeByte (byte b)
{
return (b == Byte.MaxValue) ? Byte.MinValue : (byte) (b + 1);
}
public void Encrypt_RoundTrip (MachineKeySection section)
{
byte [] data = new byte [14];
byte [] encdata = MachineKeySectionUtils.Encrypt (section, data);
byte [] decdata = MachineKeySectionUtils.Decrypt (section, encdata);
Assert.AreEqual (data, decdata, "roundtrip");
// changing length (missing first byte)
byte [] cut = new byte [encdata.Length - 1];
Array.Copy (encdata, 1, cut, 0, cut.Length);
Assert.IsNull (MachineKeySectionUtils.Decrypt (section, cut), "bad length");
// changing last byte (padding)
byte be = encdata [encdata.Length - 1];
encdata [encdata.Length - 1] = ChangeByte (be);
byte[] result = MachineKeySectionUtils.Decrypt (section, encdata);
// this will return null if a bad padding is detected - OTOH since we're using a random key and we
// encrypt a random IV it's possible the decrypted stuff will randomly have a "valid" padding (there's
// only so much possible values and the bots runs those tests pretty often and give false positive)
// To avoid this we fallback to ensure the data is invalid (if should be empty)
int total = 0;
if (result != null) {
for (int i=0; i < result.Length; i++)
total += result [i];
}
Assert.IsTrue (result == null || total != 0, "bad padding");
}
[Test]
public void Encrypt_RoundTrip_Default ()
{
Encrypt_RoundTrip (new MachineKeySection ());
}
[Test]
public void Encrypt_RoundTrip_AES ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.AES;
Encrypt_RoundTrip (section);
}
[Test]
public void Encrypt_RoundTrip_TripleDES ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.TripleDES;
Encrypt_RoundTrip (section);
}
[Test]
public void Encrypt_RoundTrip_MD5 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.MD5;
Encrypt_RoundTrip (section);
}
[Test]
public void Encrypt_RoundTrip_SHA1 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.SHA1;
Encrypt_RoundTrip (section);
}
#if NET_4_0
[Test]
public void Encrypt_RoundTrip_HMACSHA256 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.HMACSHA256;
EncryptSign_RoundTrip (section);
}
[Test]
public void Encrypt_RoundTrip_HMACSHA384 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.HMACSHA384;
EncryptSign_RoundTrip (section);
}
[Test]
public void Encrypt_RoundTrip_HMACSHA512 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.HMACSHA512;
EncryptSign_RoundTrip (section);
}
[Test]
public void Encrypt_RoundTrip_Custom_RIPEMD160 ()
{
MachineKeySection section = new MachineKeySection ();
section.ValidationAlgorithm = "alg:HMACRIPEMD160";
EncryptSign_RoundTrip (section);
}
#endif
public void EncryptSign_RoundTrip (MachineKeySection section)
{
byte [] data = new byte [14];
byte [] block = MachineKeySectionUtils.EncryptSign (section, data);
byte [] decdata = MachineKeySectionUtils.VerifyDecrypt (section, block);
Assert.AreEqual (data, decdata, "roundtrip");
// changing a byte of the data
byte b0 = block [0];
block [0] = ChangeByte (b0);
Assert.IsNull (MachineKeySectionUtils.VerifyDecrypt (section, block), "bad data");
block [0] = b0;
// changing a byte of the signature
byte be = block [block.Length - 1];
block [block.Length - 1] = ChangeByte (be);
Assert.IsNull (MachineKeySectionUtils.VerifyDecrypt (section, block), "bad signature");
}
[Test]
public void EncryptSign_RoundTrip_Default ()
{
EncryptSign_RoundTrip (new MachineKeySection ());
}
[Test]
public void EncryptSign_RoundTrip_AES ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.AES;
EncryptSign_RoundTrip (section);
}
[Test]
public void EncryptSign_RoundTrip_TripleDES ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.TripleDES;
EncryptSign_RoundTrip (section);
}
[Test]
public void EncryptSign_RoundTrip_MD5 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.MD5;
EncryptSign_RoundTrip (section);
}
[Test]
public void EncryptSign_RoundTrip_SHA1 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.SHA1;
EncryptSign_RoundTrip (section);
}
#if NET_4_0
[Test]
public void EncryptSign_RoundTrip_HMACSHA256 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.HMACSHA256;
EncryptSign_RoundTrip (section);
}
[Test]
public void EncryptSign_RoundTrip_HMACSHA384 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.HMACSHA384;
EncryptSign_RoundTrip (section);
}
[Test]
public void EncryptSign_RoundTrip_HMACSHA512 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.HMACSHA512;
EncryptSign_RoundTrip (section);
}
[Test]
public void EncryptSign_RoundTrip_Custom_RIPEMD160 ()
{
MachineKeySection section = new MachineKeySection ();
section.ValidationAlgorithm = "alg:HMACRIPEMD160";
EncryptSign_RoundTrip (section);
}
#endif
public void Validation_RoundTrip (MachineKeySection section)
{
byte [] data = new byte [] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
byte [] block = MachineKeySectionUtils.Sign (section, data);
Assert.AreEqual (data, MachineKeySectionUtils.Verify (section, block), "OK");
// changing last byte
for (int i = 0; i < data.Length; i++) {
byte b = block [i];
block [i] = ChangeByte (b);
Assert.IsNull (MachineKeySectionUtils.Verify (section, block), "bad-" + i.ToString ());
block [i] = b;
}
}
[Test]
public void Validation_RoundTrip_Default ()
{
Validation_RoundTrip (new MachineKeySection ());
}
[Test]
public void Validation_RoundTrip_AES ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.AES;
Validation_RoundTrip (section);
}
[Test]
public void Validation_RoundTrip_TripleDES ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.TripleDES;
Validation_RoundTrip (section);
}
[Test]
public void Validation_RoundTrip_MD5 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.MD5;
Validation_RoundTrip (section);
}
[Test]
public void Validation_RoundTrip_SHA1 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.SHA1;
Validation_RoundTrip (section);
}
#if NET_4_0
[Test]
public void Validation_RoundTrip_HMACSHA256 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.HMACSHA256;
Validation_RoundTrip (section);
}
[Test]
public void Validation_RoundTrip_HMACSHA384 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.HMACSHA384;
Validation_RoundTrip (section);
}
[Test]
public void Validation_RoundTrip_HMACSHA512 ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.HMACSHA512;
Validation_RoundTrip (section);
}
[Test]
public void Validation_RoundTrip_Custom_RIPEMD160 ()
{
MachineKeySection section = new MachineKeySection ();
section.ValidationAlgorithm = "alg:HMACRIPEMD160";
Validation_RoundTrip (section);
}
#endif
[Test]
public void GetHexString ()
{
Assert.AreEqual ("DEADC0DE", MachineKeySectionUtils.GetHexString (new byte [] { 0xde, 0xad, 0xc0, 0xde }), "deadcode");
}
}
}

View File

@ -0,0 +1,100 @@
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_4_0
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.Util;
using NUnit.Framework;
using MonoTests.Common;
namespace MonoTests.System.Web.Util
{
class TestRequestValidator : RequestValidator
{
public bool DoIsValidRequestString (HttpContext context, string value, RequestValidationSource requestValidationSource,
string collectionKey, out int validationFailureIndex)
{
return IsValidRequestString (context, value, requestValidationSource, collectionKey, out validationFailureIndex);
}
}
[TestFixture]
public class RequestValidatorTest
{
class FakeHttpWorkerRequest : BaseFakeHttpWorkerRequest
{
Uri uri;
public FakeHttpWorkerRequest (string url)
{
uri = new Uri (url, UriKind.Absolute);
}
public override string GetQueryString ()
{
return uri.Query;
}
public override string GetUriPath ()
{
return uri.AbsolutePath;
}
}
[Test]
public void Current ()
{
Assert.IsNotNull (RequestValidator.Current, "#A1");
Assert.AreEqual (typeof (RequestValidator).AssemblyQualifiedName, RequestValidator.Current.GetType ().AssemblyQualifiedName, "#A2");
AssertExtensions.Throws<ArgumentNullException> (() => {
RequestValidator.Current = null;
}, "#A3");
RequestValidator.Current = new TestRequestValidator ();
Assert.IsNotNull (RequestValidator.Current, "#B1");
Assert.AreEqual (typeof (TestRequestValidator).AssemblyQualifiedName, RequestValidator.Current.GetType ().AssemblyQualifiedName, "#B2");
}
[Test]
public void IsValidRequestString ()
{
var rv = new TestRequestValidator ();
int validationFailureIndex;
var fr = new FakeHttpWorkerRequest ("http://localhost/default.aspx?key=invalid%value");
var ctx = new HttpContext (fr);
Assert.IsFalse (rv.DoIsValidRequestString (null, "<script>invalid%value", RequestValidationSource.QueryString, "key", out validationFailureIndex), "#A1");
Assert.IsFalse (rv.DoIsValidRequestString (ctx, "<script>invalid%value", RequestValidationSource.QueryString, "key", out validationFailureIndex), "#A2");
}
}
}
#endif

View File

@ -0,0 +1,98 @@
//
// TransactionsCas.cs - CAS unit tests for System.Web.Util.Transactions
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.EnterpriseServices;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.Util;
namespace MonoCasTests.System.Web.Util {
[TestFixture]
[Category ("CAS")]
public class TransactionsCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor_Deny_Unrestricted ()
{
new Transactions ();
}
private void Callback ()
{
}
[Test]
// LAMESPEC - documented as AspNetHostingPermission, Level Medium
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void InvokeTransacted2_Deny_Unrestricted ()
{
try {
Transactions.InvokeTransacted (new TransactedCallback (Callback), TransactionOption.Required);
}
#if ONLY_1_1
catch (TypeInitializationException) {
// under 1.x, this _can_ trigger initialization of HttpRuntime
}
#endif
catch (PlatformNotSupportedException) {
// Mono and Windows prior to NT
}
}
[Test]
// LAMESPEC - documented as AspNetHostingPermission, Level Medium
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void InvokeTransacted3_Deny_Unrestricted ()
{
try {
bool aborted = false;
Transactions.InvokeTransacted (new TransactedCallback (Callback), TransactionOption.Required, ref aborted);
}
#if ONLY_1_1
catch (TypeInitializationException) {
// under 1.x, this _can_ trigger initialization of HttpRuntime
}
#endif
catch (PlatformNotSupportedException) {
// Mono and Windows prior to NT
}
}
// LinkDemand
public override Type Type {
get { return typeof (Transactions); }
}
}
}

View File

@ -0,0 +1,70 @@
//
// System.Web.Util.UrlUtilsTest.cs - Unit tests for System.Web.Util.UrlUtils
//
// Author:
// Noam Lampert <noaml@mainsoft.com>
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Text;
using System.Web;
using System.Web.Util;
using System.Collections.Specialized;
using NUnit.Framework;
using System.Diagnostics;
namespace MonoTests.System.Web.Util
{
[TestFixture]
public class UrlUtilsTest
{
[Test]
public void CanonicTest()
{
Assert.AreEqual("/Sample.aspx",SystemWebTestShim.UrlUtils.Canonic("/WebApplication1//../Sample.aspx"));
}
[Test]
public void CanonicTest2()
{
Assert.AreEqual("Sample.aspx",SystemWebTestShim.UrlUtils.Canonic("Path1/../Sample.aspx"));
}
[Test]
public void CanonicTest3()
{
Assert.AreEqual("/Path1/Sample.aspx",SystemWebTestShim.UrlUtils.Canonic("/../Path1/Sample.aspx"));
}
[Test]
public void CanonicTest4()
{
Assert.AreEqual("/Sample.aspx",SystemWebTestShim.UrlUtils.Canonic("/../Path1/../../Sample.aspx"));
}
[Test]
[ExpectedException(typeof(HttpException))]
public void CanonicTest5()
{
SystemWebTestShim.UrlUtils.Canonic("../Path1/../../Sample.aspx");
}
}
}
#endif

View File

@ -0,0 +1,79 @@
//
// WorkItemCas.cs - CAS unit tests for System.Web.Util.WorkItem
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
using System.Web.Util;
namespace MonoCasTests.System.Web.Util {
[TestFixture]
[Category ("CAS")]
public class WorkItemCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor_Deny_Unrestricted ()
{
new WorkItem ();
}
private void Callback ()
{
}
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void Post_Deny_UnmanagedCode ()
{
WorkItem.Post (new WorkItemCallback (Callback));
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
public void Post_PermitOnly_UnmanagedCode ()
{
try {
WorkItem.Post (new WorkItemCallback (Callback));
}
catch (PlatformNotSupportedException) {
// Mono and Windows prior to NT
}
}
// LinkDemand
public override Type Type {
get { return typeof (WorkItem); }
}
}
}