mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
Ive made the acceptance tests share the same builder in an effort to duplicate the linux port in use issue I have when running acceptance tests...seems to have been some use...now to test in CI (#486)
This commit is contained in:
parent
daa0491992
commit
600732651b
@ -20,14 +20,14 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
public class AggregateTests : IDisposable
|
public class AggregateTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _serviceOneBuilder;
|
|
||||||
private IWebHost _serviceTwoBuilder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private string _downstreamPathOne;
|
private string _downstreamPathOne;
|
||||||
private string _downstreamPathTwo;
|
private string _downstreamPathTwo;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public AggregateTests()
|
public AggregateTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51885,
|
Port = 51875,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UpstreamPathTemplate = "/laura",
|
UpstreamPathTemplate = "/laura",
|
||||||
@ -157,7 +157,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
var expected = "{\"Laura\":{Hello from Laura},\"Tom\":{Hello from Tom}}";
|
var expected = "{\"Laura\":{Hello from Laura},\"Tom\":{Hello from Tom}}";
|
||||||
|
|
||||||
this.Given(x => x.GivenServiceOneIsRunning("http://localhost:51885", "/", 200, "{Hello from Laura}"))
|
this.Given(x => x.GivenServiceOneIsRunning("http://localhost:51875", "/", 200, "{Hello from Laura}"))
|
||||||
.Given(x => x.GivenServiceTwoIsRunning("http://localhost:51886", "/", 200, "{Hello from Tom}"))
|
.Given(x => x.GivenServiceTwoIsRunning("http://localhost:51886", "/", 200, "{Hello from Tom}"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning())
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
@ -370,64 +370,40 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenServiceOneIsRunning(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenServiceOneIsRunning(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_serviceOneBuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_downstreamPathOne = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
if (_downstreamPathOne != basePath)
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
{
|
}
|
||||||
_downstreamPathOne = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
else
|
||||||
|
{
|
||||||
if(_downstreamPathOne != basePath)
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(responseBody);
|
||||||
context.Response.StatusCode = statusCode;
|
}
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_serviceOneBuilder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenServiceTwoIsRunning(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenServiceTwoIsRunning(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_serviceTwoBuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_downstreamPathTwo = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
if (_downstreamPathTwo != basePath)
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
{
|
}
|
||||||
_downstreamPathTwo = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
else
|
||||||
|
{
|
||||||
if(_downstreamPathTwo != basePath)
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(responseBody);
|
||||||
context.Response.StatusCode = statusCode;
|
}
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_serviceTwoBuilder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ThenTheDownstreamUrlPathShouldBe(string expectedDownstreamPathOne, string expectedDownstreamPath)
|
internal void ThenTheDownstreamUrlPathShouldBe(string expectedDownstreamPathOne, string expectedDownstreamPath)
|
||||||
@ -438,8 +414,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_serviceOneBuilder?.Dispose();
|
_serviceHandler.Dispose();
|
||||||
_serviceTwoBuilder?.Dispose();
|
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,36 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using IdentityServer4.AccessTokenValidation;
|
|
||||||
using IdentityServer4.Models;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
using IdentityServer4.Test;
|
using IdentityServer4.Test;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using IdentityServer4.AccessTokenValidation;
|
||||||
|
using IdentityServer4.Models;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class AuthenticationTests : IDisposable
|
public class AuthenticationTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _servicebuilder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private IWebHost _identityServerBuilder;
|
private IWebHost _identityServerBuilder;
|
||||||
private string _identityServerRootUrl = "http://localhost:51888";
|
private string _identityServerRootUrl = "http://localhost:51888";
|
||||||
private string _downstreamServicePath = "/";
|
private string _downstreamServicePath = "/";
|
||||||
private string _downstreamServiceHost = "localhost";
|
private string _downstreamServiceHost = "localhost";
|
||||||
private int _downstreamServicePort = 51876;
|
|
||||||
private string _downstreamServiceScheme = "http";
|
private string _downstreamServiceScheme = "http";
|
||||||
private string _downstreamServiceUrl = "http://localhost:51876";
|
private string _downstreamServiceUrl = "http://localhost:";
|
||||||
private readonly Action<IdentityServerAuthenticationOptions> _options;
|
private readonly Action<IdentityServerAuthenticationOptions> _options;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public AuthenticationTests()
|
public AuthenticationTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
_options = o =>
|
_options = o =>
|
||||||
{
|
{
|
||||||
@ -46,6 +45,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_401_using_identity_server_access_token()
|
public void should_return_401_using_identity_server_access_token()
|
||||||
{
|
{
|
||||||
|
int port = 54329;
|
||||||
|
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
@ -58,7 +59,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host =_downstreamServiceHost,
|
Host =_downstreamServiceHost,
|
||||||
Port = _downstreamServicePort,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = _downstreamServiceScheme,
|
DownstreamScheme = _downstreamServiceScheme,
|
||||||
@ -73,7 +74,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 201, string.Empty))
|
.And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 201, string.Empty))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
.And(x => _steps.GivenThePostHasContent("postContent"))
|
.And(x => _steps.GivenThePostHasContent("postContent"))
|
||||||
@ -85,7 +86,9 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_200_using_identity_server()
|
public void should_return_response_200_using_identity_server()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
int port = 54099;
|
||||||
|
|
||||||
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
{
|
{
|
||||||
@ -97,7 +100,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host =_downstreamServiceHost,
|
Host =_downstreamServiceHost,
|
||||||
Port = _downstreamServicePort,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = _downstreamServiceScheme,
|
DownstreamScheme = _downstreamServiceScheme,
|
||||||
@ -112,7 +115,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 200, "Hello from Laura"))
|
.And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
|
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
@ -126,7 +129,9 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_401_using_identity_server_with_token_requested_for_other_api()
|
public void should_return_response_401_using_identity_server_with_token_requested_for_other_api()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
int port = 54196;
|
||||||
|
|
||||||
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
{
|
{
|
||||||
@ -138,7 +143,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host =_downstreamServiceHost,
|
Host =_downstreamServiceHost,
|
||||||
Port = _downstreamServicePort,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = _downstreamServiceScheme,
|
DownstreamScheme = _downstreamServiceScheme,
|
||||||
@ -153,7 +158,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 200, "Hello from Laura"))
|
.And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenIHaveATokenForApi2(_identityServerRootUrl))
|
.And(x => _steps.GivenIHaveATokenForApi2(_identityServerRootUrl))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
@ -166,7 +171,9 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_201_using_identity_server_access_token()
|
public void should_return_201_using_identity_server_access_token()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
int port = 52226;
|
||||||
|
|
||||||
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
{
|
{
|
||||||
@ -178,7 +185,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host =_downstreamServiceHost,
|
Host =_downstreamServiceHost,
|
||||||
Port = _downstreamServicePort,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = _downstreamServiceScheme,
|
DownstreamScheme = _downstreamServiceScheme,
|
||||||
@ -193,7 +200,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 201, string.Empty))
|
.And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 201, string.Empty))
|
||||||
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
|
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
@ -207,7 +214,9 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_201_using_identity_server_reference_token()
|
public void should_return_201_using_identity_server_reference_token()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
int port = 52222;
|
||||||
|
|
||||||
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
{
|
{
|
||||||
@ -219,7 +228,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host =_downstreamServiceHost,
|
Host =_downstreamServiceHost,
|
||||||
Port = _downstreamServicePort,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = _downstreamServiceScheme,
|
DownstreamScheme = _downstreamServiceScheme,
|
||||||
@ -234,7 +243,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Reference))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Reference))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 201, string.Empty))
|
.And(x => x.GivenThereIsAServiceRunningOn($"{_downstreamServiceUrl}{port}", 201, string.Empty))
|
||||||
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
|
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
@ -247,23 +256,11 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody)
|
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_servicebuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
context.Response.StatusCode = statusCode;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
await context.Response.WriteAsync(responseBody);
|
||||||
.UseIISIntegration()
|
});
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.Run(async context =>
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_servicebuilder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAnIdentityServerOn(string url, string apiName, string api2Name, AccessTokenType tokenType)
|
private void GivenThereIsAnIdentityServerOn(string url, string apiName, string api2Name, AccessTokenType tokenType)
|
||||||
@ -371,7 +368,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_servicebuilder?.Dispose();
|
_serviceHandler.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
_identityServerBuilder?.Dispose();
|
_identityServerBuilder?.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,32 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using IdentityServer4.AccessTokenValidation;
|
|
||||||
using IdentityServer4.Models;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
using IdentityServer4;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using IdentityServer4.AccessTokenValidation;
|
||||||
|
using IdentityServer4.Models;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
using IdentityServer4.Test;
|
using IdentityServer4.Test;
|
||||||
|
|
||||||
public class AuthorisationTests : IDisposable
|
public class AuthorisationTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _servicebuilder;
|
|
||||||
private IWebHost _identityServerBuilder;
|
private IWebHost _identityServerBuilder;
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private Action<IdentityServerAuthenticationOptions> _options;
|
private readonly Action<IdentityServerAuthenticationOptions> _options;
|
||||||
private string _identityServerRootUrl = "http://localhost:51888";
|
private string _identityServerRootUrl = "http://localhost:51888";
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public AuthorisationTests()
|
public AuthorisationTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
_options = o =>
|
_options = o =>
|
||||||
{
|
{
|
||||||
@ -42,8 +41,10 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_200_authorising_route()
|
public void should_return_response_200_authorising_route()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
int port = 52875;
|
||||||
{
|
|
||||||
|
var configuration = new FileConfiguration
|
||||||
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
{
|
{
|
||||||
new FileReRoute
|
new FileReRoute
|
||||||
@ -54,7 +55,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51876,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = "http",
|
DownstreamScheme = "http",
|
||||||
@ -83,10 +84,10 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", 200, "Hello from Laura"))
|
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
|
.And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
@ -100,7 +101,9 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_403_authorising_route()
|
public void should_return_response_403_authorising_route()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
int port = 59471;
|
||||||
|
|
||||||
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
{
|
{
|
||||||
@ -112,7 +115,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51876,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = "http",
|
DownstreamScheme = "http",
|
||||||
@ -143,7 +146,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", 200, "Hello from Laura"))
|
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
|
.And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
@ -156,7 +159,9 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_200_using_identity_server_with_allowed_scope()
|
public void should_return_response_200_using_identity_server_with_allowed_scope()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
int port = 63471;
|
||||||
|
|
||||||
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
{
|
{
|
||||||
@ -168,7 +173,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51876,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = "http",
|
DownstreamScheme = "http",
|
||||||
@ -184,7 +189,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", 200, "Hello from Laura"))
|
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888"))
|
.And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
@ -197,7 +202,9 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_403_using_identity_server_with_scope_not_allowed()
|
public void should_return_response_403_using_identity_server_with_scope_not_allowed()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
int port = 60571;
|
||||||
|
|
||||||
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
{
|
{
|
||||||
@ -209,7 +216,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51876,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = "http",
|
DownstreamScheme = "http",
|
||||||
@ -225,7 +232,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", 200, "Hello from Laura"))
|
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888"))
|
.And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
@ -238,7 +245,9 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_fix_issue_240()
|
public void should_fix_issue_240()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
int port = 61071;
|
||||||
|
|
||||||
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
{
|
{
|
||||||
@ -250,7 +259,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51876,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = "http",
|
DownstreamScheme = "http",
|
||||||
@ -284,7 +293,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt, users))
|
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt, users))
|
||||||
.And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", 200, "Hello from Laura"))
|
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
|
.And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
|
||||||
@ -297,23 +306,11 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody)
|
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_servicebuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
context.Response.StatusCode = statusCode;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
await context.Response.WriteAsync(responseBody);
|
||||||
.UseIISIntegration()
|
});
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.Run(async context =>
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_servicebuilder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAnIdentityServerOn(string url, string apiName, AccessTokenType tokenType)
|
private void GivenThereIsAnIdentityServerOn(string url, string apiName, AccessTokenType tokenType)
|
||||||
@ -465,7 +462,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_servicebuilder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
_identityServerBuilder?.Dispose();
|
_identityServerBuilder?.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Threading;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class CachingTests : IDisposable
|
public class CachingTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public CachingTests()
|
public CachingTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,38 +199,26 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenTheServiceNowReturns(string url, int statusCode, string responseBody)
|
private void GivenTheServiceNowReturns(string url, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builder.Dispose();
|
_serviceHandler.Dispose();
|
||||||
GivenThereIsAServiceRunningOn(url, statusCode, responseBody, null, null);
|
GivenThereIsAServiceRunningOn(url, statusCode, responseBody, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody, string key, string value)
|
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody, string key, string value)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(key))
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
context.Response.Headers.Add(key, value);
|
||||||
{
|
}
|
||||||
if(!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(key))
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(responseBody);
|
||||||
context.Response.Headers.Add(key, value);
|
});
|
||||||
}
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class CaseSensitiveRoutingTests : IDisposable
|
public class CaseSensitiveRoutingTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public CaseSensitiveRoutingTests()
|
public CaseSensitiveRoutingTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,29 +224,16 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
context.Response.StatusCode = statusCode;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
await context.Response.WriteAsync(responseBody);
|
||||||
.UseIISIntegration()
|
});
|
||||||
.UseUrls(baseUrl)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.UsePathBase(basePath);
|
|
||||||
app.Run(async context =>
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,35 @@
|
|||||||
using System;
|
using Xunit;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using IdentityServer4.AccessTokenValidation;
|
|
||||||
using IdentityServer4.Models;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
using IdentityServer4;
|
|
||||||
using IdentityServer4.Test;
|
using IdentityServer4.Test;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using IdentityServer4.AccessTokenValidation;
|
||||||
|
using IdentityServer4.Models;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
|
||||||
public class ClaimsToHeadersForwardingTests : IDisposable
|
public class ClaimsToHeadersForwardingTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _servicebuilder;
|
|
||||||
private IWebHost _identityServerBuilder;
|
private IWebHost _identityServerBuilder;
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private Action<IdentityServerAuthenticationOptions> _options;
|
private Action<IdentityServerAuthenticationOptions> _options;
|
||||||
private string _identityServerRootUrl = "http://localhost:52888";
|
private string _identityServerRootUrl = "http://localhost:52888";
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public ClaimsToHeadersForwardingTests()
|
public ClaimsToHeadersForwardingTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
_options = o =>
|
_options = o =>
|
||||||
{
|
{
|
||||||
@ -107,29 +107,17 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string url, int statusCode)
|
private void GivenThereIsAServiceRunningOn(string url, int statusCode)
|
||||||
{
|
{
|
||||||
_servicebuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
var customerId = context.Request.Headers.First(x => x.Key == "CustomerId").Value.First();
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
var locationId = context.Request.Headers.First(x => x.Key == "LocationId").Value.First();
|
||||||
.UseIISIntegration()
|
var userType = context.Request.Headers.First(x => x.Key == "UserType").Value.First();
|
||||||
.UseUrls(url)
|
var userId = context.Request.Headers.First(x => x.Key == "UserId").Value.First();
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.Run(async context =>
|
|
||||||
{
|
|
||||||
var customerId = context.Request.Headers.First(x => x.Key == "CustomerId").Value.First();
|
|
||||||
var locationId = context.Request.Headers.First(x => x.Key == "LocationId").Value.First();
|
|
||||||
var userType = context.Request.Headers.First(x => x.Key == "UserType").Value.First();
|
|
||||||
var userId = context.Request.Headers.First(x => x.Key == "UserId").Value.First();
|
|
||||||
|
|
||||||
var responseBody = $"CustomerId: {customerId} LocationId: {locationId} UserType: {userType} UserId: {userId}";
|
var responseBody = $"CustomerId: {customerId} LocationId: {locationId} UserType: {userType} UserId: {userId}";
|
||||||
context.Response.StatusCode = statusCode;
|
context.Response.StatusCode = statusCode;
|
||||||
await context.Response.WriteAsync(responseBody);
|
await context.Response.WriteAsync(responseBody);
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_servicebuilder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAnIdentityServerOn(string url, string apiName, AccessTokenType tokenType, TestUser user)
|
private void GivenThereIsAnIdentityServerOn(string url, string apiName, AccessTokenType tokenType, TestUser user)
|
||||||
@ -203,7 +191,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_servicebuilder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
_identityServerBuilder?.Dispose();
|
_identityServerBuilder?.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,25 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
namespace Ocelot.AcceptanceTests
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
|
||||||
{
|
{
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class ClientRateLimitTests : IDisposable
|
public class ClientRateLimitTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private int _counterOne;
|
private int _counterOne;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public ClientRateLimitTests()
|
public ClientRateLimitTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_builder?.Dispose();
|
|
||||||
_steps.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_call_withratelimiting()
|
public void should_call_withratelimiting()
|
||||||
{
|
{
|
||||||
@ -158,6 +147,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_call_middleware_withWhitelistClient()
|
public void should_call_middleware_withWhitelistClient()
|
||||||
{
|
{
|
||||||
|
int port = 61876;
|
||||||
|
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
@ -170,7 +161,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51876,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DownstreamScheme = "http",
|
DownstreamScheme = "http",
|
||||||
@ -201,7 +192,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", "/api/ClientRateLimit"))
|
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/ClientRateLimit"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning())
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
.When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 4))
|
.When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 4))
|
||||||
@ -211,26 +202,18 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_counterOne++;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
context.Response.StatusCode = 200;
|
||||||
.UseIISIntegration()
|
context.Response.WriteAsync(_counterOne.ToString());
|
||||||
.UseUrls(baseUrl)
|
return Task.CompletedTask;
|
||||||
.Configure(app =>
|
});
|
||||||
{
|
}
|
||||||
app.UsePathBase(basePath);
|
|
||||||
app.Run(context =>
|
|
||||||
{
|
|
||||||
_counterOne++;
|
|
||||||
context.Response.StatusCode = 200;
|
|
||||||
context.Response.WriteAsync(_counterOne.ToString());
|
|
||||||
return Task.CompletedTask;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,25 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using Shouldly;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class ContentTests : IDisposable
|
public class ContentTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private string _contentType;
|
private string _contentType;
|
||||||
private long? _contentLength;
|
private long? _contentLength;
|
||||||
private bool _contentTypeHeaderExists;
|
private bool _contentTypeHeaderExists;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public ContentTests()
|
public ContentTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,30 +158,19 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_contentType = context.Request.ContentType;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
_contentLength = context.Request.ContentLength;
|
||||||
.UseIISIntegration()
|
_contentTypeHeaderExists = context.Request.Headers.TryGetValue("Content-Type", out var value);
|
||||||
.Configure(app =>
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(responseBody);
|
||||||
app.UsePathBase(basePath);
|
});
|
||||||
app.Run(async context =>
|
|
||||||
{
|
|
||||||
_contentType = context.Request.ContentType;
|
|
||||||
_contentLength = context.Request.ContentLength;
|
|
||||||
_contentTypeHeaderExists = context.Request.Headers.TryGetValue("Content-Type", out var value);
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,27 @@
|
|||||||
using System;
|
namespace Ocelot.AcceptanceTests
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Ocelot.Middleware;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using Ocelot.Middleware;
|
||||||
|
using Shouldly;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class CustomMiddlewareTests : IDisposable
|
public class CustomMiddlewareTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly string _configurationPath;
|
private readonly string _configurationPath;
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private int _counter;
|
private int _counter;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public CustomMiddlewareTests()
|
public CustomMiddlewareTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_counter = 0;
|
_counter = 0;
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
_configurationPath = "ocelot.json";
|
_configurationPath = "ocelot.json";
|
||||||
@ -340,37 +338,24 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string basePath)
|
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string basePath)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
if (string.IsNullOrEmpty(basePath))
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(context =>
|
}
|
||||||
{
|
else if (context.Request.Path.Value != basePath)
|
||||||
if(string.IsNullOrEmpty(basePath))
|
{
|
||||||
{
|
context.Response.StatusCode = 404;
|
||||||
context.Response.StatusCode = statusCode;
|
}
|
||||||
}
|
|
||||||
else if(context.Request.Path.Value != basePath)
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = 404;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,29 +1,25 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.IO.Compression;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Text;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using Shouldly;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class GzipTests : IDisposable
|
public class GzipTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public GzipTests()
|
public GzipTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,51 +62,40 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, string expected)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, string expected)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
if (context.Request.Headers.TryGetValue("Content-Encoding", out var contentEncoding))
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
contentEncoding.First().ShouldBe("gzip");
|
||||||
app.Run(async context =>
|
|
||||||
|
string text = null;
|
||||||
|
using (var decompress = new GZipStream(context.Request.Body, CompressionMode.Decompress))
|
||||||
{
|
{
|
||||||
if(context.Request.Headers.TryGetValue("Content-Encoding", out var contentEncoding))
|
using (var sr = new StreamReader(decompress))
|
||||||
{
|
{
|
||||||
contentEncoding.First().ShouldBe("gzip");
|
text = sr.ReadToEnd();
|
||||||
|
|
||||||
string text = null;
|
|
||||||
using (var decompress = new GZipStream(context.Request.Body, CompressionMode.Decompress))
|
|
||||||
{
|
|
||||||
using (var sr = new StreamReader(decompress)) {
|
|
||||||
text = sr.ReadToEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(text != expected)
|
|
||||||
{
|
|
||||||
throw new Exception("not gzipped");
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
if (text != expected)
|
||||||
|
{
|
||||||
|
throw new Exception("not gzipped");
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Response.StatusCode = statusCode;
|
||||||
|
await context.Response.WriteAsync(responseBody);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = statusCode;
|
||||||
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,24 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class HeaderTests : IDisposable
|
public class HeaderTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private int _count;
|
private int _count;
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public HeaderTests()
|
public HeaderTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,97 +385,61 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
if (_count == 0)
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.Cookies.Append("test", "0");
|
||||||
app.Run(context =>
|
_count++;
|
||||||
|
context.Response.StatusCode = statusCode;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.Request.Cookies.TryGetValue("test", out var cookieValue) || context.Request.Headers.TryGetValue("Set-Cookie", out var headerValue))
|
||||||
|
{
|
||||||
|
if (cookieValue == "0" || headerValue == "test=1; path=/")
|
||||||
{
|
{
|
||||||
if (_count == 0)
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
|
||||||
context.Response.Cookies.Append("test", "0");
|
|
||||||
_count++;
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.Request.Cookies.TryGetValue("test", out var cookieValue) || context.Request.Headers.TryGetValue("Set-Cookie", out var headerValue))
|
|
||||||
{
|
|
||||||
if (cookieValue == "0" || headerValue == "test=1; path=/")
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Response.StatusCode = 500;
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
});
|
}
|
||||||
})
|
}
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
context.Response.StatusCode = 500;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string headerKey)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string headerKey)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
if (context.Request.Headers.TryGetValue(headerKey, out var values))
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
var result = values.First();
|
||||||
app.Run(async context =>
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(result);
|
||||||
if (context.Request.Headers.TryGetValue(headerKey, out var values))
|
}
|
||||||
{
|
});
|
||||||
var result = values.First();
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string headerKey, string headerValue)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string headerKey, string headerValue)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
context.Response.OnStarting(() =>
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.Headers.Add(headerKey, headerValue);
|
||||||
app.Run(context =>
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
return Task.CompletedTask;
|
||||||
context.Response.OnStarting(() =>
|
});
|
||||||
{
|
|
||||||
context.Response.Headers.Add(headerKey, headerValue);
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
return Task.CompletedTask;
|
|
||||||
});
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,26 @@
|
|||||||
using System;
|
namespace Ocelot.AcceptanceTests
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
|
||||||
{
|
{
|
||||||
public class HttpDelegatingHandlersTests
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using Shouldly;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
public class HttpDelegatingHandlersTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private string _downstreamPath;
|
private string _downstreamPath;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public HttpDelegatingHandlersTests()
|
public HttpDelegatingHandlersTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,6 +247,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
return base.SendAsync(request, cancellationToken);
|
return base.SendAsync(request, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once ClassNeverInstantiated.Local
|
// ReSharper disable once ClassNeverInstantiated.Local
|
||||||
private class FakeHandlerAgain : DelegatingHandler
|
private class FakeHandlerAgain : DelegatingHandler
|
||||||
{
|
{
|
||||||
@ -263,33 +262,27 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
if (_downstreamPath != basePath)
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
{
|
}
|
||||||
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
else
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = statusCode;
|
||||||
|
await context.Response.WriteAsync(responseBody);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (_downstreamPath != basePath)
|
public void Dispose()
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = statusCode;
|
_steps?.Dispose();
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
_serviceHandler?.Dispose();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Ocelot.LoadBalancer.LoadBalancers;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using Ocelot.LoadBalancer.LoadBalancers;
|
||||||
|
using Shouldly;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class LoadBalancerTests : IDisposable
|
public class LoadBalancerTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builderOne;
|
|
||||||
private IWebHost _builderTwo;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private int _counterOne;
|
private int _counterOne;
|
||||||
private int _counterTwo;
|
private int _counterTwo;
|
||||||
private static readonly object _syncLock = new object();
|
private static readonly object _syncLock = new object();
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public LoadBalancerTests()
|
public LoadBalancerTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_load_balance_request_with_least_connection()
|
public void should_load_balance_request_with_least_connection()
|
||||||
{
|
{
|
||||||
var downstreamServiceOneUrl = "http://localhost:50881";
|
int portOne = 50591;
|
||||||
var downstreamServiceTwoUrl = "http://localhost:50892";
|
int portTwo = 51482;
|
||||||
|
|
||||||
|
var downstreamServiceOneUrl = $"http://localhost:{portOne}";
|
||||||
|
var downstreamServiceTwoUrl = $"http://localhost:{portTwo}";
|
||||||
|
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
@ -48,12 +48,12 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 50881
|
Port = portOne
|
||||||
},
|
},
|
||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 50892
|
Port = portTwo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,8 +76,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_load_balance_request_with_round_robin()
|
public void should_load_balance_request_with_round_robin()
|
||||||
{
|
{
|
||||||
var downstreamPortOne = 51881;
|
var downstreamPortOne = 51701;
|
||||||
var downstreamPortTwo = 51892;
|
var downstreamPortTwo = 53802;
|
||||||
var downstreamServiceOneUrl = $"http://localhost:{downstreamPortOne}";
|
var downstreamServiceOneUrl = $"http://localhost:{downstreamPortOne}";
|
||||||
var downstreamServiceTwoUrl = $"http://localhost:{downstreamPortTwo}";
|
var downstreamServiceTwoUrl = $"http://localhost:{downstreamPortTwo}";
|
||||||
|
|
||||||
@ -136,77 +136,53 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenProductServiceOneIsRunning(string url, int statusCode)
|
private void GivenProductServiceOneIsRunning(string url, int statusCode)
|
||||||
{
|
{
|
||||||
_builderOne = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
try
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
var response = string.Empty;
|
||||||
|
lock (_syncLock)
|
||||||
{
|
{
|
||||||
try
|
_counterOne++;
|
||||||
{
|
response = _counterOne.ToString();
|
||||||
var response = string.Empty;
|
}
|
||||||
lock (_syncLock)
|
|
||||||
{
|
|
||||||
_counterOne++;
|
|
||||||
response = _counterOne.ToString();
|
|
||||||
}
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(response);
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
await context.Response.WriteAsync(exception.StackTrace);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builderOne.Start();
|
context.Response.StatusCode = statusCode;
|
||||||
|
await context.Response.WriteAsync(response);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
await context.Response.WriteAsync(exception.StackTrace);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenProductServiceTwoIsRunning(string url, int statusCode)
|
private void GivenProductServiceTwoIsRunning(string url, int statusCode)
|
||||||
{
|
{
|
||||||
_builderTwo = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
try
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
var response = string.Empty;
|
||||||
|
lock (_syncLock)
|
||||||
{
|
{
|
||||||
try
|
_counterTwo++;
|
||||||
{
|
response = _counterTwo.ToString();
|
||||||
var response = string.Empty;
|
}
|
||||||
lock (_syncLock)
|
|
||||||
{
|
|
||||||
_counterTwo++;
|
|
||||||
response = _counterTwo.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Response.StatusCode = statusCode;
|
context.Response.StatusCode = statusCode;
|
||||||
await context.Response.WriteAsync(response);
|
await context.Response.WriteAsync(response);
|
||||||
}
|
}
|
||||||
catch (System.Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
await context.Response.WriteAsync(exception.StackTrace);
|
await context.Response.WriteAsync(exception.StackTrace);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builderTwo.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builderOne?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_builderTwo?.Dispose();
|
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,24 @@
|
|||||||
using System;
|
namespace Ocelot.AcceptanceTests
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class QoSTests : IDisposable
|
public class QoSTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _brokenService;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private int _requestCount;
|
private int _requestCount;
|
||||||
private IWebHost _workingService;
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public QoSTests()
|
public QoSTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,74 +224,48 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAPossiblyBrokenServiceRunningOn(string url, string responseBody)
|
private void GivenThereIsAPossiblyBrokenServiceRunningOn(string url, string responseBody)
|
||||||
{
|
{
|
||||||
_brokenService = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
//circuit starts closed
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
if (_requestCount == 0)
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
_requestCount++;
|
||||||
{
|
context.Response.StatusCode = 200;
|
||||||
//circuit starts closed
|
await context.Response.WriteAsync(responseBody);
|
||||||
if (_requestCount == 0)
|
return;
|
||||||
{
|
}
|
||||||
_requestCount++;
|
|
||||||
context.Response.StatusCode = 200;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//request one times out and polly throws exception, circuit opens
|
//request one times out and polly throws exception, circuit opens
|
||||||
if (_requestCount == 1)
|
if (_requestCount == 1)
|
||||||
{
|
{
|
||||||
_requestCount++;
|
_requestCount++;
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
context.Response.StatusCode = 200;
|
context.Response.StatusCode = 200;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//after break closes we return 200 OK
|
//after break closes we return 200 OK
|
||||||
if (_requestCount == 2)
|
if (_requestCount == 2)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 200;
|
context.Response.StatusCode = 200;
|
||||||
await context.Response.WriteAsync(responseBody);
|
await context.Response.WriteAsync(responseBody);
|
||||||
return;
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_brokenService.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody, int timeout)
|
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody, int timeout)
|
||||||
{
|
{
|
||||||
_workingService = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
Thread.Sleep(timeout);
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
context.Response.StatusCode = statusCode;
|
||||||
.UseIISIntegration()
|
await context.Response.WriteAsync(responseBody);
|
||||||
.UseUrls(url)
|
});
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.Run(async context =>
|
|
||||||
{
|
|
||||||
Thread.Sleep(timeout);
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_workingService.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_workingService?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_brokenService?.Dispose();
|
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,21 @@
|
|||||||
using System;
|
namespace Ocelot.AcceptanceTests
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Extensions.Primitives;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class RequestIdTests : IDisposable
|
public class RequestIdTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public RequestIdTests()
|
public RequestIdTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,30 +166,17 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string url)
|
private void GivenThereIsAServiceRunningOn(string url)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
context.Request.Headers.TryGetValue(_steps.RequestIdKey, out var requestId);
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
context.Response.Headers.Add(_steps.RequestIdKey, requestId.First());
|
||||||
.UseIISIntegration()
|
return Task.CompletedTask;
|
||||||
.UseUrls(url)
|
});
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.Run(context =>
|
|
||||||
{
|
|
||||||
StringValues requestId;
|
|
||||||
context.Request.Headers.TryGetValue(_steps.RequestIdKey, out requestId);
|
|
||||||
context.Response.Headers.Add(_steps.RequestIdKey, requestId.First());
|
|
||||||
return Task.CompletedTask;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,20 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class ResponseCodeTests : IDisposable
|
public class ResponseCodeTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private string _downstreamPath;
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public ResponseCodeTests()
|
public ResponseCodeTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,26 +53,15 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
context.Response.StatusCode = statusCode;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
});
|
||||||
.UseIISIntegration()
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.UsePathBase(basePath);
|
|
||||||
app.Run(async context =>
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
using System;
|
namespace Ocelot.AcceptanceTests
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class ReturnsErrorTests : IDisposable
|
public class ReturnsErrorTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _servicebuilder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public ReturnsErrorTests()
|
public ReturnsErrorTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,27 +53,12 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string url)
|
private void GivenThereIsAServiceRunningOn(string url)
|
||||||
{
|
{
|
||||||
_servicebuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, context => throw new Exception("BLAMMMM"));
|
||||||
.UseUrls(url)
|
|
||||||
.UseKestrel()
|
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.Run(context =>
|
|
||||||
{
|
|
||||||
throw new Exception("BLAMMMM");
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_servicebuilder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_servicebuilder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using Shouldly;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class RoutingTests : IDisposable
|
public class RoutingTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private string _downstreamPath;
|
private string _downstreamPath;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public RoutingTests()
|
public RoutingTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,33 +971,21 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
if (_downstreamPath != basePath)
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
{
|
}
|
||||||
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
else
|
||||||
|
{
|
||||||
if(_downstreamPath != basePath)
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(responseBody);
|
||||||
context.Response.StatusCode = statusCode;
|
}
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ThenTheDownstreamUrlPathShouldBe(string expectedDownstreamPath)
|
internal void ThenTheDownstreamUrlPathShouldBe(string expectedDownstreamPath)
|
||||||
@ -1009,7 +995,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,21 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class RoutingWithQueryStringTests : IDisposable
|
public class RoutingWithQueryStringTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private string _downstreamPath;
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public RoutingWithQueryStringTests()
|
public RoutingWithQueryStringTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,41 +204,24 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, string queryString, int statusCode, string responseBody)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, string queryString, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
if (context.Request.PathBase.Value != basePath || context.Request.QueryString.Value != queryString)
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = 500;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
{
|
}
|
||||||
if(context.Request.PathBase.Value != basePath || context.Request.QueryString.Value != queryString)
|
else
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 500;
|
context.Response.StatusCode = statusCode;
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
await context.Response.WriteAsync(responseBody);
|
||||||
}
|
}
|
||||||
else
|
});
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ThenTheDownstreamUrlPathShouldBe(string expectedDownstreamPath)
|
|
||||||
{
|
|
||||||
_downstreamPath.ShouldBe(expectedDownstreamPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,9 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Consul;
|
using Consul;
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Ocelot.Configuration.File;
|
using Ocelot.Configuration.File;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
@ -18,21 +15,19 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
public class ServiceDiscoveryTests : IDisposable
|
public class ServiceDiscoveryTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builderOne;
|
|
||||||
private IWebHost _builderTwo;
|
|
||||||
private IWebHost _fakeConsulBuilder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private readonly List<ServiceEntry> _consulServices;
|
private readonly List<ServiceEntry> _consulServices;
|
||||||
private readonly List<IServiceInstance> _eurekaInstances;
|
private readonly List<IServiceInstance> _eurekaInstances;
|
||||||
private int _counterOne;
|
private int _counterOne;
|
||||||
private int _counterTwo;
|
private int _counterTwo;
|
||||||
private static readonly object SyncLock = new object();
|
private static readonly object SyncLock = new object();
|
||||||
private IWebHost _builder;
|
|
||||||
private string _downstreamPath;
|
private string _downstreamPath;
|
||||||
private string _receivedToken;
|
private string _receivedToken;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public ServiceDiscoveryTests()
|
public ServiceDiscoveryTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
_consulServices = new List<ServiceEntry>();
|
_consulServices = new List<ServiceEntry>();
|
||||||
_eurekaInstances = new List<IServiceInstance>();
|
_eurekaInstances = new List<IServiceInstance>();
|
||||||
@ -74,7 +69,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenEurekaProductServiceOneIsRunning(downstreamServiceOneUrl, 200))
|
this.Given(x => x.GivenEurekaProductServiceOneIsRunning(downstreamServiceOneUrl))
|
||||||
.And(x => x.GivenThereIsAFakeEurekaServiceDiscoveryProvider(fakeEurekaServiceDiscoveryUrl, serviceName))
|
.And(x => x.GivenThereIsAFakeEurekaServiceDiscoveryProvider(fakeEurekaServiceDiscoveryUrl, serviceName))
|
||||||
.And(x => x.GivenTheServicesAreRegisteredWithEureka(instanceOne))
|
.And(x => x.GivenTheServicesAreRegisteredWithEureka(instanceOne))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
@ -568,26 +563,18 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAFakeEurekaServiceDiscoveryProvider(string url, string serviceName)
|
private void GivenThereIsAFakeEurekaServiceDiscoveryProvider(string url, string serviceName)
|
||||||
{
|
{
|
||||||
_fakeConsulBuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
if (context.Request.Path.Value == "/eureka/apps/")
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
var apps = new List<Application>();
|
||||||
{
|
|
||||||
if (context.Request.Path.Value == "/eureka/apps/")
|
|
||||||
{
|
|
||||||
var apps = new List<Application>();
|
|
||||||
|
|
||||||
foreach (var serviceInstance in _eurekaInstances)
|
foreach (var serviceInstance in _eurekaInstances)
|
||||||
{
|
{
|
||||||
var a = new Application
|
var a = new Application
|
||||||
{
|
{
|
||||||
name = serviceName,
|
name = serviceName,
|
||||||
instance = new List<Instance>
|
instance = new List<Instance>
|
||||||
{
|
{
|
||||||
new Instance
|
new Instance
|
||||||
{
|
{
|
||||||
@ -624,190 +611,126 @@ namespace Ocelot.AcceptanceTests
|
|||||||
actionType = "ADDED"
|
actionType = "ADDED"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
apps.Add(a);
|
apps.Add(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
var applications = new EurekaApplications
|
var applications = new EurekaApplications
|
||||||
{
|
{
|
||||||
applications = new Applications
|
applications = new Applications
|
||||||
{
|
{
|
||||||
application = apps,
|
application = apps,
|
||||||
apps__hashcode = "UP_1_",
|
apps__hashcode = "UP_1_",
|
||||||
versions__delta = "1"
|
versions__delta = "1"
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
await context.Response.WriteJsonAsync(applications);
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_fakeConsulBuilder.Start();
|
await context.Response.WriteJsonAsync(applications);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string serviceName)
|
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string serviceName)
|
||||||
{
|
{
|
||||||
_fakeConsulBuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
if (context.Request.Path.Value == $"/v1/health/service/{serviceName}")
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
{
|
||||||
.UseIISIntegration()
|
if (context.Request.Headers.TryGetValue("X-Consul-Token", out var values))
|
||||||
.UseUrls(url)
|
{
|
||||||
.Configure(app =>
|
_receivedToken = values.First();
|
||||||
{
|
}
|
||||||
app.Run(async context =>
|
|
||||||
{
|
|
||||||
if(context.Request.Path.Value == $"/v1/health/service/{serviceName}")
|
|
||||||
{
|
|
||||||
if (context.Request.Headers.TryGetValue("X-Consul-Token", out var values))
|
|
||||||
{
|
|
||||||
_receivedToken = values.First();
|
|
||||||
}
|
|
||||||
|
|
||||||
await context.Response.WriteJsonAsync(_consulServices);
|
await context.Response.WriteJsonAsync(_consulServices);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_fakeConsulBuilder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenProductServiceOneIsRunning(string url, int statusCode)
|
private void GivenProductServiceOneIsRunning(string url, int statusCode)
|
||||||
{
|
{
|
||||||
_builderOne = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
try
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
string response;
|
||||||
|
lock (SyncLock)
|
||||||
{
|
{
|
||||||
try
|
_counterOne++;
|
||||||
{
|
response = _counterOne.ToString();
|
||||||
string response;
|
}
|
||||||
lock (SyncLock)
|
|
||||||
{
|
|
||||||
_counterOne++;
|
|
||||||
response = _counterOne.ToString();
|
|
||||||
}
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(response);
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
await context.Response.WriteAsync(exception.StackTrace);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builderOne.Start();
|
context.Response.StatusCode = statusCode;
|
||||||
|
await context.Response.WriteAsync(response);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
await context.Response.WriteAsync(exception.StackTrace);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenProductServiceTwoIsRunning(string url, int statusCode)
|
private void GivenProductServiceTwoIsRunning(string url, int statusCode)
|
||||||
{
|
{
|
||||||
_builderTwo = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
try
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
string response;
|
||||||
|
lock (SyncLock)
|
||||||
{
|
{
|
||||||
try
|
_counterTwo++;
|
||||||
{
|
response = _counterTwo.ToString();
|
||||||
string response;
|
}
|
||||||
lock (SyncLock)
|
|
||||||
{
|
|
||||||
_counterTwo++;
|
|
||||||
response = _counterTwo.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Response.StatusCode = statusCode;
|
context.Response.StatusCode = statusCode;
|
||||||
await context.Response.WriteAsync(response);
|
await context.Response.WriteAsync(response);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
await context.Response.WriteAsync(exception.StackTrace);
|
await context.Response.WriteAsync(exception.StackTrace);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builderTwo.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenEurekaProductServiceOneIsRunning(string url, int statusCode)
|
private void GivenEurekaProductServiceOneIsRunning(string url)
|
||||||
{
|
{
|
||||||
_builderOne = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
try
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
context.Response.StatusCode = 200;
|
||||||
{
|
await context.Response.WriteAsync(nameof(ServiceDiscoveryTests));
|
||||||
try
|
}
|
||||||
{
|
catch (Exception exception)
|
||||||
context.Response.StatusCode = 200;
|
{
|
||||||
await context.Response.WriteAsync(nameof(ServiceDiscoveryTests));
|
await context.Response.WriteAsync(exception.StackTrace);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
});
|
||||||
{
|
|
||||||
await context.Response.WriteAsync(exception.StackTrace);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builderOne.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
if (_downstreamPath != basePath)
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
{
|
}
|
||||||
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
else
|
||||||
|
{
|
||||||
if(_downstreamPath != basePath)
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(responseBody);
|
||||||
context.Response.StatusCode = statusCode;
|
}
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builderOne?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_builderTwo?.Dispose();
|
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,22 @@
|
|||||||
using System.Linq;
|
|
||||||
using Microsoft.Extensions.Primitives;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Ocelot.Configuration.File;
|
using Ocelot.Configuration.File;
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
public class ServiceFabricTests : IDisposable
|
public class ServiceFabricTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private string _downstreamPath;
|
private string _downstreamPath;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public ServiceFabricTests()
|
public ServiceFabricTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,46 +96,34 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, string expectedQueryString)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, string expectedQueryString)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
if (_downstreamPath != basePath)
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (context.Request.QueryString.Value.Contains(expectedQueryString))
|
||||||
{
|
{
|
||||||
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
context.Response.StatusCode = statusCode;
|
||||||
|
await context.Response.WriteAsync(responseBody);
|
||||||
if(_downstreamPath != basePath)
|
}
|
||||||
{
|
else
|
||||||
context.Response.StatusCode = statusCode;
|
{
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
context.Response.StatusCode = statusCode;
|
||||||
}
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
if (context.Request.QueryString.Value.Contains(expectedQueryString))
|
});
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
108
test/Ocelot.AcceptanceTests/ServiceHandler.cs
Normal file
108
test/Ocelot.AcceptanceTests/ServiceHandler.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
namespace Ocelot.AcceptanceTests
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.WebSockets;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
public class ServiceHandler : IDisposable
|
||||||
|
{
|
||||||
|
private IWebHost _builder;
|
||||||
|
|
||||||
|
public void GivenThereIsAServiceRunningOn(string baseUrl, RequestDelegate del)
|
||||||
|
{
|
||||||
|
_builder = new WebHostBuilder()
|
||||||
|
.UseUrls(baseUrl)
|
||||||
|
.UseKestrel()
|
||||||
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
.UseIISIntegration()
|
||||||
|
.Configure(app =>
|
||||||
|
{
|
||||||
|
app.Run(del);
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_builder.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, RequestDelegate del)
|
||||||
|
{
|
||||||
|
_builder = new WebHostBuilder()
|
||||||
|
.UseUrls(baseUrl)
|
||||||
|
.UseKestrel()
|
||||||
|
.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()
|
||||||
|
.UseUrls(baseUrl)
|
||||||
|
.UseKestrel(options =>
|
||||||
|
{
|
||||||
|
options.Listen(IPAddress.Loopback, port, listenOptions =>
|
||||||
|
{
|
||||||
|
listenOptions.UseHttps(fileName, password);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
.Configure(app =>
|
||||||
|
{
|
||||||
|
app.UsePathBase(basePath);
|
||||||
|
app.Run(del);
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_builder.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task StartFakeDownstreamService(string url, string path, Func<HttpContext, Func<Task>, Task> middleware)
|
||||||
|
{
|
||||||
|
_builder = new WebHostBuilder()
|
||||||
|
.ConfigureServices(s => { }).UseKestrel()
|
||||||
|
.UseUrls(url)
|
||||||
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
.ConfigureAppConfiguration((hostingContext, config) =>
|
||||||
|
{
|
||||||
|
config.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath);
|
||||||
|
var env = hostingContext.HostingEnvironment;
|
||||||
|
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
||||||
|
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: false);
|
||||||
|
config.AddEnvironmentVariables();
|
||||||
|
})
|
||||||
|
.ConfigureLogging((hostingContext, logging) =>
|
||||||
|
{
|
||||||
|
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
||||||
|
logging.AddConsole();
|
||||||
|
})
|
||||||
|
.Configure(app =>
|
||||||
|
{
|
||||||
|
app.UseWebSockets();
|
||||||
|
app.Use(middleware);
|
||||||
|
})
|
||||||
|
.UseIISIntegration()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
await _builder.StartAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_builder?.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,25 +1,22 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class SslTests : IDisposable
|
public class SslTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private string _downstreamPath;
|
private string _downstreamPath;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public SslTests()
|
public SslTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,48 +95,26 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, int port)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, int port)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, "idsrv3test.pfx", "idsrv3test", port, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel(options =>
|
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||||
|
|
||||||
|
if (_downstreamPath != basePath)
|
||||||
{
|
{
|
||||||
options.Listen(IPAddress.Loopback, port, listenOptions =>
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
listenOptions.UseHttps("idsrv3test.pfx", "idsrv3test");
|
}
|
||||||
});
|
else
|
||||||
})
|
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync(responseBody);
|
||||||
{
|
}
|
||||||
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
});
|
||||||
|
|
||||||
if(_downstreamPath != basePath)
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ThenTheDownstreamUrlPathShouldBe(string expectedDownstreamPath)
|
|
||||||
{
|
|
||||||
_downstreamPath.ShouldBe(expectedDownstreamPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,31 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using Shouldly;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class StickySessionsTests : IDisposable
|
public class StickySessionsTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builderOne;
|
|
||||||
private IWebHost _builderTwo;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private int _counterOne;
|
private int _counterOne;
|
||||||
private int _counterTwo;
|
private int _counterTwo;
|
||||||
private static readonly object _syncLock = new object();
|
private static readonly object SyncLock = new object();
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public StickySessionsTests()
|
public StickySessionsTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_use_same_downstream_host()
|
public void should_use_same_downstream_host()
|
||||||
{
|
{
|
||||||
var downstreamPortOne = 51881;
|
var downstreamPortOne = 51375;
|
||||||
var downstreamPortTwo = 51892;
|
var downstreamPortTwo = 51892;
|
||||||
var downstreamServiceOneUrl = $"http://localhost:{downstreamPortOne}";
|
var downstreamServiceOneUrl = $"http://localhost:{downstreamPortOne}";
|
||||||
var downstreamServiceTwoUrl = $"http://localhost:{downstreamPortTwo}";
|
var downstreamServiceTwoUrl = $"http://localhost:{downstreamPortTwo}";
|
||||||
@ -244,77 +241,52 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenProductServiceOneIsRunning(string url, int statusCode)
|
private void GivenProductServiceOneIsRunning(string url, int statusCode)
|
||||||
{
|
{
|
||||||
_builderOne = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
try
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
var response = string.Empty;
|
||||||
|
lock (SyncLock)
|
||||||
{
|
{
|
||||||
try
|
_counterOne++;
|
||||||
{
|
response = _counterOne.ToString();
|
||||||
var response = string.Empty;
|
}
|
||||||
lock (_syncLock)
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(response);
|
||||||
_counterOne++;
|
}
|
||||||
response = _counterOne.ToString();
|
catch (Exception exception)
|
||||||
}
|
{
|
||||||
context.Response.StatusCode = statusCode;
|
await context.Response.WriteAsync(exception.StackTrace);
|
||||||
await context.Response.WriteAsync(response);
|
}
|
||||||
}
|
});
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
await context.Response.WriteAsync(exception.StackTrace);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builderOne.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenProductServiceTwoIsRunning(string url, int statusCode)
|
private void GivenProductServiceTwoIsRunning(string url, int statusCode)
|
||||||
{
|
{
|
||||||
_builderTwo = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
try
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
var response = string.Empty;
|
||||||
|
lock (SyncLock)
|
||||||
{
|
{
|
||||||
try
|
_counterTwo++;
|
||||||
{
|
response = _counterTwo.ToString();
|
||||||
var response = string.Empty;
|
}
|
||||||
lock (_syncLock)
|
|
||||||
{
|
|
||||||
_counterTwo++;
|
|
||||||
response = _counterTwo.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Response.StatusCode = statusCode;
|
context.Response.StatusCode = statusCode;
|
||||||
await context.Response.WriteAsync(response);
|
await context.Response.WriteAsync(response);
|
||||||
}
|
}
|
||||||
catch (System.Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
await context.Response.WriteAsync(exception.StackTrace);
|
await context.Response.WriteAsync(exception.StackTrace);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builderTwo.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builderOne?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_builderTwo?.Dispose();
|
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,25 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Consul;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using Consul;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class TwoDownstreamServicesTests : IDisposable
|
public class TwoDownstreamServicesTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builderOne;
|
|
||||||
private IWebHost _builderTwo;
|
|
||||||
private IWebHost _fakeConsulBuilder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private readonly List<ServiceEntry> _serviceEntries;
|
private readonly List<ServiceEntry> _serviceEntries;
|
||||||
private string _downstreamPathOne;
|
private string _downstreamPathOne;
|
||||||
private string _downstreamPathTwo;
|
private string _downstreamPathTwo;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public TwoDownstreamServicesTests()
|
public TwoDownstreamServicesTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
_serviceEntries = new List<ServiceEntry>();
|
_serviceEntries = new List<ServiceEntry>();
|
||||||
}
|
}
|
||||||
@ -98,93 +93,58 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url)
|
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url)
|
||||||
{
|
{
|
||||||
_fakeConsulBuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
if (context.Request.Path.Value == "/v1/health/service/product")
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
{
|
||||||
.UseIISIntegration()
|
await context.Response.WriteJsonAsync(_serviceEntries);
|
||||||
.UseUrls(url)
|
}
|
||||||
.Configure(app =>
|
});
|
||||||
{
|
|
||||||
app.Run(async context =>
|
|
||||||
{
|
|
||||||
if(context.Request.Path.Value == "/v1/health/service/product")
|
|
||||||
{
|
|
||||||
await context.Response.WriteJsonAsync(_serviceEntries);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_fakeConsulBuilder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenProductServiceOneIsRunning(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenProductServiceOneIsRunning(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builderOne = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_downstreamPathOne = !string.IsNullOrEmpty(context.Request.PathBase.Value)
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
? context.Request.PathBase.Value
|
||||||
.UseIISIntegration()
|
: context.Request.Path.Value;
|
||||||
.Configure(app =>
|
|
||||||
|
if (_downstreamPathOne != basePath)
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
{
|
}
|
||||||
_downstreamPathOne = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
else
|
||||||
|
{
|
||||||
if(_downstreamPathOne != basePath)
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(responseBody);
|
||||||
context.Response.StatusCode = statusCode;
|
}
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builderOne.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenProductServiceTwoIsRunning(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenProductServiceTwoIsRunning(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builderTwo = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_downstreamPathTwo = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
if (_downstreamPathTwo != basePath)
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
{
|
}
|
||||||
_downstreamPathTwo = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
else
|
||||||
|
{
|
||||||
if(_downstreamPathTwo != basePath)
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(responseBody);
|
||||||
context.Response.StatusCode = statusCode;
|
}
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builderTwo.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builderOne?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_builderTwo?.Dispose();
|
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,30 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class UpstreamHostTests : IDisposable
|
public class UpstreamHostTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _builder;
|
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private string _downstreamPath;
|
private string _downstreamPath;
|
||||||
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public UpstreamHostTests()
|
public UpstreamHostTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_200_with_simple_url_and_hosts_match()
|
public void should_return_response_200_with_simple_url_and_hosts_match()
|
||||||
{
|
{
|
||||||
|
int port = 64905;
|
||||||
|
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
@ -39,7 +38,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51875,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UpstreamPathTemplate = "/",
|
UpstreamPathTemplate = "/",
|
||||||
@ -49,7 +48,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51875", "/", 200, "Hello from Laura"))
|
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning())
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||||
@ -61,6 +60,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes()
|
public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes()
|
||||||
{
|
{
|
||||||
|
int port = 64904;
|
||||||
|
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
@ -74,7 +75,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51875,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UpstreamPathTemplate = "/",
|
UpstreamPathTemplate = "/",
|
||||||
@ -100,7 +101,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51875", "/", 200, "Hello from Laura"))
|
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning())
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||||
@ -112,6 +113,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes_reversed()
|
public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes_reversed()
|
||||||
{
|
{
|
||||||
|
int port = 64903;
|
||||||
|
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
@ -141,7 +144,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51875,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UpstreamPathTemplate = "/",
|
UpstreamPathTemplate = "/",
|
||||||
@ -151,7 +154,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51875", "/", 200, "Hello from Laura"))
|
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning())
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||||
@ -163,6 +166,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes_reversed_with_no_host_first()
|
public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes_reversed_with_no_host_first()
|
||||||
{
|
{
|
||||||
|
int port = 64902;
|
||||||
|
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
@ -191,7 +196,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51875,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UpstreamPathTemplate = "/",
|
UpstreamPathTemplate = "/",
|
||||||
@ -201,7 +206,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51875", "/", 200, "Hello from Laura"))
|
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning())
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||||
@ -213,6 +218,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_response_404_with_simple_url_and_hosts_dont_match()
|
public void should_return_response_404_with_simple_url_and_hosts_dont_match()
|
||||||
{
|
{
|
||||||
|
int port = 64901;
|
||||||
|
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
{
|
{
|
||||||
ReRoutes = new List<FileReRoute>
|
ReRoutes = new List<FileReRoute>
|
||||||
@ -226,7 +233,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
new FileHostAndPort
|
new FileHostAndPort
|
||||||
{
|
{
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 51875,
|
Port = port,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UpstreamPathTemplate = "/",
|
UpstreamPathTemplate = "/",
|
||||||
@ -236,7 +243,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51875", "/", 200, "Hello from Laura"))
|
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
|
||||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||||
.And(x => _steps.GivenOcelotIsRunning())
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||||
@ -246,43 +253,26 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||||
.UseUrls(baseUrl)
|
{
|
||||||
.UseKestrel()
|
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
if (_downstreamPath != basePath)
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.UsePathBase(basePath);
|
context.Response.StatusCode = statusCode;
|
||||||
app.Run(async context =>
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||||
{
|
}
|
||||||
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
else
|
||||||
|
{
|
||||||
if(_downstreamPath != basePath)
|
context.Response.StatusCode = statusCode;
|
||||||
{
|
await context.Response.WriteAsync(responseBody);
|
||||||
context.Response.StatusCode = statusCode;
|
}
|
||||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = statusCode;
|
|
||||||
await context.Response.WriteAsync(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_builder.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ThenTheDownstreamUrlPathShouldBe(string expectedDownstreamPath)
|
|
||||||
{
|
|
||||||
_downstreamPath.ShouldBe(expectedDownstreamPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,29 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net.WebSockets;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Consul;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Ocelot.Configuration.File;
|
|
||||||
using Shouldly;
|
|
||||||
using TestStack.BDDfy;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ocelot.AcceptanceTests
|
namespace Ocelot.AcceptanceTests
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.WebSockets;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Consul;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
using Shouldly;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
public class WebSocketTests : IDisposable
|
public class WebSocketTests : IDisposable
|
||||||
{
|
{
|
||||||
private IWebHost _firstDownstreamHost;
|
|
||||||
private IWebHost _secondDownstreamHost;
|
|
||||||
private readonly List<string> _secondRecieved;
|
private readonly List<string> _secondRecieved;
|
||||||
private readonly List<string> _firstRecieved;
|
private readonly List<string> _firstRecieved;
|
||||||
private readonly List<ServiceEntry> _serviceEntries;
|
private readonly List<ServiceEntry> _serviceEntries;
|
||||||
private readonly Steps _steps;
|
private readonly Steps _steps;
|
||||||
private IWebHost _fakeConsulBuilder;
|
private readonly ServiceHandler _serviceHandler;
|
||||||
|
|
||||||
public WebSocketTests()
|
public WebSocketTests()
|
||||||
{
|
{
|
||||||
|
_serviceHandler = new ServiceHandler();
|
||||||
_steps = new Steps();
|
_steps = new Steps();
|
||||||
_firstRecieved = new List<string>();
|
_firstRecieved = new List<string>();
|
||||||
_secondRecieved = new List<string>();
|
_secondRecieved = new List<string>();
|
||||||
@ -211,25 +205,13 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string serviceName)
|
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string serviceName)
|
||||||
{
|
{
|
||||||
_fakeConsulBuilder = new WebHostBuilder()
|
_serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
|
||||||
.UseUrls(url)
|
{
|
||||||
.UseKestrel()
|
if (context.Request.Path.Value == $"/v1/health/service/{serviceName}")
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseUrls(url)
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
await context.Response.WriteJsonAsync(_serviceEntries);
|
||||||
{
|
}
|
||||||
if (context.Request.Path.Value == $"/v1/health/service/{serviceName}")
|
});
|
||||||
{
|
|
||||||
await context.Response.WriteJsonAsync(_serviceEntries);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_fakeConsulBuilder.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task WhenIStartTheClients()
|
private async Task WhenIStartTheClients()
|
||||||
@ -333,94 +315,48 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
private async Task StartFakeDownstreamService(string url, string path)
|
private async Task StartFakeDownstreamService(string url, string path)
|
||||||
{
|
{
|
||||||
_firstDownstreamHost = new WebHostBuilder()
|
await _serviceHandler.StartFakeDownstreamService(url, path, async(context, next) =>
|
||||||
.ConfigureServices(s => { }).UseKestrel()
|
{
|
||||||
.UseUrls(url)
|
if (context.Request.Path == path)
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.ConfigureAppConfiguration((hostingContext, config) =>
|
|
||||||
{
|
{
|
||||||
config.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath);
|
if (context.WebSockets.IsWebSocketRequest)
|
||||||
var env = hostingContext.HostingEnvironment;
|
|
||||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
|
||||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: false);
|
|
||||||
config.AddEnvironmentVariables();
|
|
||||||
})
|
|
||||||
.ConfigureLogging((hostingContext, logging) =>
|
|
||||||
{
|
|
||||||
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
|
||||||
logging.AddConsole();
|
|
||||||
})
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.UseWebSockets();
|
|
||||||
app.Use(async (context, next) =>
|
|
||||||
{
|
{
|
||||||
if (context.Request.Path == path)
|
var webSocket = await context.WebSockets.AcceptWebSocketAsync();
|
||||||
{
|
await Echo(webSocket);
|
||||||
if (context.WebSockets.IsWebSocketRequest)
|
}
|
||||||
{
|
else
|
||||||
WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
|
{
|
||||||
await Echo(webSocket);
|
context.Response.StatusCode = 400;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
context.Response.StatusCode = 400;
|
{
|
||||||
}
|
await next();
|
||||||
}
|
}
|
||||||
else
|
});
|
||||||
{
|
|
||||||
await next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.UseIISIntegration().Build();
|
|
||||||
await _firstDownstreamHost.StartAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task StartSecondFakeDownstreamService(string url, string path)
|
private async Task StartSecondFakeDownstreamService(string url, string path)
|
||||||
{
|
{
|
||||||
_secondDownstreamHost = new WebHostBuilder()
|
await _serviceHandler.StartFakeDownstreamService(url, path, async (context, next) =>
|
||||||
.ConfigureServices(s => { }).UseKestrel()
|
{
|
||||||
.UseUrls(url)
|
if (context.Request.Path == path)
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.ConfigureAppConfiguration((hostingContext, config) =>
|
|
||||||
{
|
{
|
||||||
config.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath);
|
if (context.WebSockets.IsWebSocketRequest)
|
||||||
var env = hostingContext.HostingEnvironment;
|
|
||||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
|
||||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: false);
|
|
||||||
config.AddEnvironmentVariables();
|
|
||||||
})
|
|
||||||
.ConfigureLogging((hostingContext, logging) =>
|
|
||||||
{
|
|
||||||
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
|
||||||
logging.AddConsole();
|
|
||||||
})
|
|
||||||
.Configure(app =>
|
|
||||||
{
|
|
||||||
app.UseWebSockets();
|
|
||||||
app.Use(async (context, next) =>
|
|
||||||
{
|
{
|
||||||
if (context.Request.Path == path)
|
WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
|
||||||
{
|
await Message(webSocket);
|
||||||
if (context.WebSockets.IsWebSocketRequest)
|
}
|
||||||
{
|
else
|
||||||
WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
|
{
|
||||||
await Message(webSocket);
|
context.Response.StatusCode = 400;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
context.Response.StatusCode = 400;
|
{
|
||||||
}
|
await next();
|
||||||
}
|
}
|
||||||
else
|
});
|
||||||
{
|
|
||||||
await next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.UseIISIntegration().Build();
|
|
||||||
await _secondDownstreamHost.StartAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Echo(WebSocket webSocket)
|
private async Task Echo(WebSocket webSocket)
|
||||||
@ -473,10 +409,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
_serviceHandler?.Dispose();
|
||||||
_steps.Dispose();
|
_steps.Dispose();
|
||||||
_firstDownstreamHost?.Dispose();
|
|
||||||
_secondDownstreamHost?.Dispose();
|
|
||||||
_fakeConsulBuilder?.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user