Remove ChangeEnvironmentAction class and throw when env flag is set in mod_rewrite rule

This commit is contained in:
Nate McMaster 2016-09-23 16:05:46 -07:00
parent 58ef98b184
commit e003594fd8
No known key found for this signature in database
GPG Key ID: BD729980AA6A21BD
6 changed files with 73 additions and 52 deletions

3
.gitignore vendored
View File

@ -30,4 +30,5 @@ project.lock.json
.testPublish/
.idea/
.vscode/
*.nuget.props
*.nuget.targets

View File

@ -178,8 +178,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
if (flags.GetValue(FlagType.Env, out flag))
{
// parse env
_actions.Add(new ChangeEnvironmentAction(flag));
throw new NotSupportedException(Resources.Error_ChangeEnvironmentNotSupported);
}
if (flags.HasFlag(FlagType.Forbidden))

View File

@ -1,22 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
{
public class ChangeEnvironmentAction : UrlAction
{
public ChangeEnvironmentAction(string env)
{
// TODO
throw new NotImplementedException("Changing the environment is not implemented");
}
public override void ApplyAction(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch)
{
// Do stuff to modify the env
throw new NotImplementedException("Changing the environment is not implemented");
}
}
}

View File

@ -154,6 +154,22 @@ namespace Microsoft.AspNetCore.Rewrite
return GetString("Error_IntegerMatch_FormatExceptionMessage");
}
/// <summary>
/// Error adding a mod_rewrite rule. The change environment flag is not supported.
/// </summary>
internal static string Error_ChangeEnvironmentNotSupported
{
get { return GetString("Error_ChangeEnvironmentNotSupported"); }
}
/// <summary>
/// Error adding a mod_rewrite rule. The change environment flag is not supported.
/// </summary>
internal static string FormatError_ChangeEnvironmentNotSupported()
{
return GetString("Error_ChangeEnvironmentNotSupported");
}
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
@ -144,4 +144,7 @@
<data name="Error_IntegerMatch_FormatExceptionMessage" xml:space="preserve">
<value>Syntax error for integers in comparison.</value>
</data>
<data name="Error_ChangeEnvironmentNotSupported" xml:space="preserve">
<value>Error adding a mod_rewrite rule. The change environment flag is not supported.</value>
</data>
</root>

View File

@ -0,0 +1,24 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite;
using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests
{
public class RuleBuilderTest
{
[Fact]
// see https://httpd.apache.org/docs/2.4/rewrite/advanced.html#setenvvars
public void AddAction_Throws_ChangeEnvNotSupported()
{
var builder = new RuleBuilder();
var flags = new Flags();
flags.SetFlag(FlagType.Env, "rewritten:1");
var ex = Assert.Throws<NotSupportedException>(() => builder.AddAction(null, flags));
Assert.Equal(Resources.Error_ChangeEnvironmentNotSupported, ex.Message);
}
}
}