mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 16:18:14 +08:00
Rename all ReRoute to Route to move closer to YARP +semver: breaking
This commit is contained in:
@ -3,7 +3,6 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Request.Middleware;
|
||||
using Ocelot.Responses;
|
||||
@ -16,7 +15,7 @@
|
||||
|
||||
public class IPSecurityPolicyTests
|
||||
{
|
||||
private readonly DownstreamReRouteBuilder _downstreamReRouteBuilder;
|
||||
private readonly DownstreamRouteBuilder _downstreamRouteBuilder;
|
||||
private readonly IPSecurityPolicy _ipSecurityPolicy;
|
||||
private Response response;
|
||||
private HttpContext _httpContext;
|
||||
@ -26,14 +25,14 @@
|
||||
_httpContext = new DefaultHttpContext();
|
||||
_httpContext.Items.UpsertDownstreamRequest(new DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "http://test.com")));
|
||||
_httpContext.Connection.RemoteIpAddress = Dns.GetHostAddresses("192.168.1.1")[0];
|
||||
_downstreamReRouteBuilder = new DownstreamReRouteBuilder();
|
||||
_downstreamRouteBuilder = new DownstreamRouteBuilder();
|
||||
_ipSecurityPolicy = new IPSecurityPolicy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_No_blocked_Ip_and_allowed_Ip()
|
||||
{
|
||||
this.Given(x => x.GivenSetDownstreamReRoute())
|
||||
this.Given(x => x.GivenSetDownstreamRoute())
|
||||
.When(x => x.WhenTheSecurityPolicy())
|
||||
.Then(x => x.ThenSecurityPassing())
|
||||
.BDDfy();
|
||||
@ -44,7 +43,7 @@
|
||||
{
|
||||
_httpContext.Connection.RemoteIpAddress = Dns.GetHostAddresses("192.168.1.1")[0];
|
||||
this.Given(x => x.GivenSetBlockedIP())
|
||||
.Given(x => x.GivenSetDownstreamReRoute())
|
||||
.Given(x => x.GivenSetDownstreamRoute())
|
||||
.When(x => x.WhenTheSecurityPolicy())
|
||||
.Then(x => x.ThenNotSecurityPassing())
|
||||
.BDDfy();
|
||||
@ -55,7 +54,7 @@
|
||||
{
|
||||
_httpContext.Connection.RemoteIpAddress = Dns.GetHostAddresses("192.168.1.2")[0];
|
||||
this.Given(x => x.GivenSetBlockedIP())
|
||||
.Given(x => x.GivenSetDownstreamReRoute())
|
||||
.Given(x => x.GivenSetDownstreamRoute())
|
||||
.When(x => x.WhenTheSecurityPolicy())
|
||||
.Then(x => x.ThenSecurityPassing())
|
||||
.BDDfy();
|
||||
@ -66,7 +65,7 @@
|
||||
{
|
||||
_httpContext.Connection.RemoteIpAddress = Dns.GetHostAddresses("192.168.1.1")[0];
|
||||
this.Given(x => x.GivenSetAllowedIP())
|
||||
.Given(x => x.GivenSetDownstreamReRoute())
|
||||
.Given(x => x.GivenSetDownstreamRoute())
|
||||
.When(x => x.WhenTheSecurityPolicy())
|
||||
.Then(x => x.ThenSecurityPassing())
|
||||
.BDDfy();
|
||||
@ -77,7 +76,7 @@
|
||||
{
|
||||
_httpContext.Connection.RemoteIpAddress = Dns.GetHostAddresses("192.168.1.2")[0];
|
||||
this.Given(x => x.GivenSetAllowedIP())
|
||||
.Given(x => x.GivenSetDownstreamReRoute())
|
||||
.Given(x => x.GivenSetDownstreamRoute())
|
||||
.When(x => x.WhenTheSecurityPolicy())
|
||||
.Then(x => x.ThenNotSecurityPassing())
|
||||
.BDDfy();
|
||||
@ -85,22 +84,22 @@
|
||||
|
||||
private void GivenSetAllowedIP()
|
||||
{
|
||||
_downstreamReRouteBuilder.WithSecurityOptions(new SecurityOptions(new List<string> { "192.168.1.1" }, new List<string>()));
|
||||
_downstreamRouteBuilder.WithSecurityOptions(new SecurityOptions(new List<string> { "192.168.1.1" }, new List<string>()));
|
||||
}
|
||||
|
||||
private void GivenSetBlockedIP()
|
||||
{
|
||||
_downstreamReRouteBuilder.WithSecurityOptions(new SecurityOptions(new List<string>(), new List<string> { "192.168.1.1" }));
|
||||
_downstreamRouteBuilder.WithSecurityOptions(new SecurityOptions(new List<string>(), new List<string> { "192.168.1.1" }));
|
||||
}
|
||||
|
||||
private void GivenSetDownstreamReRoute()
|
||||
private void GivenSetDownstreamRoute()
|
||||
{
|
||||
_httpContext.Items.UpsertDownstreamReRoute(_downstreamReRouteBuilder.Build());
|
||||
_httpContext.Items.UpsertDownstreamRoute(_downstreamRouteBuilder.Build());
|
||||
}
|
||||
|
||||
private void WhenTheSecurityPolicy()
|
||||
{
|
||||
response = _ipSecurityPolicy.Security(_httpContext.Items.DownstreamReRoute(), _httpContext).GetAwaiter().GetResult();
|
||||
response = _ipSecurityPolicy.Security(_httpContext.Items.DownstreamRoute(), _httpContext).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private void ThenSecurityPassing()
|
||||
|
Reference in New Issue
Block a user