Skip to content

Commit

Permalink
[asp.net] A few moves/changes following previous patch review
Browse files Browse the repository at this point in the history
Backport of commit 21d2c6a

    * Makefile: Compile tests with TEST defined (to include System.Web.Util.
    MachineKeySectionUtils unit tests)
    * System.Web.dll.sources: Move MachineKeySectionUtils.cs from System.
    Web.Configuration_2.0 to System.Web.Util
    * System.Web_test.dll.sources: Move MachineKeySectionUtilsTest.cs from
    System.Web.Configuration_2.0 to System.Web.Util

    * System.Web.Configuration_2.0/MachineKeySection.cs: Adjust using
    clauses. Uncomment some code. Fix TripleDES versus 3DES for Validation
    under NET_4_0. Remove 'private' on fields/methods.
    * System.Web.Handlers/AssemblyResourceLoader.cs: Adjust using clauses
    * System.Web.Security/MembershipHelper.cs: Adjust using clauses
    * System.Web.Security/RolePrincipal.cs: Adjust using clauses
    * System.Web.SessionState_2.0/SessionId.cs: Adjust using clauses
    * System.Web.UI/LosFormatter.cs: Adjust using clauses.
    * System.Web.Util/MachineKeySectionUtils.cs: Moved from System.Web.
    Configuration_2.0. Rename namespace and remove 'internal' on type
    declaration

    * Test/System.Web.Util/MachineKeySectionUtilsTest.cs: Moved from Test/
    System.Web.Configuration/MachineKeySectionTest.cs. Add test case for
    TripleDES versus 3DES
  • Loading branch information
grendello committed Nov 26, 2010
1 parent e7419ca commit 08eecbd
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mcs/class/System.Web/Makefile
Expand Up @@ -279,7 +279,7 @@ TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -doc:$(test_lib:.dll=.xml) -nowarn:219,169,159
$(foreach file,$(NUNIT_APP_GLOBALRESOURCES_FILES),$(shell echo $(file) | sed -e 's;\(.*\)/\(.*\);/resource:\1/\2,App_GlobalResources/\2 ;g'))

ifeq (net_2_0, $(PROFILE))
TEST_MCS_FLAGS += -r:System.Web.Extensions.dll
TEST_MCS_FLAGS += -r:System.Web.Extensions.dll -d:TEST
endif

EXTRA_DISTFILES = $(RESOURCE_FILES_2) $(RESOURCE_FILES_1) $(TEST_RESOURCE_FILES) UplevelHelperDefinitions.xml $(RESX_DIST) \
Expand Down
Expand Up @@ -34,6 +34,7 @@
using System.Configuration;
using System.Xml;
using System.Security.Cryptography;
using System.Web.Util;

namespace System.Web.Configuration
{
Expand Down
Expand Up @@ -35,6 +35,7 @@
using System.ComponentModel;
using System.Configuration;
using System.Security.Cryptography;
using System.Web.Util;

namespace System.Web.Configuration {

Expand Down Expand Up @@ -127,7 +128,7 @@ protected override void Reset (ConfigurationElement parentElement)
get { return (string) base [decryptionKeyProp];}
set {
base[decryptionKeyProp] = value;
// SetDecryptionKey (value);
SetDecryptionKey (value);
}
}

Expand All @@ -138,7 +139,10 @@ protected override void Reset (ConfigurationElement parentElement)
set {
if (value == MachineKeyValidation.Custom)
throw new ArgumentException ();
// ValidationAlgorithm = value.ToString ();

string algo = value.ToString ();
// enum and accept values differs for TripleDES
ValidationAlgorithm = (algo == "TripleDES") ? "3DES" : algo;
}
}

Expand Down Expand Up @@ -175,7 +179,7 @@ protected override void Reset (ConfigurationElement parentElement)
get { return (string) base [validationKeyProp];}
set {
base[validationKeyProp] = value;
// SetValidationKey (value);
SetValidationKey (value);
}
}

Expand All @@ -188,10 +192,10 @@ protected override void Reset (ConfigurationElement parentElement)
get { return WebConfigurationManager.GetSection ("system.web/machineKey") as MachineKeySection; }
}

private byte[] decryption_key;
private byte[] validation_key;
private SymmetricAlgorithm decryption_template;
private KeyedHashAlgorithm validation_template;
byte[] decryption_key;
byte[] validation_key;
SymmetricAlgorithm decryption_template;
KeyedHashAlgorithm validation_template;

internal SymmetricAlgorithm GetDecryptionAlgorithm ()
{
Expand All @@ -200,7 +204,7 @@ internal SymmetricAlgorithm GetDecryptionAlgorithm ()
}

// not to be reused outside algorithm and key validation purpose
private SymmetricAlgorithm DecryptionTemplate {
SymmetricAlgorithm DecryptionTemplate {
get {
if (decryption_template == null)
decryption_template = GetDecryptionAlgorithm ();
Expand Down Expand Up @@ -238,7 +242,7 @@ internal KeyedHashAlgorithm GetValidationAlgorithm ()
}

// not to be reused outside algorithm and key validation purpose
private KeyedHashAlgorithm ValidationTemplate {
KeyedHashAlgorithm ValidationTemplate {
get {
if (validation_template == null)
validation_template = GetValidationAlgorithm ();
Expand Down
Expand Up @@ -34,6 +34,7 @@
using System.Web.Configuration;
using System.Security.Cryptography;
using System.Text;
using System.Web.Util;

namespace System.Web.Security
{
Expand Down
1 change: 1 addition & 0 deletions mcs/class/System.Web/System.Web.Security/RolePrincipal.cs
Expand Up @@ -34,6 +34,7 @@
using System.Security.Permissions;
using System.Security.Principal;
using System.Web.Configuration;
using System.Web.Util;
using System.IO;
using System.Text;

Expand Down
1 change: 1 addition & 0 deletions mcs/class/System.Web/System.Web.SessionState/SessionId.cs
Expand Up @@ -29,6 +29,7 @@
using System.Text;
using System.Security.Cryptography;
using System.Web.Configuration;
using System.Web.Util;

namespace System.Web.SessionState {

Expand Down
2 changes: 1 addition & 1 deletion mcs/class/System.Web/System.Web.UI/LosFormatter.cs
Expand Up @@ -32,7 +32,7 @@
using System.IO;
using System.Security.Permissions;
using System.Text;
using System.Web.Configuration;
using System.Web.Util;

namespace System.Web.UI {

Expand Down
Expand Up @@ -36,8 +36,9 @@
#endif
using System.Security.Cryptography;
using System.Text;
using System.Web.Configuration;

namespace System.Web.Configuration {
namespace System.Web.Util {

internal static class MachineKeySectionUtils {
static byte ToHexValue (char c, bool high)
Expand Down
3 changes: 2 additions & 1 deletion mcs/class/System.Web/System.Web.dll.sources
Expand Up @@ -200,7 +200,7 @@ System.Web.Configuration_2.0/IConfigMapPathFactory.cs
System.Web.Configuration_2.0/IRemoteWebConfigurationHostServer.cs
System.Web.Configuration_2.0/LowerCaseStringConverter.cs
System.Web.Configuration_2.0/MachineKeySection.cs
System.Web.Configuration_2.0/MachineKeySectionUtils.cs

System.Web.Configuration_2.0/MachineKeyValidationConverter.cs
System.Web.Configuration_2.0/MembershipSection.cs
System.Web.Configuration_2.0/MonoSettingsSection.cs
Expand Down Expand Up @@ -1194,6 +1194,7 @@ System.Web.Util/Helpers.cs
System.Web.Util/ICalls.cs
System.Web.Util/IWebObjectFactory.cs
System.Web.Util/IWebPropertyAccessor.cs
System.Web.Util/MachineKeySectionUtils.cs
System.Web.Util/SearchPattern.cs
System.Web.Util/SerializationHelper.cs
System.Web.Util/StrUtils.cs
Expand Down
2 changes: 1 addition & 1 deletion mcs/class/System.Web/System.Web_test.dll.sources
Expand Up @@ -86,7 +86,6 @@ System.Web.Configuration/DeploymentSectionTest.cs
System.Web.Configuration/GlobalizationSectionTest.cs
System.Web.Configuration/HostingEnvironmentSectionTest.cs
System.Web.Configuration/MachineKeySectionTest.cs
System.Web.Configuration/MachineKeySectionUtilsTest.cs
System.Web.Configuration/MachineKeyValidationConverterTest.cs
System.Web.Configuration/NullableStringValidatorTest.cs
System.Web.Configuration/ProfilePropertySettingsTest.cs
Expand Down Expand Up @@ -528,6 +527,7 @@ System.Web.UI.WebControls/WebColorConverterCas.cs
System.Web.UI.WebControls/WebControlCas.cs
System.Web.UI.WebControls/XmlCas.cs
System.Web.UI.WebControls/XmlDataSourceCas.cs
System.Web.Util/MachineKeySectionUtilsTest.cs
System.Web.Util/TransactionsCas.cs
System.Web.Util/UrlUtilsTest.cs
System.Web.Util/WorkItemCas.cs
Expand Down
Expand Up @@ -120,6 +120,27 @@ public void Validation_Custom ()
// cannot be set directly
}

[Test]
public void Validation ()
{
MachineKeySection section = new MachineKeySection ();
section.Validation = MachineKeyValidation.AES;
Assert.AreEqual ("AES", section.ValidationAlgorithm, "AES");
section.Validation = MachineKeyValidation.HMACSHA256;
Assert.AreEqual ("HMACSHA256", section.ValidationAlgorithm, "HMACSHA256");
section.Validation = MachineKeyValidation.HMACSHA384;
Assert.AreEqual ("HMACSHA384", section.ValidationAlgorithm, "HMACSHA384");
section.Validation = MachineKeyValidation.HMACSHA512;
Assert.AreEqual ("HMACSHA512", section.ValidationAlgorithm, "HMACSHA512");
section.Validation = MachineKeyValidation.MD5;
Assert.AreEqual ("MD5", section.ValidationAlgorithm, "MD5");
section.Validation = MachineKeyValidation.SHA1;
Assert.AreEqual ("SHA1", section.ValidationAlgorithm, "SHA1");
// special case, enum value and algorithm names differs
section.Validation = MachineKeyValidation.TripleDES;
Assert.AreEqual ("3DES", section.ValidationAlgorithm, "3DES");
}

[Test]
[ExpectedException (typeof (ArgumentException))]
public void ValidationAlgorithm ()
Expand Down
Expand Up @@ -29,6 +29,7 @@
using System;
using System.IO;
using System.Web.Configuration;
using System.Web.Util;
using NUnit.Framework;

namespace MonoTests.System.Web.Configuration {
Expand Down

0 comments on commit 08eecbd

Please sign in to comment.