mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
Merge branch 'andreatosato-master'
This commit is contained in:
commit
def55b3c3c
@ -25,6 +25,7 @@ Here is an example ReRoute configuration, You don't need to set all of these thi
|
||||
"Get"
|
||||
],
|
||||
"DownstreamHttpMethod": "",
|
||||
"DownstreamHttpVersion": "",
|
||||
"AddHeadersToRequest": {},
|
||||
"AddClaimsToRequest": {},
|
||||
"RouteClaimsRequirement": {},
|
||||
@ -279,3 +280,8 @@ Registering a callback
|
||||
_callbackHolder.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
DownstreamHttpVersion
|
||||
---------------------
|
||||
|
||||
Ocelot allows you to choose the HTTP version it will use to make the proxy request. It can be set as "1.0", "1.1" or "2.0".
|
@ -1,5 +1,6 @@
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Values;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@ -42,6 +43,7 @@ namespace Ocelot.Configuration.Builder
|
||||
private bool _dangerousAcceptAnyServerCertificateValidator;
|
||||
private SecurityOptions _securityOptions;
|
||||
private string _downstreamHttpMethod;
|
||||
private Version _downstreamHttpVersion;
|
||||
|
||||
public DownstreamReRouteBuilder()
|
||||
{
|
||||
@ -255,6 +257,12 @@ namespace Ocelot.Configuration.Builder
|
||||
return this;
|
||||
}
|
||||
|
||||
public DownstreamReRouteBuilder WithDownstreamHttpVersion(Version downstreamHttpVersion)
|
||||
{
|
||||
_downstreamHttpVersion = downstreamHttpVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DownstreamReRoute Build()
|
||||
{
|
||||
return new DownstreamReRoute(
|
||||
@ -290,7 +298,8 @@ namespace Ocelot.Configuration.Builder
|
||||
_addHeadersToUpstream,
|
||||
_dangerousAcceptAnyServerCertificateValidator,
|
||||
_securityOptions,
|
||||
_downstreamHttpMethod);
|
||||
_downstreamHttpMethod,
|
||||
_downstreamHttpVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,15 @@ namespace Ocelot.Configuration.Creator
|
||||
private readonly IHttpHandlerOptionsCreator _httpHandlerOptionsCreator;
|
||||
private readonly IAdministrationPath _adminPath;
|
||||
private readonly ILoadBalancerOptionsCreator _loadBalancerOptionsCreator;
|
||||
private readonly IVersionCreator _versionCreator;
|
||||
|
||||
public ConfigurationCreator(
|
||||
IServiceProviderConfigurationCreator serviceProviderConfigCreator,
|
||||
IQoSOptionsCreator qosOptionsCreator,
|
||||
IHttpHandlerOptionsCreator httpHandlerOptionsCreator,
|
||||
IServiceProvider serviceProvider,
|
||||
ILoadBalancerOptionsCreator loadBalancerOptionsCreator
|
||||
ILoadBalancerOptionsCreator loadBalancerOptionsCreator,
|
||||
IVersionCreator versionCreator
|
||||
)
|
||||
{
|
||||
_adminPath = serviceProvider.GetService<IAdministrationPath>();
|
||||
@ -27,6 +29,7 @@ namespace Ocelot.Configuration.Creator
|
||||
_serviceProviderConfigCreator = serviceProviderConfigCreator;
|
||||
_qosOptionsCreator = qosOptionsCreator;
|
||||
_httpHandlerOptionsCreator = httpHandlerOptionsCreator;
|
||||
_versionCreator = versionCreator;
|
||||
}
|
||||
|
||||
public InternalConfiguration Create(FileConfiguration fileConfiguration, List<ReRoute> reRoutes)
|
||||
@ -41,6 +44,8 @@ namespace Ocelot.Configuration.Creator
|
||||
|
||||
var adminPath = _adminPath != null ? _adminPath.Path : null;
|
||||
|
||||
var version = _versionCreator.Create(fileConfiguration.GlobalConfiguration.DownstreamHttpVersion);
|
||||
|
||||
return new InternalConfiguration(reRoutes,
|
||||
adminPath,
|
||||
serviceProviderConfiguration,
|
||||
@ -48,7 +53,8 @@ namespace Ocelot.Configuration.Creator
|
||||
lbOptions,
|
||||
fileConfiguration.GlobalConfiguration.DownstreamScheme,
|
||||
qosOptions,
|
||||
httpHandlerOptions
|
||||
httpHandlerOptions,
|
||||
version
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,12 @@ namespace Ocelot.Configuration.Creator
|
||||
public class DynamicsCreator : IDynamicsCreator
|
||||
{
|
||||
private readonly IRateLimitOptionsCreator _rateLimitOptionsCreator;
|
||||
private readonly IVersionCreator _versionCreator;
|
||||
|
||||
public DynamicsCreator(IRateLimitOptionsCreator rateLimitOptionsCreator)
|
||||
public DynamicsCreator(IRateLimitOptionsCreator rateLimitOptionsCreator, IVersionCreator versionCreator)
|
||||
{
|
||||
_rateLimitOptionsCreator = rateLimitOptionsCreator;
|
||||
_versionCreator = versionCreator;
|
||||
}
|
||||
|
||||
public List<ReRoute> Create(FileConfiguration fileConfiguration)
|
||||
@ -26,10 +28,13 @@ namespace Ocelot.Configuration.Creator
|
||||
var rateLimitOption = _rateLimitOptionsCreator
|
||||
.Create(fileDynamicReRoute.RateLimitRule, globalConfiguration);
|
||||
|
||||
var version = _versionCreator.Create(fileDynamicReRoute.DownstreamHttpVersion);
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithEnableRateLimiting(rateLimitOption.EnableRateLimiting)
|
||||
.WithRateLimitOptions(rateLimitOption)
|
||||
.WithServiceName(fileDynamicReRoute.ServiceName)
|
||||
.WithDownstreamHttpVersion(version)
|
||||
.Build();
|
||||
|
||||
var reRoute = new ReRouteBuilder()
|
||||
|
17
src/Ocelot/Configuration/Creator/HttpVersionCreator.cs
Normal file
17
src/Ocelot/Configuration/Creator/HttpVersionCreator.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace Ocelot.Configuration.Creator
|
||||
{
|
||||
using System;
|
||||
|
||||
public class HttpVersionCreator : IVersionCreator
|
||||
{
|
||||
public Version Create(string downstreamHttpVersion)
|
||||
{
|
||||
if (!Version.TryParse(downstreamHttpVersion, out Version version))
|
||||
{
|
||||
version = new Version(1, 1);
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
9
src/Ocelot/Configuration/Creator/IVersionCreator.cs
Normal file
9
src/Ocelot/Configuration/Creator/IVersionCreator.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Ocelot.Configuration.Creator
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface IVersionCreator
|
||||
{
|
||||
Version Create(string downstreamHttpVersion);
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ namespace Ocelot.Configuration.Creator
|
||||
private readonly IDownstreamAddressesCreator _downstreamAddressesCreator;
|
||||
private readonly IReRouteKeyCreator _reRouteKeyCreator;
|
||||
private readonly ISecurityOptionsCreator _securityOptionsCreator;
|
||||
private readonly IVersionCreator _versionCreator;
|
||||
|
||||
public ReRoutesCreator(
|
||||
IClaimsToThingCreator claimsToThingCreator,
|
||||
@ -37,7 +38,8 @@ namespace Ocelot.Configuration.Creator
|
||||
IDownstreamAddressesCreator downstreamAddressesCreator,
|
||||
ILoadBalancerOptionsCreator loadBalancerOptionsCreator,
|
||||
IReRouteKeyCreator reRouteKeyCreator,
|
||||
ISecurityOptionsCreator securityOptionsCreator
|
||||
ISecurityOptionsCreator securityOptionsCreator,
|
||||
IVersionCreator versionCreator
|
||||
)
|
||||
{
|
||||
_reRouteKeyCreator = reRouteKeyCreator;
|
||||
@ -55,6 +57,7 @@ namespace Ocelot.Configuration.Creator
|
||||
_httpHandlerOptionsCreator = httpHandlerOptionsCreator;
|
||||
_loadBalancerOptionsCreator = loadBalancerOptionsCreator;
|
||||
_securityOptionsCreator = securityOptionsCreator;
|
||||
_versionCreator = versionCreator;
|
||||
}
|
||||
|
||||
public List<ReRoute> Create(FileConfiguration fileConfiguration)
|
||||
@ -104,6 +107,8 @@ namespace Ocelot.Configuration.Creator
|
||||
|
||||
var securityOptions = _securityOptionsCreator.Create(fileReRoute.SecurityOptions);
|
||||
|
||||
var downstreamHttpVersion = _versionCreator.Create(fileReRoute.DownstreamHttpVersion);
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithKey(fileReRoute.Key)
|
||||
.WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
|
||||
@ -138,6 +143,7 @@ namespace Ocelot.Configuration.Creator
|
||||
.WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
|
||||
.WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
|
||||
.WithSecurityOptions(securityOptions)
|
||||
.WithDownstreamHttpVersion(downstreamHttpVersion)
|
||||
.WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod)
|
||||
.Build();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
namespace Ocelot.Configuration
|
||||
{
|
||||
using Creator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Values;
|
||||
|
||||
@ -39,7 +40,8 @@ namespace Ocelot.Configuration
|
||||
List<AddHeader> addHeadersToUpstream,
|
||||
bool dangerousAcceptAnyServerCertificateValidator,
|
||||
SecurityOptions securityOptions,
|
||||
string downstreamHttpMethod)
|
||||
string downstreamHttpMethod,
|
||||
Version downstreamHttpVersion)
|
||||
{
|
||||
DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
|
||||
AddHeadersToDownstream = addHeadersToDownstream;
|
||||
@ -74,6 +76,7 @@ namespace Ocelot.Configuration
|
||||
AddHeadersToUpstream = addHeadersToUpstream;
|
||||
SecurityOptions = securityOptions;
|
||||
DownstreamHttpMethod = downstreamHttpMethod;
|
||||
DownstreamHttpVersion = downstreamHttpVersion;
|
||||
}
|
||||
|
||||
public string Key { get; }
|
||||
@ -109,5 +112,6 @@ namespace Ocelot.Configuration
|
||||
public bool DangerousAcceptAnyServerCertificateValidator { get; }
|
||||
public SecurityOptions SecurityOptions { get; }
|
||||
public string DownstreamHttpMethod { get; }
|
||||
public Version DownstreamHttpVersion { get; }
|
||||
}
|
||||
}
|
||||
|
@ -4,5 +4,6 @@ namespace Ocelot.Configuration.File
|
||||
{
|
||||
public string ServiceName { get; set; }
|
||||
public FileRateLimitRule RateLimitRule { get; set; }
|
||||
public string DownstreamHttpVersion { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -26,5 +26,7 @@
|
||||
public string DownstreamScheme { get; set; }
|
||||
|
||||
public FileHttpHandlerOptions HttpHandlerOptions { get; set; }
|
||||
|
||||
public string DownstreamHttpVersion { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -56,5 +56,6 @@ namespace Ocelot.Configuration.File
|
||||
public int Timeout { get; set; }
|
||||
public bool DangerousAcceptAnyServerCertificateValidator { get; set; }
|
||||
public FileSecurityOptions SecurityOptions { get; set; }
|
||||
public string DownstreamHttpVersion { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Configuration
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface IInternalConfiguration
|
||||
{
|
||||
List<ReRoute> ReRoutes { get; }
|
||||
@ -19,5 +21,7 @@ namespace Ocelot.Configuration
|
||||
QoSOptions QoSOptions { get; }
|
||||
|
||||
HttpHandlerOptions HttpHandlerOptions { get; }
|
||||
|
||||
Version DownstreamHttpVersion { get; }
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Configuration
|
||||
{
|
||||
using System;
|
||||
|
||||
public class InternalConfiguration : IInternalConfiguration
|
||||
{
|
||||
public InternalConfiguration(
|
||||
@ -12,7 +14,8 @@ namespace Ocelot.Configuration
|
||||
LoadBalancerOptions loadBalancerOptions,
|
||||
string downstreamScheme,
|
||||
QoSOptions qoSOptions,
|
||||
HttpHandlerOptions httpHandlerOptions)
|
||||
HttpHandlerOptions httpHandlerOptions,
|
||||
Version downstreamHttpVersion)
|
||||
{
|
||||
ReRoutes = reRoutes;
|
||||
AdministrationPath = administrationPath;
|
||||
@ -22,6 +25,7 @@ namespace Ocelot.Configuration
|
||||
DownstreamScheme = downstreamScheme;
|
||||
QoSOptions = qoSOptions;
|
||||
HttpHandlerOptions = httpHandlerOptions;
|
||||
DownstreamHttpVersion = downstreamHttpVersion;
|
||||
}
|
||||
|
||||
public List<ReRoute> ReRoutes { get; }
|
||||
@ -32,5 +36,7 @@ namespace Ocelot.Configuration
|
||||
public string DownstreamScheme { get; }
|
||||
public QoSOptions QoSOptions { get; }
|
||||
public HttpHandlerOptions HttpHandlerOptions { get; }
|
||||
|
||||
public Version DownstreamHttpVersion { get; }
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,11 @@
|
||||
RuleForEach(reRoute => reRoute.DownstreamHostAndPorts)
|
||||
.SetValidator(hostAndPortValidator);
|
||||
});
|
||||
|
||||
When(reRoute => !string.IsNullOrEmpty(reRoute.DownstreamHttpVersion), () =>
|
||||
{
|
||||
RuleFor(r => r.DownstreamHttpVersion).Matches("^[0-9]([.,][0-9]{1,1})?$");
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<bool> IsSupportedAuthenticationProviders(FileAuthenticationOptions authenticationOptions, CancellationToken cancellationToken)
|
||||
|
@ -136,6 +136,7 @@ namespace Ocelot.DependencyInjection
|
||||
Services.TryAddSingleton<IFrameworkDescription, FrameworkDescription>();
|
||||
Services.TryAddSingleton<IQoSFactory, QoSFactory>();
|
||||
Services.TryAddSingleton<IExceptionToErrorMapper, HttpExeptionToErrorMapper>();
|
||||
Services.TryAddSingleton<IVersionCreator, HttpVersionCreator>();
|
||||
|
||||
//add security
|
||||
this.AddSecurity();
|
||||
|
@ -1,5 +1,6 @@
|
||||
namespace Ocelot.DownstreamRouteFinder.Finder
|
||||
{
|
||||
using System;
|
||||
using Configuration;
|
||||
using Configuration.Builder;
|
||||
using Configuration.Creator;
|
||||
@ -54,6 +55,7 @@
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithDownstreamScheme(configuration.DownstreamScheme)
|
||||
.WithLoadBalancerOptions(configuration.LoadBalancerOptions)
|
||||
.WithDownstreamHttpVersion(configuration.DownstreamHttpVersion)
|
||||
.WithUpstreamPathTemplate(upstreamPathTemplate);
|
||||
|
||||
var rateLimitOptions = configuration.ReRoutes != null
|
||||
|
@ -24,7 +24,8 @@
|
||||
{
|
||||
Content = await MapContent(request),
|
||||
Method = MapMethod(request, downstreamReRoute),
|
||||
RequestUri = MapUri(request)
|
||||
RequestUri = MapUri(request),
|
||||
Version = downstreamReRoute.DownstreamHttpVersion,
|
||||
};
|
||||
|
||||
MapHeaders(request, requestMessage);
|
||||
|
243
test/Ocelot.AcceptanceTests/HttpTests.cs
Normal file
243
test/Ocelot.AcceptanceTests/HttpTests.cs
Normal file
@ -0,0 +1,243 @@
|
||||
namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Configuration.File;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
public class HttpTests : IDisposable
|
||||
{
|
||||
private readonly Steps _steps;
|
||||
private readonly ServiceHandler _serviceHandler;
|
||||
|
||||
public HttpTests()
|
||||
{
|
||||
_serviceHandler = new ServiceHandler();
|
||||
_steps = new Steps();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_when_using_http_one()
|
||||
{
|
||||
const int port = 53219;
|
||||
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/{url}",
|
||||
DownstreamScheme = "https",
|
||||
UpstreamPathTemplate = "/{url}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = port,
|
||||
},
|
||||
},
|
||||
DownstreamHttpMethod = "POST",
|
||||
DownstreamHttpVersion = "1.0",
|
||||
DangerousAcceptAnyServerCertificateValidator = true
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http1))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_when_using_http_one_point_one()
|
||||
{
|
||||
const int port = 53279;
|
||||
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/{url}",
|
||||
DownstreamScheme = "https",
|
||||
UpstreamPathTemplate = "/{url}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = port,
|
||||
},
|
||||
},
|
||||
DownstreamHttpMethod = "POST",
|
||||
DownstreamHttpVersion = "1.1",
|
||||
DangerousAcceptAnyServerCertificateValidator = true
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http1))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_when_using_http_two_point_zero()
|
||||
{
|
||||
const int port = 53675;
|
||||
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/{url}",
|
||||
DownstreamScheme = "https",
|
||||
UpstreamPathTemplate = "/{url}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = port,
|
||||
},
|
||||
},
|
||||
DownstreamHttpMethod = "POST",
|
||||
DownstreamHttpVersion = "2.0",
|
||||
DangerousAcceptAnyServerCertificateValidator = true
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const string expected = "here is some content";
|
||||
var httpContent = new StringContent(expected);
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http2))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(_ => _steps.ThenTheResponseBodyShouldBe(expected))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_500_when_using_http_one_to_talk_to_server_running_http_two()
|
||||
{
|
||||
const int port = 53677;
|
||||
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/{url}",
|
||||
DownstreamScheme = "https",
|
||||
UpstreamPathTemplate = "/{url}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = port,
|
||||
},
|
||||
},
|
||||
DownstreamHttpMethod = "POST",
|
||||
DownstreamHttpVersion = "1.1",
|
||||
DangerousAcceptAnyServerCertificateValidator = true
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const string expected = "here is some content";
|
||||
var httpContent = new StringContent(expected);
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http2))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.InternalServerError))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_when_using_http_two_to_talk_to_server_running_http_one_point_one()
|
||||
{
|
||||
const int port = 53679;
|
||||
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/{url}",
|
||||
DownstreamScheme = "https",
|
||||
UpstreamPathTemplate = "/{url}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = port,
|
||||
},
|
||||
},
|
||||
DownstreamHttpMethod = "POST",
|
||||
DownstreamHttpVersion = "2.0",
|
||||
DangerousAcceptAnyServerCertificateValidator = true
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const string expected = "here is some content";
|
||||
var httpContent = new StringContent(expected);
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http1))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(_ => _steps.ThenTheResponseBodyShouldBe(expected))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int port, HttpProtocols protocols)
|
||||
{
|
||||
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||
{
|
||||
context.Response.StatusCode = 200;
|
||||
var reader = new StreamReader(context.Request.Body);
|
||||
var body = await reader.ReadToEndAsync();
|
||||
await context.Response.WriteAsync(body);
|
||||
}, port, protocols);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_serviceHandler.Dispose();
|
||||
_steps.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ namespace Ocelot.AcceptanceTests
|
||||
public void should_load_balance_request_with_least_connection()
|
||||
{
|
||||
int portOne = 50591;
|
||||
int portTwo = 51482;
|
||||
int portTwo = 54483;
|
||||
|
||||
var downstreamServiceOneUrl = $"http://localhost:{portOne}";
|
||||
var downstreamServiceTwoUrl = $"http://localhost:{portTwo}";
|
||||
|
@ -6,9 +6,11 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
|
||||
public class ServiceHandler : IDisposable
|
||||
{
|
||||
@ -47,6 +49,31 @@
|
||||
_builder.Start();
|
||||
}
|
||||
|
||||
public void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, RequestDelegate del, int port, HttpProtocols protocols)
|
||||
{
|
||||
_builder = new WebHostBuilder()
|
||||
.UseUrls(baseUrl)
|
||||
.UseKestrel()
|
||||
.ConfigureKestrel(serverOptions =>
|
||||
{
|
||||
serverOptions.Listen(IPAddress.Loopback, port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps("idsrv3test.pfx", "idsrv3test");
|
||||
listenOptions.Protocols = protocols;
|
||||
});
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UsePathBase(basePath);
|
||||
app.Run(del);
|
||||
})
|
||||
.Build();
|
||||
|
||||
_builder.Start();
|
||||
}
|
||||
|
||||
public void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, string fileName, string password, int port, RequestDelegate del)
|
||||
{
|
||||
_builder = new WebHostBuilder()
|
||||
|
@ -392,6 +392,7 @@ namespace Ocelot.AcceptanceTests
|
||||
_ocelotServer = new TestServer(_webHostBuilder);
|
||||
|
||||
_ocelotClient = _ocelotServer.CreateClient();
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
public void WhenIGetUrlOnTheApiGatewayWaitingForTheResponseToBeOk(string url)
|
||||
|
@ -59,7 +59,7 @@ namespace Ocelot.Benchmarks
|
||||
|
||||
_downstreamContext = new DownstreamContext(httpContext)
|
||||
{
|
||||
Configuration = new InternalConfiguration(new List<ReRoute>(), null, null, null, null, null, null, null)
|
||||
Configuration = new InternalConfiguration(new List<ReRoute>(), null, null, null, null, null, null, null, null)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
private readonly Mock<IQoSOptionsCreator> _qosCreator;
|
||||
private readonly Mock<IHttpHandlerOptionsCreator> _hhoCreator;
|
||||
private readonly Mock<ILoadBalancerOptionsCreator> _lboCreator;
|
||||
private readonly Mock<IVersionCreator> _vCreator;
|
||||
private FileConfiguration _fileConfig;
|
||||
private List<ReRoute> _reRoutes;
|
||||
private ServiceProviderConfiguration _spc;
|
||||
@ -30,6 +31,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
public ConfigurationCreatorTests()
|
||||
{
|
||||
_vCreator = new Mock<IVersionCreator>();
|
||||
_lboCreator = new Mock<ILoadBalancerOptionsCreator>();
|
||||
_hhoCreator = new Mock<IHttpHandlerOptionsCreator>();
|
||||
_qosCreator = new Mock<IQoSOptionsCreator>();
|
||||
@ -117,7 +119,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
private void WhenICreate()
|
||||
{
|
||||
var serviceProvider = _serviceCollection.BuildServiceProvider();
|
||||
_creator = new ConfigurationCreator(_spcCreator.Object, _qosCreator.Object, _hhoCreator.Object, serviceProvider, _lboCreator.Object);
|
||||
_creator = new ConfigurationCreator(_spcCreator.Object, _qosCreator.Object, _hhoCreator.Object, serviceProvider, _lboCreator.Object, _vCreator.Object);
|
||||
_result = _creator.Create(_fileConfig, _reRoutes);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
using System;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
@ -14,15 +15,18 @@
|
||||
{
|
||||
private readonly DynamicsCreator _creator;
|
||||
private readonly Mock<IRateLimitOptionsCreator> _rloCreator;
|
||||
private readonly Mock<IVersionCreator> _versionCreator;
|
||||
private List<ReRoute> _result;
|
||||
private FileConfiguration _fileConfig;
|
||||
private RateLimitOptions _rlo1;
|
||||
private RateLimitOptions _rlo2;
|
||||
private Version _version;
|
||||
|
||||
public DynamicsCreatorTests()
|
||||
{
|
||||
_versionCreator = new Mock<IVersionCreator>();
|
||||
_rloCreator = new Mock<IRateLimitOptionsCreator>();
|
||||
_creator = new DynamicsCreator(_rloCreator.Object);
|
||||
_creator = new DynamicsCreator(_rloCreator.Object, _versionCreator.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -50,7 +54,8 @@
|
||||
RateLimitRule = new FileRateLimitRule
|
||||
{
|
||||
EnableRateLimiting = false
|
||||
}
|
||||
},
|
||||
DownstreamHttpVersion = "1.1"
|
||||
},
|
||||
new FileDynamicReRoute
|
||||
{
|
||||
@ -58,16 +63,19 @@
|
||||
RateLimitRule = new FileRateLimitRule
|
||||
{
|
||||
EnableRateLimiting = true
|
||||
}
|
||||
},
|
||||
DownstreamHttpVersion = "2.0"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(_ => GivenThe(fileConfig))
|
||||
.And(_ => GivenTheRloCreatorReturns())
|
||||
.And(_ => GivenTheVersionCreatorReturns())
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheReRoutesAreReturned())
|
||||
.And(_ => ThenTheRloCreatorIsCalledCorrectly())
|
||||
.And(_ => ThenTheVersionCreatorIsCalledCorrectly())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -80,18 +88,32 @@
|
||||
_fileConfig.GlobalConfiguration), Times.Once);
|
||||
}
|
||||
|
||||
private void ThenTheVersionCreatorIsCalledCorrectly()
|
||||
{
|
||||
_versionCreator.Verify(x => x.Create(_fileConfig.DynamicReRoutes[0].DownstreamHttpVersion), Times.Once);
|
||||
_versionCreator.Verify(x => x.Create(_fileConfig.DynamicReRoutes[1].DownstreamHttpVersion), Times.Once);
|
||||
}
|
||||
|
||||
private void ThenTheReRoutesAreReturned()
|
||||
{
|
||||
_result.Count.ShouldBe(2);
|
||||
_result[0].DownstreamReRoute[0].EnableEndpointEndpointRateLimiting.ShouldBeFalse();
|
||||
_result[0].DownstreamReRoute[0].RateLimitOptions.ShouldBe(_rlo1);
|
||||
_result[0].DownstreamReRoute[0].DownstreamHttpVersion.ShouldBe(_version);
|
||||
_result[0].DownstreamReRoute[0].ServiceName.ShouldBe(_fileConfig.DynamicReRoutes[0].ServiceName);
|
||||
|
||||
_result[1].DownstreamReRoute[0].EnableEndpointEndpointRateLimiting.ShouldBeTrue();
|
||||
_result[1].DownstreamReRoute[0].RateLimitOptions.ShouldBe(_rlo2);
|
||||
_result[1].DownstreamReRoute[0].DownstreamHttpVersion.ShouldBe(_version);
|
||||
_result[1].DownstreamReRoute[0].ServiceName.ShouldBe(_fileConfig.DynamicReRoutes[1].ServiceName);
|
||||
}
|
||||
|
||||
private void GivenTheVersionCreatorReturns()
|
||||
{
|
||||
_version = new Version("1.1");
|
||||
_versionCreator.Setup(x => x.Create(It.IsAny<string>())).Returns(_version);
|
||||
}
|
||||
|
||||
private void GivenTheRloCreatorReturns()
|
||||
{
|
||||
_rlo1 = new RateLimitOptionsBuilder().Build();
|
||||
|
@ -15,6 +15,8 @@ using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
using System;
|
||||
|
||||
public class FileConfigurationSetterTests
|
||||
{
|
||||
private FileConfiguration _fileConfiguration;
|
||||
@ -38,7 +40,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
var fileConfig = new FileConfiguration();
|
||||
var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();
|
||||
var config = new InternalConfiguration(new List<ReRoute>(), string.Empty, serviceProviderConfig, "asdf", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
|
||||
var config = new InternalConfiguration(new List<ReRoute>(), string.Empty, serviceProviderConfig, "asdf", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
|
||||
|
||||
this.Given(x => GivenTheFollowingConfiguration(fileConfig))
|
||||
.And(x => GivenTheRepoReturns(new OkResponse()))
|
||||
|
@ -87,7 +87,7 @@
|
||||
_reRoutes = new List<ReRoute> { new ReRouteBuilder().Build() };
|
||||
_aggregates = new List<ReRoute> { new ReRouteBuilder().Build() };
|
||||
_dynamics = new List<ReRoute> { new ReRouteBuilder().Build() };
|
||||
_internalConfig = new InternalConfiguration(null, "", null, "", null, "", null, null);
|
||||
_internalConfig = new InternalConfiguration(null, "", null, "", null, "", null, null, null);
|
||||
|
||||
_reRoutesCreator.Setup(x => x.Create(It.IsAny<FileConfiguration>())).Returns(_reRoutes);
|
||||
_aggregatesCreator.Setup(x => x.Create(It.IsAny<FileConfiguration>(), It.IsAny<List<ReRoute>>())).Returns(_aggregates);
|
||||
|
@ -120,6 +120,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
public string DownstreamScheme { get; }
|
||||
public QoSOptions QoSOptions { get; }
|
||||
public HttpHandlerOptions HttpHandlerOptions { get; }
|
||||
public Version DownstreamHttpVersion { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
using System;
|
||||
using Moq;
|
||||
using Ocelot.Cache;
|
||||
using Ocelot.Configuration;
|
||||
@ -30,6 +31,7 @@
|
||||
private Mock<ILoadBalancerOptionsCreator> _lboCreator;
|
||||
private Mock<IReRouteKeyCreator> _rrkCreator;
|
||||
private Mock<ISecurityOptionsCreator> _soCreator;
|
||||
private Mock<IVersionCreator> _versionCreator;
|
||||
private FileConfiguration _fileConfig;
|
||||
private ReRouteOptions _rro;
|
||||
private string _requestId;
|
||||
@ -46,6 +48,7 @@
|
||||
private LoadBalancerOptions _lbo;
|
||||
private List<ReRoute> _result;
|
||||
private SecurityOptions _securityOptions;
|
||||
private Version _expectedVersion;
|
||||
|
||||
public ReRoutesCreatorTests()
|
||||
{
|
||||
@ -63,6 +66,7 @@
|
||||
_lboCreator = new Mock<ILoadBalancerOptionsCreator>();
|
||||
_rrkCreator = new Mock<IReRouteKeyCreator>();
|
||||
_soCreator = new Mock<ISecurityOptionsCreator>();
|
||||
_versionCreator = new Mock<IVersionCreator>();
|
||||
|
||||
_creator = new ReRoutesCreator(
|
||||
_cthCreator.Object,
|
||||
@ -78,7 +82,8 @@
|
||||
_daCreator.Object,
|
||||
_lboCreator.Object,
|
||||
_rrkCreator.Object,
|
||||
_soCreator.Object
|
||||
_soCreator.Object,
|
||||
_versionCreator.Object
|
||||
);
|
||||
}
|
||||
|
||||
@ -155,6 +160,7 @@
|
||||
|
||||
private void GivenTheDependenciesAreSetUpCorrectly()
|
||||
{
|
||||
_expectedVersion = new Version("1.1");
|
||||
_rro = new ReRouteOptions(false, false, false, false, false);
|
||||
_requestId = "testy";
|
||||
_rrk = "besty";
|
||||
@ -182,6 +188,7 @@
|
||||
_hfarCreator.Setup(x => x.Create(It.IsAny<FileReRoute>())).Returns(_ht);
|
||||
_daCreator.Setup(x => x.Create(It.IsAny<FileReRoute>())).Returns(_dhp);
|
||||
_lboCreator.Setup(x => x.Create(It.IsAny<FileLoadBalancerOptions>())).Returns(_lbo);
|
||||
_versionCreator.Setup(x => x.Create(It.IsAny<string>())).Returns(_expectedVersion);
|
||||
}
|
||||
|
||||
private void ThenTheReRoutesAreCreated()
|
||||
@ -209,6 +216,7 @@
|
||||
|
||||
private void ThenTheReRouteIsSet(FileReRoute expected, int reRouteIndex)
|
||||
{
|
||||
_result[reRouteIndex].DownstreamReRoute[0].DownstreamHttpVersion.ShouldBe(_expectedVersion);
|
||||
_result[reRouteIndex].DownstreamReRoute[0].IsAuthenticated.ShouldBe(_rro.IsAuthenticated);
|
||||
_result[reRouteIndex].DownstreamReRoute[0].IsAuthorised.ShouldBe(_rro.IsAuthorised);
|
||||
_result[reRouteIndex].DownstreamReRoute[0].IsCached.ShouldBe(_rro.IsCached);
|
||||
|
@ -305,6 +305,71 @@
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("1.0")]
|
||||
[InlineData("1.1")]
|
||||
[InlineData("2.0")]
|
||||
[InlineData("1,0")]
|
||||
[InlineData("1,1")]
|
||||
[InlineData("2,0")]
|
||||
[InlineData("1")]
|
||||
[InlineData("2")]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
public void should_be_valid_re_route_using_downstream_http_version(string version)
|
||||
{
|
||||
var fileReRoute = new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/test",
|
||||
UpstreamPathTemplate = "/test",
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 5000,
|
||||
},
|
||||
},
|
||||
DownstreamHttpVersion = version,
|
||||
};
|
||||
|
||||
this.Given(_ => GivenThe(fileReRoute))
|
||||
.When(_ => WhenIValidate())
|
||||
.Then(_ => ThenTheResultIsValid())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("retg1.1")]
|
||||
[InlineData("re2.0")]
|
||||
[InlineData("1,0a")]
|
||||
[InlineData("a1,1")]
|
||||
[InlineData("12,0")]
|
||||
[InlineData("asdf")]
|
||||
public void should_be_invalid_re_route_using_downstream_http_version(string version)
|
||||
{
|
||||
var fileReRoute = new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/test",
|
||||
UpstreamPathTemplate = "/test",
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 5000,
|
||||
},
|
||||
},
|
||||
DownstreamHttpVersion = version,
|
||||
};
|
||||
|
||||
this.Given(_ => GivenThe(fileReRoute))
|
||||
.When(_ => WhenIValidate())
|
||||
.Then(_ => ThenTheResultIsInvalid())
|
||||
.And(_ => ThenTheErrorsContains("'Downstream Http Version' is not in the correct format."))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenAnAuthProvider(string key)
|
||||
{
|
||||
var schemes = new List<AuthenticationScheme>
|
||||
|
54
test/Ocelot.UnitTests/Configuration/VersionCreatorTests.cs
Normal file
54
test/Ocelot.UnitTests/Configuration/VersionCreatorTests.cs
Normal file
@ -0,0 +1,54 @@
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
using System;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
public class VersionCreatorTests
|
||||
{
|
||||
private readonly HttpVersionCreator _creator;
|
||||
private string _input;
|
||||
private Version _result;
|
||||
|
||||
public VersionCreatorTests()
|
||||
{
|
||||
_creator = new HttpVersionCreator();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_version_based_on_input()
|
||||
{
|
||||
this.Given(_ => GivenTheInput("2.0"))
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheResultIs(2, 0))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_default_to_version_one_point_one()
|
||||
{
|
||||
this.Given(_ => GivenTheInput(""))
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheResultIs(1, 1))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheInput(string input)
|
||||
{
|
||||
_input = input;
|
||||
}
|
||||
|
||||
private void WhenICreate()
|
||||
{
|
||||
_result = _creator.Create(_input);
|
||||
}
|
||||
|
||||
private void ThenTheResultIs(int major, int minor)
|
||||
{
|
||||
_result.Major.ShouldBe(major);
|
||||
_result.Minor.ShouldBe(minor);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
using System;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
@ -44,7 +45,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
[Fact]
|
||||
public void should_create_downstream_route()
|
||||
{
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration))
|
||||
.When(_ => WhenICreate())
|
||||
@ -71,7 +72,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
var reRoutes = new List<ReRoute> { reRoute };
|
||||
|
||||
var configuration = new InternalConfiguration(reRoutes, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(reRoutes, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration))
|
||||
.When(_ => WhenICreate())
|
||||
@ -83,7 +84,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
[Fact]
|
||||
public void should_cache_downstream_route()
|
||||
{
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration, "/geoffisthebest/"))
|
||||
.When(_ => WhenICreate())
|
||||
@ -96,7 +97,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
[Fact]
|
||||
public void should_not_cache_downstream_route()
|
||||
{
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration, "/geoffistheworst/"))
|
||||
.When(_ => WhenICreate())
|
||||
@ -110,7 +111,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
public void should_create_downstream_route_with_no_path()
|
||||
{
|
||||
var upstreamUrlPath = "/auth/";
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
|
||||
.When(_ => WhenICreate())
|
||||
@ -122,7 +123,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
public void should_create_downstream_route_with_only_first_segment_no_traling_slash()
|
||||
{
|
||||
var upstreamUrlPath = "/auth";
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
|
||||
.When(_ => WhenICreate())
|
||||
@ -134,7 +135,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
public void should_create_downstream_route_with_segments_no_traling_slash()
|
||||
{
|
||||
var upstreamUrlPath = "/auth/test";
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
|
||||
.When(_ => WhenICreate())
|
||||
@ -146,7 +147,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
public void should_create_downstream_route_and_remove_query_string()
|
||||
{
|
||||
var upstreamUrlPath = "/auth/test?test=1&best=2";
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
|
||||
.When(_ => WhenICreate())
|
||||
@ -158,7 +159,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
public void should_create_downstream_route_for_sticky_sessions()
|
||||
{
|
||||
var loadBalancerOptions = new LoadBalancerOptionsBuilder().WithType(nameof(CookieStickySessions)).WithKey("boom").WithExpiryInMs(1).Build();
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration))
|
||||
.When(_ => WhenICreate())
|
||||
@ -174,7 +175,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithTimeoutValue(1)
|
||||
.Build();
|
||||
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration))
|
||||
.And(_ => GivenTheQosCreatorReturns(qoSOptions))
|
||||
@ -186,7 +187,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
[Fact]
|
||||
public void should_create_downstream_route_with_handler_options()
|
||||
{
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration))
|
||||
.When(_ => WhenICreate())
|
||||
|
@ -1,5 +1,6 @@
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
@ -48,7 +49,7 @@
|
||||
[Fact]
|
||||
public void should_call_scoped_data_repository_correctly()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, new ServiceProviderConfigurationBuilder().Build(), "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
|
||||
var config = new InternalConfiguration(null, null, new ServiceProviderConfigurationBuilder().Build(), "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
|
@ -13,6 +13,8 @@ using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
using System;
|
||||
|
||||
public class DownstreamRouteFinderTests
|
||||
{
|
||||
private readonly IDownstreamRouteProvider _downstreamRouteFinder;
|
||||
@ -739,7 +741,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
private void GivenTheConfigurationIs(List<ReRoute> reRoutesConfig, string adminPath, ServiceProviderConfiguration serviceProviderConfig)
|
||||
{
|
||||
_reRoutesConfig = reRoutesConfig;
|
||||
_config = new InternalConfiguration(_reRoutesConfig, adminPath, serviceProviderConfig, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
|
||||
_config = new InternalConfiguration(_reRoutesConfig, adminPath, serviceProviderConfig, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
|
||||
}
|
||||
|
||||
private void GivenThereIsAnUpstreamUrlPath(string upstreamUrlPath)
|
||||
|
@ -1,5 +1,6 @@
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
@ -140,12 +141,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
private void GivenTheReRoutes(List<ReRoute> reRoutes)
|
||||
{
|
||||
_config = new InternalConfiguration(reRoutes, "", null, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
|
||||
_config = new InternalConfiguration(reRoutes, "", null, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
|
||||
}
|
||||
|
||||
private void GivenTheReRoutes(List<ReRoute> reRoutes, ServiceProviderConfiguration config)
|
||||
{
|
||||
_config = new InternalConfiguration(reRoutes, "", config, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
|
||||
_config = new InternalConfiguration(reRoutes, "", config, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -382,7 +382,7 @@
|
||||
|
||||
private void GivenTheServiceProviderConfigIs(ServiceProviderConfiguration config)
|
||||
{
|
||||
var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null);
|
||||
var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null, null);
|
||||
_downstreamContext.Configuration = configuration;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
[Fact]
|
||||
public void NoDownstreamException()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, null, null, null, null, null, null);
|
||||
var config = new InternalConfiguration(null, null, null, null, null, null, null, null, null);
|
||||
|
||||
this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigurationIs(config))
|
||||
@ -65,7 +65,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
[Fact]
|
||||
public void DownstreamException()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, null, null, null, null, null, null);
|
||||
var config = new InternalConfiguration(null, null, null, null, null, null, null, null, null);
|
||||
|
||||
this.Given(_ => GivenAnExceptionWillBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigurationIs(config))
|
||||
@ -77,7 +77,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
[Fact]
|
||||
public void ShouldSetRequestId()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, null, "requestidkey", null, null, null, null);
|
||||
var config = new InternalConfiguration(null, null, null, "requestidkey", null, null, null, null, null);
|
||||
|
||||
this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigurationIs(config))
|
||||
@ -90,7 +90,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
[Fact]
|
||||
public void ShouldSetAspDotNetRequestId()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, null, null, null, null, null, null);
|
||||
var config = new InternalConfiguration(null, null, null, null, null, null, null, null, null);
|
||||
|
||||
this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigurationIs(config))
|
||||
|
@ -20,7 +20,7 @@
|
||||
{
|
||||
var configRepo = new Mock<IInternalConfigurationRepository>();
|
||||
configRepo.Setup(x => x.Get())
|
||||
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, null, null, null, null, null, null)));
|
||||
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, null, null, null, null, null, null, null)));
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<IInternalConfigurationRepository>(configRepo.Object);
|
||||
var sp = services.BuildServiceProvider();
|
||||
@ -35,7 +35,7 @@
|
||||
var client = new Mock<IDiscoveryClient>();
|
||||
var configRepo = new Mock<IInternalConfigurationRepository>();
|
||||
configRepo.Setup(x => x.Get())
|
||||
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, serviceProviderConfig, null, null, null, null, null)));
|
||||
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, serviceProviderConfig, null, null, null, null, null, null)));
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<IInternalConfigurationRepository>(configRepo.Object);
|
||||
services.AddSingleton<IDiscoveryClient>(client.Object);
|
||||
|
@ -139,7 +139,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
private void GivenTheConfigurationIs(ServiceProviderConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null);
|
||||
var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null, null);
|
||||
_downstreamContext.Configuration = configuration;
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@
|
||||
.And(_ => GivenTheInputRequestHasHost(host))
|
||||
.And(_ => GivenTheInputRequestHasPath(path))
|
||||
.And(_ => GivenTheInputRequestHasQueryString(queryString))
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasUri(expectedUri))
|
||||
@ -80,6 +81,7 @@
|
||||
{
|
||||
this.Given(_ => GivenTheInputRequestHasMethod(method))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasMethod(method))
|
||||
@ -107,6 +109,7 @@
|
||||
this.Given(_ => GivenTheInputRequestHasHeaders())
|
||||
.And(_ => GivenTheInputRequestHasMethod("GET"))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasEachHeader())
|
||||
@ -119,6 +122,7 @@
|
||||
this.Given(_ => GivenTheInputRequestHasNoHeaders())
|
||||
.And(_ => GivenTheInputRequestHasMethod("GET"))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasNoHeaders())
|
||||
@ -131,6 +135,7 @@
|
||||
this.Given(_ => GivenTheInputRequestHasContent("This is my content"))
|
||||
.And(_ => GivenTheInputRequestHasMethod("GET"))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasContent("This is my content"))
|
||||
@ -143,6 +148,7 @@
|
||||
this.Given(_ => GivenTheInputRequestHasNullContent())
|
||||
.And(_ => GivenTheInputRequestHasMethod("GET"))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasNoContent())
|
||||
@ -155,6 +161,7 @@
|
||||
this.Given(_ => GivenTheInputRequestHasNoContentType())
|
||||
.And(_ => GivenTheInputRequestHasMethod("GET"))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasNoContent())
|
||||
@ -167,6 +174,7 @@
|
||||
this.Given(_ => GivenTheInputRequestHasNoContentLength())
|
||||
.And(_ => GivenTheInputRequestHasMethod("GET"))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasNoContent())
|
||||
@ -192,6 +200,7 @@
|
||||
.And(_ => GivenTheContentMD5Is(md5bytes))
|
||||
.And(_ => GivenTheInputRequestHasMethod("GET"))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasContentTypeHeader("application/json"))
|
||||
@ -213,6 +222,7 @@
|
||||
.And(_ => GivenTheContentTypeIs("application/json"))
|
||||
.And(_ => GivenTheInputRequestHasMethod("POST"))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.And(_ => GivenTheDownstreamReRoute())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasContentTypeHeader("application/json"))
|
||||
@ -223,7 +233,15 @@
|
||||
|
||||
private void GivenTheDownstreamReRouteMethodIs(string input)
|
||||
{
|
||||
_downstreamReRoute = new DownstreamReRouteBuilder().WithDownStreamHttpMethod(input).Build();
|
||||
_downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownStreamHttpMethod(input)
|
||||
.WithDownstreamHttpVersion(new Version("1.1")).Build();
|
||||
}
|
||||
|
||||
private void GivenTheDownstreamReRoute()
|
||||
{
|
||||
_downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamHttpVersion(new Version("1.1")).Build();
|
||||
}
|
||||
|
||||
private void GivenTheInputRequestHasNoContentLength()
|
||||
|
Loading…
x
Reference in New Issue
Block a user