From 0c150e5722a3862ad969b91d53298404fb91a59d Mon Sep 17 00:00:00 2001 From: Raman Maksimchuk Date: Thu, 19 Sep 2024 18:51:27 +0300 Subject: [PATCH] Convert to theory: define 2 test cases --- .../Routing/RoutingTests.cs | 46 ++++++------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/test/Ocelot.AcceptanceTests/Routing/RoutingTests.cs b/test/Ocelot.AcceptanceTests/Routing/RoutingTests.cs index e45ec0cfa..61bc3fa12 100644 --- a/test/Ocelot.AcceptanceTests/Routing/RoutingTests.cs +++ b/test/Ocelot.AcceptanceTests/Routing/RoutingTests.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Http; using Ocelot.Configuration.File; +using System.Web; namespace Ocelot.AcceptanceTests.Routing { @@ -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 - { - new() - { - DownstreamPathTemplate = "/routed/api/{path}", - DownstreamHostAndPorts = new List - { - new() - { - Host = "localhost", - Port = port, - }, - }, - DownstreamScheme = "http", - UpstreamPathTemplate = "/api/{path}", - UpstreamHttpMethod = new List { "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)