Skip to content

Commit

Permalink
A few moves/changes following previous patch review
Browse files Browse the repository at this point in the history
* 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
Sebastien Pouliot authored and grendello committed Nov 2, 2010
1 parent 4106e07 commit 8d8cae9
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 21 deletions.
4 changes: 2 additions & 2 deletions mcs/class/System.Web/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,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 = \
Expand Down Expand Up @@ -442,4 +442,4 @@ ifdef STANDALONE_TEST_COMPILABLE_TESTS
done
endif



Original file line number Diff line number Diff line change
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 @@ public string DecryptionKey {
get { return (string) base [decryptionKeyProp];}
set {
base[decryptionKeyProp] = value;
// SetDecryptionKey (value);
SetDecryptionKey (value);
}
}

Expand All @@ -138,7 +139,10 @@ public MachineKeyValidation Validation {
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 @@ public string ValidationKey {
get { return (string) base [validationKeyProp];}
set {
base[validationKeyProp] = value;
// SetValidationKey (value);
SetValidationKey (value);
}
}

Expand All @@ -188,10 +192,10 @@ internal static MachineKeySection Config {
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Configuration;
using System.Web.Util;

namespace System.Web.Handlers {
#if SYSTEM_WEB_EXTENSIONS
Expand Down
5 changes: 3 additions & 2 deletions mcs/class/System.Web/System.Web.Security/MembershipHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// System.Web.Security.MembershipEncryptionHelper
// System.Web.Security.MembershipHelper
//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
Expand Down Expand Up @@ -27,10 +27,11 @@
// 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.Configuration.Provider;
using System.Security.Cryptography;
using System.Web.Configuration;
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// System.Web.Configuration.MachineKeySection
// System.Web.Util.MachineKeySectionUtils
//
// Authors:
// Chris Toshok (toshok@ximian.com)
Expand Down Expand Up @@ -34,12 +34,13 @@
using System.Configuration.Provider;
using System.Security.Cryptography;
using System.Text;
using System.Web.Configuration;

#if NET_2_0

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

internal static class MachineKeySectionUtils {
static class MachineKeySectionUtils {
static byte ToHexValue (char c, bool high)
{
byte v;
Expand Down
2 changes: 1 addition & 1 deletion mcs/class/System.Web/System.Web.dll.sources
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ System.Web.Configuration_2.0/LowerCaseStringConverter.cs
System.Web.Configuration_2.0/MachineKeyCompatibilityMode.cs
System.Web.Configuration_2.0/MachineKeyRegistryStorage.cs
System.Web.Configuration_2.0/MachineKeySection.cs
System.Web.Configuration_2.0/MachineKeySectionUtils.cs
System.Web.Configuration_2.0/MachineKeyValidation.cs
System.Web.Configuration_2.0/MachineKeyValidationConverter.cs
System.Web.Configuration_2.0/MembershipSection.cs
Expand Down Expand Up @@ -1166,6 +1165,7 @@ System.Web.Util/HttpEncoder.cs
System.Web.Util/ICalls.cs
System.Web.Util/IWebObjectFactory.cs
System.Web.Util/IWebPropertyAccessor.cs
System.Web.Util/MachineKeySectionUtils.cs
System.Web.Util/RuntimeHelpers.cs
System.Web.Util/SearchPattern.cs
System.Web.Util/SerializationHelper.cs
Expand Down
2 changes: 1 addition & 1 deletion mcs/class/System.Web/System.Web_test.dll.sources
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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 @@ -551,6 +550,7 @@ System.Web.UI.WebControls/WebControlCas.cs
System.Web.UI.WebControls/XmlCas.cs
System.Web.UI.WebControls/XmlDataSourceCas.cs
System.Web.Util/HttpEncoderTest.cs
System.Web.Util/MachineKeySectionUtilsTest.cs
System.Web.Util/RequestValidatorTest.cs
System.Web.Util/TransactionsCas.cs
System.Web.Util/UrlUtilsTest.cs
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
using System;
using System.IO;
using System.Web.Configuration;
using System.Web.Util;
using NUnit.Framework;

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

[TestFixture]
public class MachineKeySectionUtilsTest {
Expand Down

0 comments on commit 8d8cae9

Please sign in to comment.