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/ .testPublish/
.idea/ .idea/
.vscode/ .vscode/
*.nuget.props
*.nuget.targets

View File

@ -178,8 +178,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
if (flags.GetValue(FlagType.Env, out flag)) if (flags.GetValue(FlagType.Env, out flag))
{ {
// parse env throw new NotSupportedException(Resources.Error_ChangeEnvironmentNotSupported);
_actions.Add(new ChangeEnvironmentAction(flag));
} }
if (flags.HasFlag(FlagType.Forbidden)) 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"); 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) private static string GetString(string name, params string[] formatterNames)
{ {
var value = _resourceManager.GetString(name); var value = _resourceManager.GetString(name);

View File

@ -144,4 +144,7 @@
<data name="Error_IntegerMatch_FormatExceptionMessage" xml:space="preserve"> <data name="Error_IntegerMatch_FormatExceptionMessage" xml:space="preserve">
<value>Syntax error for integers in comparison.</value> <value>Syntax error for integers in comparison.</value>
</data> </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> </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);
}
}
}