From b38e2011cf875d90390140413a4fc81b6248b0b3 Mon Sep 17 00:00:00 2001 From: Jacob Hines Date: Wed, 30 Aug 2023 15:26:11 -0500 Subject: [PATCH] Updated RouteOptionsExtensions.ExpandConfig to respect DangerousAcceptAnyServerCertificateValidator --- .../RouteOptionsExtensions.cs | 1 + .../RouteOptionsExtensionsShould.cs | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/MMLib.SwaggerForOcelot/RouteOptionsExtensions.cs b/src/MMLib.SwaggerForOcelot/RouteOptionsExtensions.cs index 0603894..df06f65 100644 --- a/src/MMLib.SwaggerForOcelot/RouteOptionsExtensions.cs +++ b/src/MMLib.SwaggerForOcelot/RouteOptionsExtensions.cs @@ -69,6 +69,7 @@ public static IEnumerable ExpandConfig( DownstreamHttpVersion = routeOption.DownstreamHttpVersion, DownstreamScheme = routeOption.DownstreamScheme, AuthenticationOptions = routeOption.AuthenticationOptions, + DangerousAcceptAnyServerCertificateValidator = routeOption.DangerousAcceptAnyServerCertificateValidator }); routeOptions.AddRange(versionMappedRouteOptions); } diff --git a/tests/MMLib.SwaggerForOcelot.Tests/RouteOptionsExtensionsShould.cs b/tests/MMLib.SwaggerForOcelot.Tests/RouteOptionsExtensionsShould.cs index 54a9f81..b1cd34d 100644 --- a/tests/MMLib.SwaggerForOcelot.Tests/RouteOptionsExtensionsShould.cs +++ b/tests/MMLib.SwaggerForOcelot.Tests/RouteOptionsExtensionsShould.cs @@ -52,5 +52,71 @@ public void GroupRoutesByPaths() .Should() .BeEquivalentTo("Get", "Post"); } + + [Fact] + public void ExpandConfig() + { + IEnumerable routeOptions = new List() + { + new RouteOptions(){ + DownstreamPathTemplate= "/api/{version}/masterdatatype", + UpstreamPathTemplate = "/masterdatatype", + UpstreamHttpMethod = new HashSet(){ "Get"}, + DangerousAcceptAnyServerCertificateValidator = true + }, + new RouteOptions(){ + DownstreamPathTemplate= "/api/{version}/masterdatatype", + UpstreamPathTemplate = "/masterdatatype", + UpstreamHttpMethod = new HashSet(){ "Post"}, + DangerousAcceptAnyServerCertificateValidator = true + }, + new RouteOptions(){ + DownstreamPathTemplate= "/api/{version}/masterdatatype/{everything}", + UpstreamPathTemplate = "/masterdatatype/{everything}", + UpstreamHttpMethod = new HashSet(){ "Delete"}, + DangerousAcceptAnyServerCertificateValidator = true + }, + new RouteOptions(){ + DownstreamPathTemplate= "/api/{version}/masterdatatype/{everything}", + UpstreamPathTemplate = "/masterdatatype/{everything}", + UpstreamHttpMethod = new HashSet(){ "Delete"}, + VirtualDirectory = "something", + DangerousAcceptAnyServerCertificateValidator = true + }, + new RouteOptions(){ + DownstreamPathTemplate= "/api/{version}/masterdata", + UpstreamPathTemplate = "/masterdata", + UpstreamHttpMethod = new HashSet(){ "Delete"}, + DangerousAcceptAnyServerCertificateValidator = true + }, + }; + + SwaggerEndPointOptions swaggerEndPointOptions = new() + { + Config = new List() + { + new SwaggerEndPointConfig() + { + Version = "v1" + } + } + }; + + IEnumerable actual = routeOptions.ExpandConfig(swaggerEndPointOptions); + + actual + .Should() + .HaveCount(5); + actual + .First() + .DownstreamPathTemplate + .Should() + .Contain("v1"); + actual + .First() + .DangerousAcceptAnyServerCertificateValidator + .Should() + .BeTrue(); + } } }