You've already forked linux-packaging-mono
Imported Upstream version 4.0.0~alpha1
Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
@ -37,7 +37,6 @@ namespace MonoTests.System.Web.Security
|
||||
Assert.AreEqual ("/", FormsAuthentication.FormsCookiePath, "FormsCookiePath");
|
||||
Assert.IsFalse (FormsAuthentication.RequireSSL, "RequireSSL");
|
||||
Assert.IsTrue (FormsAuthentication.SlidingExpiration, "SlidingExpiration");
|
||||
#if NET_2_0
|
||||
// MSDN: The default is an empty string ("") but null.
|
||||
Assert.AreEqual ("", FormsAuthentication.CookieDomain, "CookieDomain");
|
||||
Assert.AreEqual (HttpCookieMode.UseDeviceProfile, FormsAuthentication.CookieMode, "CookieMode");
|
||||
@ -45,7 +44,6 @@ namespace MonoTests.System.Web.Security
|
||||
Assert.AreEqual ("/NunitWeb/default.aspx", FormsAuthentication.DefaultUrl);
|
||||
Assert.IsFalse (FormsAuthentication.EnableCrossAppRedirects, "EnableCrossAppRedirects");
|
||||
Assert.AreEqual ("/NunitWeb/login.aspx", FormsAuthentication.LoginUrl, "LoginUrl");
|
||||
#endif
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -108,7 +106,6 @@ namespace MonoTests.System.Web.Security
|
||||
{
|
||||
FormsAuthentication.HashPasswordForStoringInConfigFile ("mono", "SHA256");
|
||||
}
|
||||
#if NET_2_0
|
||||
[Test]
|
||||
[ExpectedException (typeof (NullReferenceException))]
|
||||
public void RedirectToLoginPage ()
|
||||
@ -139,7 +136,6 @@ namespace MonoTests.System.Web.Security
|
||||
// not throwing
|
||||
Assert.IsFalse (FormsAuthentication.Authenticate ("user", "password"), "string,string");
|
||||
}
|
||||
#endif
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void TestFixtureTearDown()
|
||||
|
@ -52,11 +52,7 @@ namespace MonoCasTests.System.Web.Security {
|
||||
ticket = new FormsAuthenticationTicket ("mine", false, Int32.MaxValue);
|
||||
}
|
||||
catch (NullReferenceException) {
|
||||
#if NET_2_0
|
||||
Assert.Fail ("this should work on 2.0");
|
||||
#else
|
||||
Assert.Ignore ("fails with NullReferenceException on MS 1.x");
|
||||
#endif
|
||||
}
|
||||
Assert.AreEqual ("/", ticket.CookiePath, "CookiePath");
|
||||
Assert.IsTrue (ticket.Expiration.Year >= 6088, "Expiration");
|
||||
@ -78,11 +74,7 @@ namespace MonoCasTests.System.Web.Security {
|
||||
ticket = new FormsAuthenticationTicket (1, "mine", DateTime.MinValue, DateTime.MaxValue, true, "data");
|
||||
}
|
||||
catch (NullReferenceException) {
|
||||
#if NET_2_0
|
||||
Assert.Fail ("this should work on 2.0");
|
||||
#else
|
||||
Assert.Ignore ("fails with NullReferenceException on MS 1.x");
|
||||
#endif
|
||||
}
|
||||
Assert.AreEqual ("/", ticket.CookiePath, "CookiePath");
|
||||
Assert.AreEqual (DateTime.MaxValue, ticket.Expiration, "Expiration");
|
||||
|
@ -25,6 +25,9 @@
|
||||
// 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.Security.Cryptography;
|
||||
|
||||
|
||||
#if NET_4_0
|
||||
using System;
|
||||
using System.Text;
|
||||
@ -166,6 +169,39 @@ namespace MonoTests.System.Web.Security
|
||||
// Success
|
||||
}
|
||||
}
|
||||
|
||||
#if NET_4_5
|
||||
[Test]
|
||||
public void Protect ()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentNullException> (() =>
|
||||
MachineKey.Protect (null, null),
|
||||
"MachineKey.Protect not throwing an ArgumentNullException");
|
||||
|
||||
AssertExtensions.Throws<ArgumentNullException> (() =>
|
||||
MachineKey.Protect (null, new [] { "test" }),
|
||||
"MachineKey.Protect not throwing an ArgumentNullException");
|
||||
|
||||
var testString = "asfgasd43tqrt4";
|
||||
var validUsages = new [] { "usage1", "usage2" };
|
||||
var oneUsage = new [] { "usage1" };
|
||||
var invalidUsages = new [] { "usage1", "invalidUsage" };
|
||||
|
||||
var plainBytes = Encoding.ASCII.GetBytes (testString);
|
||||
var encryptedBytes = MachineKey.Protect (plainBytes, validUsages);
|
||||
var validDecryptedBytes = MachineKey.Unprotect (encryptedBytes, validUsages);
|
||||
|
||||
Assert.AreEqual (plainBytes, validDecryptedBytes, "Decryption didn't work");
|
||||
|
||||
AssertExtensions.Throws<CryptographicException> (() =>
|
||||
MachineKey.Unprotect (encryptedBytes, invalidUsages),
|
||||
"Purposes not encrypting properly");
|
||||
|
||||
AssertExtensions.Throws<CryptographicException> (() =>
|
||||
MachineKey.Unprotect (encryptedBytes, oneUsage),
|
||||
"Single purpose working when multiple supplied");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -0,0 +1,140 @@
|
||||
#if NET_4_5
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web.Security;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Web.Security {
|
||||
|
||||
[TestFixture]
|
||||
public class MembershipPasswordAttributeTest
|
||||
{
|
||||
private ValidationContext _validationContext;
|
||||
|
||||
public MembershipPasswordAttributeTest ()
|
||||
{
|
||||
_validationContext = new ValidationContext (new object ())
|
||||
{
|
||||
DisplayName = "testDisplay",
|
||||
MemberName = "testMember"
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsValid ()
|
||||
{
|
||||
var passwordAttribute = new MembershipPasswordAttributeTestClass ();
|
||||
Assert.IsTrue (passwordAttribute.IsValid (""), "sending an empty password password should should be treated as valid");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsValid_with_ValidationContext ()
|
||||
{
|
||||
var passwordAttribute = new MembershipPasswordAttributeTestClass ();
|
||||
var result = passwordAttribute.TestValidation ("", _validationContext);
|
||||
Assert.IsNull (result, "sending an empty password password should return a null response");
|
||||
|
||||
result = passwordAttribute.TestValidation ("a!12345", _validationContext);
|
||||
Assert.AreEqual (ValidationResult.Success, result, "Should suceed with a 7 character length and a single nonalphanumeric");
|
||||
|
||||
// test error priority
|
||||
passwordAttribute.MinRequiredPasswordLength = 4;
|
||||
passwordAttribute.MinRequiredNonAlphanumericCharacters = 2;
|
||||
result = passwordAttribute.TestValidation ("aaa", _validationContext);
|
||||
Assert.AreEqual ("The 'testDisplay' field is an invalid password. Password must have 4 or more characters.", result.ErrorMessage);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MinRequiredPasswordLength ()
|
||||
{
|
||||
var passwordAttribute = new MembershipPasswordAttributeTestClass ();
|
||||
var result = passwordAttribute.TestValidation ("a!1234", _validationContext);
|
||||
Assert.AreEqual ("The 'testDisplay' field is an invalid password. Password must have 7 or more characters.", result.ErrorMessage, "Error message not correct for lower Min characters");
|
||||
Assert.AreEqual (_validationContext.MemberName, result.MemberNames.FirstOrDefault (), "Member name not correct");
|
||||
|
||||
passwordAttribute.MinRequiredPasswordLength = 6;
|
||||
result = passwordAttribute.TestValidation ("a!1234", _validationContext);
|
||||
Assert.AreEqual (ValidationResult.Success, result, "Should suceed with a 6 character length after it's reset");
|
||||
|
||||
result = passwordAttribute.TestValidation ("a!123", _validationContext);
|
||||
Assert.AreEqual("The 'testDisplay' field is an invalid password. Password must have 6 or more characters.", result.ErrorMessage, "Error message not correct for Min characters of 6");
|
||||
|
||||
|
||||
passwordAttribute.MinRequiredPasswordLength = 1;
|
||||
result = passwordAttribute.TestValidation ("!", _validationContext);
|
||||
Assert.AreEqual(ValidationResult.Success, result, "Should suceed with a 6 character length after it's reset");
|
||||
|
||||
// Note there is no test for empty password here as it returns null and is therefore in the generic test
|
||||
|
||||
// Error Message changes
|
||||
passwordAttribute.MinRequiredPasswordLength = 5;
|
||||
passwordAttribute.MinPasswordLengthError = "There was an error";
|
||||
result = passwordAttribute.TestValidation ("a!13", _validationContext);
|
||||
Assert.AreEqual("There was an error", result.ErrorMessage, "Error Message wasn't correct without parameters.");
|
||||
|
||||
passwordAttribute.MinPasswordLengthError = "There was an error parameter1: {0}";
|
||||
result = passwordAttribute.TestValidation ("a!13", _validationContext);
|
||||
Assert.AreEqual("There was an error parameter1: testDisplay", result.ErrorMessage, "Error Message wasn't correct with 1 parameter.");
|
||||
|
||||
passwordAttribute.MinPasswordLengthError = "There was an error parameter1: {0} parameter2: {1}";
|
||||
result = passwordAttribute.TestValidation ("a!13", _validationContext);
|
||||
Assert.AreEqual ("There was an error parameter1: testDisplay parameter2: 5", result.ErrorMessage, "Error Message wasn't correct with 2 parameters.");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MinRequiredNonAlphanumericCharacters ()
|
||||
{
|
||||
var passwordAttribute = new MembershipPasswordAttributeTestClass ();
|
||||
var result = passwordAttribute.TestValidation ("a!12345", _validationContext);
|
||||
Assert.AreEqual (ValidationResult.Success, result, "Should succeed with the default 1 non alpha numeric");
|
||||
|
||||
result = passwordAttribute.TestValidation ("a123456", _validationContext);
|
||||
Assert.AreEqual ("The 'testDisplay' field is an invalid password. Password must have 1 or more non-alphanumeric characters.", result.ErrorMessage, "Expected validation to fail without non-alphanumerics");
|
||||
|
||||
|
||||
passwordAttribute.MinRequiredNonAlphanumericCharacters = 3;
|
||||
result = passwordAttribute.TestValidation ("a!&12345", _validationContext);
|
||||
Assert.AreEqual ("The 'testDisplay' field is an invalid password. Password must have 3 or more non-alphanumeric characters.", result.ErrorMessage, "Expected validation to fail without 3 non-alphanumerics");
|
||||
|
||||
result = passwordAttribute.TestValidation ("a!?&132154", _validationContext);
|
||||
Assert.AreEqual (ValidationResult.Success, result, "Should succeed with 3 non alpha numerics");
|
||||
|
||||
passwordAttribute.MinRequiredNonAlphanumericCharacters = 0;
|
||||
result = passwordAttribute.TestValidation ("a123456", _validationContext);
|
||||
Assert.AreEqual (ValidationResult.Success, result, "Should succeed with 0 non alpha numerics");
|
||||
|
||||
// Error Message changes
|
||||
passwordAttribute.MinRequiredNonAlphanumericCharacters = 1;
|
||||
passwordAttribute.MinNonAlphanumericCharactersError = "There was an error";
|
||||
result = passwordAttribute.TestValidation ("a123456", _validationContext);
|
||||
Assert.AreEqual ("There was an error", result.ErrorMessage, "Error Message wasn't correct without parameters.");
|
||||
|
||||
passwordAttribute.MinNonAlphanumericCharactersError = "There was an error parameter1: {0}";
|
||||
result = passwordAttribute.TestValidation ("a123456", _validationContext);
|
||||
Assert.AreEqual("There was an error parameter1: testDisplay", result.ErrorMessage, "Error Message wasn't correct with 1 parameter.");
|
||||
|
||||
passwordAttribute.MinNonAlphanumericCharactersError = "There was an error parameter1: {0} parameter2: {1}";
|
||||
result = passwordAttribute.TestValidation ("a123456", _validationContext);
|
||||
Assert.AreEqual ("There was an error parameter1: testDisplay parameter2: 1", result.ErrorMessage, "Error Message wasn't correct with 2 parameters.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FormatErrorMessage ()
|
||||
{
|
||||
var passwordAttribute = new MembershipPasswordAttribute ();
|
||||
Assert.AreEqual ("The field testDisplay2 is invalid.", passwordAttribute.FormatErrorMessage ("testDisplay2"));
|
||||
}
|
||||
|
||||
internal class MembershipPasswordAttributeTestClass : MembershipPasswordAttribute
|
||||
{
|
||||
public ValidationResult TestValidation (object val, ValidationContext context)
|
||||
{
|
||||
return IsValid (val, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -27,7 +27,6 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if NET_2_0
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
@ -74,4 +73,3 @@ namespace MonoTests.System.Web.Security {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,6 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if NET_2_0
|
||||
|
||||
using System;
|
||||
using System.Configuration.Provider;
|
||||
@ -214,4 +213,3 @@ namespace MonoTests.System.Web.Security {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -26,7 +26,6 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if NET_2_0
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
@ -90,4 +89,3 @@ namespace MonoTests.System.Web.Security {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,6 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if NET_2_0
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
@ -152,4 +151,3 @@ namespace MonoTests.System.Web.Security {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,6 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if NET_2_0
|
||||
|
||||
using System;
|
||||
using System.Configuration.Provider;
|
||||
@ -128,4 +127,3 @@ namespace MonoTests.System.Web.Security {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -26,7 +26,6 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if NET_2_0
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
@ -91,4 +90,3 @@ namespace MonoTests.System.Web.Security {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user