Skip to content

Commit

Permalink
Convert to theory: define 2 test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
raman-m committed Sep 19, 2024
1 parent 4848e11 commit 0c150e5
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions test/Ocelot.AcceptanceTests/Routing/RoutingTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Http;
using Ocelot.Configuration.File;
using System.Web;

namespace Ocelot.AcceptanceTests.Routing
{
Expand Down Expand Up @@ -1167,41 +1168,22 @@ public void should_fix_issue_271()
.BDDfy();
}

[Fact]
[Theory]
[Trait("Bug", "2116")]
public void should_change_downstream_path_by_upstream_path_when_path_contains_malicious_characters()
[InlineData("debug()")] // no query
[InlineData("debug%28%29")] // debug()
public void Should_change_downstream_path_by_upstream_path_when_path_contains_malicious_characters(string path)
{
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
{
new()
{
DownstreamPathTemplate = "/routed/api/{path}",
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new()
{
Host = "localhost",
Port = port,
},
},
DownstreamScheme = "http",
UpstreamPathTemplate = "/api/{path}",
UpstreamHttpMethod = new List<string> { "Get" },
},
},
};

this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/routed/api/debug(", HttpStatusCode.OK, string.Empty))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/api/debug("))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => ThenTheDownstreamUrlPathShouldBe("/routed/api/debug("))
.BDDfy();
var configuration = GivenDefaultConfiguration(port, "/api/{path}", "/routed/api/{path}");
var decodedDownstreamUrlPath = $"/routed/api/{HttpUtility.UrlDecode(path)}";
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", decodedDownstreamUrlPath, HttpStatusCode.OK, string.Empty))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway($"/api/{path}")) // should be encoded
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => ThenTheDownstreamUrlPathShouldBe(decodedDownstreamUrlPath))
.BDDfy();
}

private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, HttpStatusCode statusCode, string responseBody)
Expand Down

0 comments on commit 0c150e5

Please sign in to comment.