changed to json configuration to get rid of yaml imports

This commit is contained in:
TomPallister 2016-11-02 21:50:53 +00:00
parent 190e394011
commit f4acb4f041
33 changed files with 386 additions and 356 deletions

View File

@ -25,8 +25,6 @@
<dependency id="Microsoft.Extensions.Options.ConfigurationExtensions" version="1.0.0" /> <dependency id="Microsoft.Extensions.Options.ConfigurationExtensions" version="1.0.0" />
<dependency id="Microsoft.AspNetCore.Http" version="1.0.0" /> <dependency id="Microsoft.AspNetCore.Http" version="1.0.0" />
<dependency id="System.Text.RegularExpressions" version="4.1.0" /> <dependency id="System.Text.RegularExpressions" version="4.1.0" />
<dependency id="YamlDotNet" version="3.9.0" />
<dependency id="NetEscapades.Configuration.Yaml" version="1.2.0" />
<dependency id="Microsoft.AspNetCore.Authentication.OAuth" version="1.0.0" /> <dependency id="Microsoft.AspNetCore.Authentication.OAuth" version="1.0.0" />
<dependency id="Microsoft.AspNetCore.Authentication.JwtBearer" version="1.0.0" /> <dependency id="Microsoft.AspNetCore.Authentication.JwtBearer" version="1.0.0" />
<dependency id="Microsoft.AspNetCore.Authentication.OpenIdConnect" version="1.0.0" /> <dependency id="Microsoft.AspNetCore.Authentication.OpenIdConnect" version="1.0.0" />

View File

@ -31,11 +31,76 @@ All versions can be found [here](https://www.nuget.org/packages/Ocelot/)
## Configuration ## Configuration
An example configuration can be found [here](https://github.com/TomPallister/Ocelot/blob/develop/test/Ocelot.ManualTest/configuration.yaml). More detailed instructions to come on how to configure this. An example configuration can be found [here](https://github.com/TomPallister/Ocelot/blob/develop/test/Ocelot.ManualTest/configuration.json). More detailed instructions to come on how to configure this.
"ReRoutes": [
{
# The url we are forwarding the request to
"UpstreamTemplate": "/identityserverexample",
# The path we are listening on for this re route
"UpstreamTemplate": "/identityserverexample",
# The method we are listening for on this re route
"UpstreamHttpMethod": "Get",
# Only support identity server at the moment
"AuthenticationOptions": {
"Provider": "IdentityServer",
"ProviderRootUrl": "http://localhost:52888",
"ScopeName": "api",
"AdditionalScopes": [
"openid",
"offline_access"
],
# Required if using reference tokens
"ScopeSecret": "secret"
},
# WARNING - will overwrite any headers already in the request with these values.
# Ocelot will look in the user claims for the key in [] then return the value and save
# it as a header with the given key before the colon (:). The index selection on value
# means that Ocelot will use the delimiter specified after the next > to split the
# claim value and return the index specified.
"AddHeadersToRequest": {
"CustomerId": "Claims[CustomerId] > value",
"LocationId": "Claims[LocationId] > value",
"UserType": "Claims[sub] > value[0] > |",
"UserId": "Claims[sub] > value[1] > |"
},
# WARNING - will overwrite any claims already in the request with these values.
# Ocelot will look in the user claims for the key in [] then return the value and save
# it as a claim with the given key before the colon (:). The index selection on value
# means that Ocelot will use the delimiter specified after the next > to split the
# claim value and return the index specified.
"AddClaimsToRequest": {
"CustomerId": "Claims[CustomerId] > value",
"LocationId": "Claims[LocationId] > value",
"UserType": "Claims[sub] > value[0] > |",
"UserId": "Claims[sub] > value[1] > |"
},
# WARNING - will overwrite any query string entries already in the request with these values.
# Ocelot will look in the user claims for the key in [] then return the value and save
# it as a query string with the given key before the colon (:). The index selection on value
# means that Ocelot will use the delimiter specified after the next > to split the
# claim value and return the index specified.
"AddQueriesToRequest": {
"CustomerId": "Claims[CustomerId] > value",
"LocationId": "Claims[LocationId] > value",
"UserType": "Claims[sub] > value[0] > |",
"UserId": "Claims[sub] > value[1] > |"
},
# This specifies any claims that are required for the user to access this re route.
# In this example the user must have the claim type UserType and
# the value must be registered
"RouteClaimsRequirement": {
"UserType": "registered"
},
# This tells Ocelot to look for a header and use its value as a request/correlation id.
# If it is set here then the id will be forwarded to the downstream service. If it
# does not then it will not be forwarded
"RequestIdKey": "OcRequestId"
}
## Startup ## Startup
An example startup using a yaml file for configuration can be seen below. Currently this is the only way to get configuration into Ocelot. An example startup using a json file for configuration can be seen below. Currently this is the only way to get configuration into Ocelot.
public class Startup public class Startup
{ {
@ -45,9 +110,9 @@ An example startup using a yaml file for configuration can be seen below. Curren
{ {
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath) .SetBasePath(env.ContentRootPath)
.AddJsonFile("configuration.json", optional: true, reloadOnChange: true)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddYamlFile("configuration.yaml")
.AddEnvironmentVariables(); .AddEnvironmentVariables();
Configuration = builder.Build(); Configuration = builder.Build();
@ -56,7 +121,7 @@ An example startup using a yaml file for configuration can be seen below. Curren
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddOcelotYamlConfiguration(Configuration); services.AddOcelotFileConfiguration(Configuration);
services.AddOcelot(); services.AddOcelot();
} }

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Ocelot.Configuration.File;
using Ocelot.Configuration.Parser; using Ocelot.Configuration.Parser;
using Ocelot.Configuration.Validator; using Ocelot.Configuration.Validator;
using Ocelot.Configuration.Yaml;
using Ocelot.Responses; using Ocelot.Responses;
namespace Ocelot.Configuration.Creator namespace Ocelot.Configuration.Creator
@ -13,20 +13,20 @@ namespace Ocelot.Configuration.Creator
/// <summary> /// <summary>
/// Register as singleton /// Register as singleton
/// </summary> /// </summary>
public class YamlOcelotConfigurationCreator : IOcelotConfigurationCreator public class FileOcelotConfigurationCreator : IOcelotConfigurationCreator
{ {
private readonly IOptions<YamlConfiguration> _options; private readonly IOptions<FileConfiguration> _options;
private readonly IConfigurationValidator _configurationValidator; private readonly IConfigurationValidator _configurationValidator;
private const string RegExMatchEverything = ".*"; private const string RegExMatchEverything = ".*";
private const string RegExMatchEndString = "$"; private const string RegExMatchEndString = "$";
private readonly IClaimToThingConfigurationParser _claimToThingConfigurationParser; private readonly IClaimToThingConfigurationParser _claimToThingConfigurationParser;
private readonly ILogger<YamlOcelotConfigurationCreator> _logger; private readonly ILogger<FileOcelotConfigurationCreator> _logger;
public YamlOcelotConfigurationCreator( public FileOcelotConfigurationCreator(
IOptions<YamlConfiguration> options, IOptions<FileConfiguration> options,
IConfigurationValidator configurationValidator, IConfigurationValidator configurationValidator,
IClaimToThingConfigurationParser claimToThingConfigurationParser, IClaimToThingConfigurationParser claimToThingConfigurationParser,
ILogger<YamlOcelotConfigurationCreator> logger) ILogger<FileOcelotConfigurationCreator> logger)
{ {
_options = options; _options = options;
_configurationValidator = configurationValidator; _configurationValidator = configurationValidator;
@ -42,7 +42,7 @@ namespace Ocelot.Configuration.Creator
} }
/// <summary> /// <summary>
/// This method is meant to be tempoary to convert a yaml config to an ocelot config...probably wont keep this but we will see /// This method is meant to be tempoary to convert a config to an ocelot config...probably wont keep this but we will see
/// will need a refactor at some point as its crap /// will need a refactor at some point as its crap
/// </summary> /// </summary>
private IOcelotConfiguration SetUpConfiguration() private IOcelotConfiguration SetUpConfiguration()
@ -63,16 +63,16 @@ namespace Ocelot.Configuration.Creator
var reRoutes = new List<ReRoute>(); var reRoutes = new List<ReRoute>();
foreach (var yamlReRoute in _options.Value.ReRoutes) foreach (var reRoute in _options.Value.ReRoutes)
{ {
var ocelotReRoute = SetUpReRoute(yamlReRoute); var ocelotReRoute = SetUpReRoute(reRoute);
reRoutes.Add(ocelotReRoute); reRoutes.Add(ocelotReRoute);
} }
return new OcelotConfiguration(reRoutes); return new OcelotConfiguration(reRoutes);
} }
private ReRoute SetUpReRoute(YamlReRoute reRoute) private ReRoute SetUpReRoute(FileReRoute reRoute)
{ {
var upstreamTemplate = reRoute.UpstreamTemplate; var upstreamTemplate = reRoute.UpstreamTemplate;

View File

@ -1,9 +1,14 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Ocelot.Configuration.Yaml namespace Ocelot.Configuration.File
{ {
public class YamlAuthenticationOptions public class FileAuthenticationOptions
{ {
public FileAuthenticationOptions()
{
AdditionalScopes = new List<string>();
}
public string Provider { get; set; } public string Provider { get; set; }
public string ProviderRootUrl { get; set; } public string ProviderRootUrl { get; set; }
public string ScopeName { get; set; } public string ScopeName { get; set; }

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Ocelot.Configuration.File
{
public class FileConfiguration
{
public FileConfiguration()
{
ReRoutes = new List<FileReRoute>();
}
public List<FileReRoute> ReRoutes { get; set; }
}
}

View File

@ -1,21 +1,22 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Ocelot.Configuration.Yaml namespace Ocelot.Configuration.File
{ {
public class YamlReRoute public class FileReRoute
{ {
public YamlReRoute() public FileReRoute()
{ {
AddHeadersToRequest = new Dictionary<string, string>(); AddHeadersToRequest = new Dictionary<string, string>();
AddClaimsToRequest = new Dictionary<string, string>(); AddClaimsToRequest = new Dictionary<string, string>();
RouteClaimsRequirement = new Dictionary<string, string>(); RouteClaimsRequirement = new Dictionary<string, string>();
AddQueriesToRequest = new Dictionary<string, string>(); AddQueriesToRequest = new Dictionary<string, string>();
AuthenticationOptions = new FileAuthenticationOptions();
} }
public string DownstreamTemplate { get; set; } public string DownstreamTemplate { get; set; }
public string UpstreamTemplate { get; set; } public string UpstreamTemplate { get; set; }
public string UpstreamHttpMethod { get; set; } public string UpstreamHttpMethod { get; set; }
public YamlAuthenticationOptions AuthenticationOptions { get; set; } public FileAuthenticationOptions AuthenticationOptions { get; set; }
public Dictionary<string, string> AddHeadersToRequest { get; set; } public Dictionary<string, string> AddHeadersToRequest { get; set; }
public Dictionary<string, string> AddClaimsToRequest { get; set; } public Dictionary<string, string> AddClaimsToRequest { get; set; }
public Dictionary<string, string> RouteClaimsRequirement { get; set; } public Dictionary<string, string> RouteClaimsRequirement { get; set; }

View File

@ -2,15 +2,15 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Ocelot.Authentication.Handler; using Ocelot.Authentication.Handler;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using Ocelot.Errors; using Ocelot.Errors;
using Ocelot.Responses; using Ocelot.Responses;
namespace Ocelot.Configuration.Validator namespace Ocelot.Configuration.Validator
{ {
public class YamlConfigurationValidator : IConfigurationValidator public class FileConfigurationValidator : IConfigurationValidator
{ {
public Response<ConfigurationValidationResult> IsValid(YamlConfiguration configuration) public Response<ConfigurationValidationResult> IsValid(FileConfiguration configuration)
{ {
var result = CheckForDupliateReRoutes(configuration); var result = CheckForDupliateReRoutes(configuration);
@ -29,25 +29,25 @@ namespace Ocelot.Configuration.Validator
return new OkResponse<ConfigurationValidationResult>(result); return new OkResponse<ConfigurationValidationResult>(result);
} }
private ConfigurationValidationResult CheckForUnsupportedAuthenticationProviders(YamlConfiguration configuration) private ConfigurationValidationResult CheckForUnsupportedAuthenticationProviders(FileConfiguration configuration)
{ {
var errors = new List<Error>(); var errors = new List<Error>();
foreach (var yamlReRoute in configuration.ReRoutes) foreach (var reRoute in configuration.ReRoutes)
{ {
var isAuthenticated = !string.IsNullOrEmpty(yamlReRoute.AuthenticationOptions?.Provider); var isAuthenticated = !string.IsNullOrEmpty(reRoute.AuthenticationOptions?.Provider);
if (!isAuthenticated) if (!isAuthenticated)
{ {
continue; continue;
} }
if (IsSupportedAuthenticationProvider(yamlReRoute.AuthenticationOptions?.Provider)) if (IsSupportedAuthenticationProvider(reRoute.AuthenticationOptions?.Provider))
{ {
continue; continue;
} }
var error = new UnsupportedAuthenticationProviderError($"{yamlReRoute.AuthenticationOptions?.Provider} is unsupported authentication provider, upstream template is {yamlReRoute.UpstreamTemplate}, upstream method is {yamlReRoute.UpstreamHttpMethod}"); var error = new UnsupportedAuthenticationProviderError($"{reRoute.AuthenticationOptions?.Provider} is unsupported authentication provider, upstream template is {reRoute.UpstreamTemplate}, upstream method is {reRoute.UpstreamHttpMethod}");
errors.Add(error); errors.Add(error);
} }
@ -63,7 +63,7 @@ namespace Ocelot.Configuration.Validator
return Enum.TryParse(provider, true, out supportedProvider); return Enum.TryParse(provider, true, out supportedProvider);
} }
private ConfigurationValidationResult CheckForDupliateReRoutes(YamlConfiguration configuration) private ConfigurationValidationResult CheckForDupliateReRoutes(FileConfiguration configuration)
{ {
var hasDupes = configuration.ReRoutes var hasDupes = configuration.ReRoutes
.GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod }).Any(x => x.Skip(1).Any()); .GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod }).Any(x => x.Skip(1).Any());

View File

@ -1,10 +1,10 @@
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using Ocelot.Responses; using Ocelot.Responses;
namespace Ocelot.Configuration.Validator namespace Ocelot.Configuration.Validator
{ {
public interface IConfigurationValidator public interface IConfigurationValidator
{ {
Response<ConfigurationValidationResult> IsValid(YamlConfiguration configuration); Response<ConfigurationValidationResult> IsValid(FileConfiguration configuration);
} }
} }

View File

@ -1,14 +0,0 @@
using System.Collections.Generic;
namespace Ocelot.Configuration.Yaml
{
public class YamlConfiguration
{
public YamlConfiguration()
{
ReRoutes = new List<YamlReRoute>();
}
public List<YamlReRoute> ReRoutes { get; set; }
}
}

View File

@ -6,11 +6,11 @@ using Ocelot.Authentication.Handler.Factory;
using Ocelot.Authorisation; using Ocelot.Authorisation;
using Ocelot.Claims; using Ocelot.Claims;
using Ocelot.Configuration.Creator; using Ocelot.Configuration.Creator;
using Ocelot.Configuration.File;
using Ocelot.Configuration.Parser; using Ocelot.Configuration.Parser;
using Ocelot.Configuration.Provider; using Ocelot.Configuration.Provider;
using Ocelot.Configuration.Repository; using Ocelot.Configuration.Repository;
using Ocelot.Configuration.Validator; using Ocelot.Configuration.Validator;
using Ocelot.Configuration.Yaml;
using Ocelot.DownstreamRouteFinder.Finder; using Ocelot.DownstreamRouteFinder.Finder;
using Ocelot.DownstreamRouteFinder.UrlMatcher; using Ocelot.DownstreamRouteFinder.UrlMatcher;
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer; using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
@ -26,15 +26,14 @@ namespace Ocelot.DependencyInjection
{ {
public static class ServiceCollectionExtensions public static class ServiceCollectionExtensions
{ {
public static IServiceCollection AddOcelotYamlConfiguration(this IServiceCollection services, IConfigurationRoot configurationRoot) public static IServiceCollection AddOcelotFileConfiguration(this IServiceCollection services, IConfigurationRoot configurationRoot)
{ {
// initial configuration from yaml services.Configure<FileConfiguration>(configurationRoot);
services.Configure<YamlConfiguration>(configurationRoot);
// ocelot services. // ocelot services.
services.AddSingleton<IOcelotConfigurationCreator, YamlOcelotConfigurationCreator>(); services.AddSingleton<IOcelotConfigurationCreator, FileOcelotConfigurationCreator>();
services.AddSingleton<IOcelotConfigurationRepository, InMemoryOcelotConfigurationRepository>(); services.AddSingleton<IOcelotConfigurationRepository, InMemoryOcelotConfigurationRepository>();
services.AddSingleton<IConfigurationValidator, YamlConfigurationValidator>(); services.AddSingleton<IConfigurationValidator, FileConfigurationValidator>();
return services; return services;
} }

View File

@ -27,16 +27,12 @@
"Microsoft.NETCore.App": { "Microsoft.NETCore.App": {
"version": "1.0.1", "version": "1.0.1",
"type": "platform" "type": "platform"
}, }
"NetEscapades.Configuration.Yaml": "1.2.0",
"YamlDotNet": "4.0.0"
}, },
"frameworks": { "frameworks": {
"netcoreapp1.4": { "netcoreapp1.4": {
"imports": [ "imports": [
"dotnet5.6",
"portable-net45+win8"
] ]
} }
} }

View File

@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using TestStack.BDDfy; using TestStack.BDDfy;
using Xunit; using Xunit;
@ -31,16 +31,16 @@ 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()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = _downstreamServiceRootUrl, DownstreamTemplate = _downstreamServiceRootUrl,
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Post", UpstreamHttpMethod = "Post",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string>(), AdditionalScopes = new List<string>(),
Provider = "IdentityServer", Provider = "IdentityServer",
@ -55,7 +55,7 @@ namespace Ocelot.AcceptanceTests
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt)) this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty)) .And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenThePostHasContent("postContent")) .And(x => _steps.GivenThePostHasContent("postContent"))
.When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) .When(x => _steps.WhenIPostUrlOnTheApiGateway("/"))
@ -66,16 +66,16 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_401_using_identity_server_reference_token() public void should_return_401_using_identity_server_reference_token()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = _downstreamServiceRootUrl, DownstreamTemplate = _downstreamServiceRootUrl,
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Post", UpstreamHttpMethod = "Post",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string>(), AdditionalScopes = new List<string>(),
Provider = "IdentityServer", Provider = "IdentityServer",
@ -90,7 +90,7 @@ namespace Ocelot.AcceptanceTests
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Reference)) this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Reference))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty)) .And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenThePostHasContent("postContent")) .And(x => _steps.GivenThePostHasContent("postContent"))
.When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) .When(x => _steps.WhenIPostUrlOnTheApiGateway("/"))
@ -101,16 +101,16 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_200_using_identity_server() public void should_return_response_200_using_identity_server()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = _downstreamServiceRootUrl, DownstreamTemplate = _downstreamServiceRootUrl,
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Get", UpstreamHttpMethod = "Get",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string>(), AdditionalScopes = new List<string>(),
Provider = "IdentityServer", Provider = "IdentityServer",
@ -126,7 +126,7 @@ namespace Ocelot.AcceptanceTests
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt)) this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 200, "Hello from Laura")) .And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 200, "Hello from Laura"))
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenIHaveAddedATokenToMyRequest()) .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
@ -138,16 +138,16 @@ 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 yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = _downstreamServiceRootUrl, DownstreamTemplate = _downstreamServiceRootUrl,
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Post", UpstreamHttpMethod = "Post",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string>(), AdditionalScopes = new List<string>(),
Provider = "IdentityServer", Provider = "IdentityServer",
@ -163,7 +163,7 @@ namespace Ocelot.AcceptanceTests
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt)) this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty)) .And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty))
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenIHaveAddedATokenToMyRequest()) .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
.And(x => _steps.GivenThePostHasContent("postContent")) .And(x => _steps.GivenThePostHasContent("postContent"))
@ -175,16 +175,16 @@ 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 yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = _downstreamServiceRootUrl, DownstreamTemplate = _downstreamServiceRootUrl,
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Post", UpstreamHttpMethod = "Post",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string>(), AdditionalScopes = new List<string>(),
Provider = "IdentityServer", Provider = "IdentityServer",
@ -200,7 +200,7 @@ namespace Ocelot.AcceptanceTests
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Reference)) this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Reference))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty)) .And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty))
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenIHaveAddedATokenToMyRequest()) .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
.And(x => _steps.GivenThePostHasContent("postContent")) .And(x => _steps.GivenThePostHasContent("postContent"))

View File

@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using TestStack.BDDfy; using TestStack.BDDfy;
using Xunit; using Xunit;
@ -29,16 +29,16 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_200_authorising_route() public void should_return_response_200_authorising_route()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:51876/", DownstreamTemplate = "http://localhost:51876/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Get", UpstreamHttpMethod = "Get",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string>(), AdditionalScopes = new List<string>(),
Provider = "IdentityServer", Provider = "IdentityServer",
@ -71,7 +71,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:51876", 200, "Hello from Laura"))
.And(x => _steps.GivenIHaveAToken("http://localhost:51888")) .And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenIHaveAddedATokenToMyRequest()) .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
@ -83,16 +83,16 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_403_authorising_route() public void should_return_response_403_authorising_route()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:51876/", DownstreamTemplate = "http://localhost:51876/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Get", UpstreamHttpMethod = "Get",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string>(), AdditionalScopes = new List<string>(),
Provider = "IdentityServer", Provider = "IdentityServer",
@ -124,7 +124,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:51876", 200, "Hello from Laura"))
.And(x => _steps.GivenIHaveAToken("http://localhost:51888")) .And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenIHaveAddedATokenToMyRequest()) .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))

View File

@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using TestStack.BDDfy; using TestStack.BDDfy;
using Xunit; using Xunit;
@ -44,16 +44,16 @@ namespace Ocelot.AcceptanceTests
} }
}; };
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:52876/", DownstreamTemplate = "http://localhost:52876/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Get", UpstreamHttpMethod = "Get",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string> AdditionalScopes = new List<string>
{ {
@ -79,7 +79,7 @@ namespace Ocelot.AcceptanceTests
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:52888", "api", AccessTokenType.Jwt, user)) this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:52888", "api", AccessTokenType.Jwt, user))
.And(x => x.GivenThereIsAServiceRunningOn("http://localhost:52876", 200)) .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:52876", 200))
.And(x => _steps.GivenIHaveAToken("http://localhost:52888")) .And(x => _steps.GivenIHaveAToken("http://localhost:52888"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenIHaveAddedATokenToMyRequest()) .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using TestStack.BDDfy; using TestStack.BDDfy;
using Xunit; using Xunit;
@ -44,16 +44,16 @@ namespace Ocelot.AcceptanceTests
} }
}; };
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:57876/", DownstreamTemplate = "http://localhost:57876/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Get", UpstreamHttpMethod = "Get",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string> AdditionalScopes = new List<string>
{ {
@ -79,7 +79,7 @@ namespace Ocelot.AcceptanceTests
this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:57888", "api", AccessTokenType.Jwt, user)) this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:57888", "api", AccessTokenType.Jwt, user))
.And(x => x.GivenThereIsAServiceRunningOn("http://localhost:57876", 200)) .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:57876", 200))
.And(x => _steps.GivenIHaveAToken("http://localhost:57888")) .And(x => _steps.GivenIHaveAToken("http://localhost:57888"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenIHaveAddedATokenToMyRequest()) .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))

View File

@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using Ocelot.Infrastructure.RequestData; using Ocelot.Infrastructure.RequestData;
using Ocelot.Middleware; using Ocelot.Middleware;
using TestStack.BDDfy; using TestStack.BDDfy;
@ -25,7 +25,7 @@ namespace Ocelot.AcceptanceTests
public CustomMiddlewareTests() public CustomMiddlewareTests()
{ {
_steps = new Steps();; _steps = new Steps();;
_configurationPath = "configuration.yaml"; _configurationPath = "configuration.json";
} }
[Fact] [Fact]
@ -39,11 +39,11 @@ namespace Ocelot.AcceptanceTests
} }
}; };
var yamlConfiguration = new YamlConfiguration var fileConfiguration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:41879/", DownstreamTemplate = "http://localhost:41879/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
@ -53,7 +53,7 @@ namespace Ocelot.AcceptanceTests
}; };
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200)) this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration, _configurationPath)) .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
.And(x => _steps.GivenOcelotIsRunning(configuration)) .And(x => _steps.GivenOcelotIsRunning(configuration))
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
@ -72,11 +72,11 @@ namespace Ocelot.AcceptanceTests
} }
}; };
var yamlConfiguration = new YamlConfiguration var fileConfiguration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:41879/", DownstreamTemplate = "http://localhost:41879/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
@ -86,7 +86,7 @@ namespace Ocelot.AcceptanceTests
}; };
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200)) this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration, _configurationPath)) .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
.And(x => _steps.GivenOcelotIsRunning(configuration)) .And(x => _steps.GivenOcelotIsRunning(configuration))
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))

View File

@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using TestStack.BDDfy; using TestStack.BDDfy;
using Xunit; using Xunit;
@ -27,11 +27,11 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_use_default_request_id_and_forward() public void should_use_default_request_id_and_forward()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:51879/", DownstreamTemplate = "http://localhost:51879/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
@ -42,7 +42,7 @@ namespace Ocelot.AcceptanceTests
}; };
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879")) this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheRequestIdIsReturned()) .Then(x => _steps.ThenTheRequestIdIsReturned())
@ -52,11 +52,11 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_use_request_id_and_forward() public void should_use_request_id_and_forward()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:51879/", DownstreamTemplate = "http://localhost:51879/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
@ -69,7 +69,7 @@ namespace Ocelot.AcceptanceTests
var requestId = Guid.NewGuid().ToString(); var requestId = Guid.NewGuid().ToString();
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879")) this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/", requestId)) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/", requestId))
.Then(x => _steps.ThenTheRequestIdIsReturned(requestId)) .Then(x => _steps.ThenTheRequestIdIsReturned(requestId))

View File

@ -4,7 +4,7 @@ using System.IO;
using System.Net; using System.Net;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using TestStack.BDDfy; using TestStack.BDDfy;
using Xunit; using Xunit;
@ -23,21 +23,21 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_200_and_foward_claim_as_header() public void should_return_response_200_and_foward_claim_as_header()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:53876/", DownstreamTemplate = "http://localhost:53876/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
UpstreamHttpMethod = "Get", UpstreamHttpMethod = "Get"
} }
} }
}; };
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:53876")) this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:53876"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.InternalServerError)) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.InternalServerError))

View File

@ -5,7 +5,7 @@ using System.Net;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using TestStack.BDDfy; using TestStack.BDDfy;
using Xunit; using Xunit;
@ -24,7 +24,7 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_404_when_no_configuration_at_all() public void should_return_response_404_when_no_configuration_at_all()
{ {
this.Given(x => _steps.GivenThereIsAConfiguration(new YamlConfiguration())) this.Given(x => _steps.GivenThereIsAConfiguration(new FileConfiguration()))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound)) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound))
@ -34,11 +34,11 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_200_with_simple_url() public void should_return_response_200_with_simple_url()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:51879/", DownstreamTemplate = "http://localhost:51879/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
@ -48,7 +48,7 @@ namespace Ocelot.AcceptanceTests
}; };
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", 200, "Hello from Laura")) this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", 200, "Hello from Laura"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
@ -59,11 +59,11 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_200_with_complex_url() public void should_return_response_200_with_complex_url()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:51879/api/products/{productId}", DownstreamTemplate = "http://localhost:51879/api/products/{productId}",
UpstreamTemplate = "/products/{productId}", UpstreamTemplate = "/products/{productId}",
@ -73,7 +73,7 @@ namespace Ocelot.AcceptanceTests
}; };
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/api/products/1", 200, "Some Product")) this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/api/products/1", 200, "Some Product"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/products/1")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/products/1"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
@ -84,11 +84,11 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_201_with_simple_url() public void should_return_response_201_with_simple_url()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:51879/", DownstreamTemplate = "http://localhost:51879/",
UpstreamTemplate = "/", UpstreamTemplate = "/",
@ -98,7 +98,7 @@ namespace Ocelot.AcceptanceTests
}; };
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", 201, string.Empty)) this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", 201, string.Empty))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenThePostHasContent("postContent")) .And(x => _steps.GivenThePostHasContent("postContent"))
.When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) .When(x => _steps.WhenIPostUrlOnTheApiGateway("/"))
@ -109,11 +109,11 @@ namespace Ocelot.AcceptanceTests
[Fact] [Fact]
public void should_return_response_201_with_complex_query_string() public void should_return_response_201_with_complex_query_string()
{ {
var yamlConfiguration = new YamlConfiguration var configuration = new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://localhost:51879/newThing", DownstreamTemplate = "http://localhost:51879/newThing",
UpstreamTemplate = "/newThing", UpstreamTemplate = "/newThing",
@ -123,7 +123,7 @@ namespace Ocelot.AcceptanceTests
}; };
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", 200, "Hello from Laura")) this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", 200, "Hello from Laura"))
.And(x => _steps.GivenThereIsAConfiguration(yamlConfiguration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/newThing?DeviceType=IphoneApp&Browser=moonpigIphone&BrowserString=-&CountryCode=123&DeviceName=iPhone 5 (GSM+CDMA)&OperatingSystem=iPhone OS 7.1.2&BrowserVersion=3708AdHoc&ipAddress=-")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/newThing?DeviceType=IphoneApp&Browser=moonpigIphone&BrowserString=-&CountryCode=123&DeviceName=iPhone 5 (GSM+CDMA)&OperatingSystem=iPhone OS 7.1.2&BrowserVersion=3708AdHoc&ipAddress=-"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))

View File

@ -10,12 +10,11 @@ using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ocelot.Configuration.Yaml; using Ocelot.Configuration.File;
using Ocelot.DependencyInjection; using Ocelot.DependencyInjection;
using Ocelot.ManualTest; using Ocelot.ManualTest;
using Ocelot.Middleware; using Ocelot.Middleware;
using Shouldly; using Shouldly;
using YamlDotNet.Serialization;
namespace Ocelot.AcceptanceTests namespace Ocelot.AcceptanceTests
{ {
@ -29,40 +28,34 @@ namespace Ocelot.AcceptanceTests
public HttpClient OcelotClient => _ocelotClient; public HttpClient OcelotClient => _ocelotClient;
public string RequestIdKey = "OcRequestId"; public string RequestIdKey = "OcRequestId";
public void GivenThereIsAConfiguration(YamlConfiguration yamlConfiguration) public void GivenThereIsAConfiguration(FileConfiguration fileConfiguration)
{ {
var configurationPath = TestConfiguration.ConfigurationPath; var configurationPath = TestConfiguration.ConfigurationPath;
var serializer = new Serializer(); var jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration);
if (File.Exists(configurationPath)) if (File.Exists(configurationPath))
{ {
File.Delete(configurationPath); File.Delete(configurationPath);
} }
using (TextWriter writer = File.CreateText(configurationPath)) File.WriteAllText(configurationPath, jsonConfiguration);
{
serializer.Serialize(writer, yamlConfiguration);
}
} }
public void GivenThereIsAConfiguration(YamlConfiguration yamlConfiguration, string configurationPath) public void GivenThereIsAConfiguration(FileConfiguration fileConfiguration, string configurationPath)
{ {
var serializer = new Serializer(); var jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration);
if (File.Exists(configurationPath)) if (File.Exists(configurationPath))
{ {
File.Delete(configurationPath); File.Delete(configurationPath);
} }
using (TextWriter writer = File.CreateText(configurationPath)) File.WriteAllText(configurationPath, jsonConfiguration);
{
serializer.Serialize(writer, yamlConfiguration);
}
} }
/// <summary> /// <summary>
/// This is annoying cos it should be in the constructor but we need to set up the yaml file before calling startup so its a step. /// This is annoying cos it should be in the constructor but we need to set up the file before calling startup so its a step.
/// </summary> /// </summary>
public void GivenOcelotIsRunning() public void GivenOcelotIsRunning()
{ {
@ -73,14 +66,14 @@ namespace Ocelot.AcceptanceTests
} }
/// <summary> /// <summary>
/// This is annoying cos it should be in the constructor but we need to set up the yaml file before calling startup so its a step. /// This is annoying cos it should be in the constructor but we need to set up the file before calling startup so its a step.
/// </summary> /// </summary>
public void GivenOcelotIsRunning(OcelotMiddlewareConfiguration ocelotMiddlewareConfig) public void GivenOcelotIsRunning(OcelotMiddlewareConfiguration ocelotMiddlewareConfig)
{ {
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory()) .SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddYamlFile("configuration.yaml") .AddJsonFile("configuration.json")
.AddEnvironmentVariables(); .AddEnvironmentVariables();
var configuration = builder.Build(); var configuration = builder.Build();
@ -89,7 +82,7 @@ namespace Ocelot.AcceptanceTests
.UseConfiguration(configuration) .UseConfiguration(configuration)
.ConfigureServices(s => .ConfigureServices(s =>
{ {
s.AddOcelotYamlConfiguration(configuration); s.AddOcelotFileConfiguration(configuration);
s.AddOcelot(); s.AddOcelot();
}) })
.ConfigureLogging(l => .ConfigureLogging(l =>

View File

@ -3,6 +3,6 @@
public static class TestConfiguration public static class TestConfiguration
{ {
public static double Version => 1.4; public static double Version => 1.4;
public static string ConfigurationPath => $"./bin/Debug/netcoreapp{Version}/configuration.yaml"; public static string ConfigurationPath => $"./bin/Debug/netcoreapp{Version}/configuration.json";
} }
} }

View File

@ -0,0 +1 @@
{"ReRoutes":[{"DownstreamTemplate":"http://localhost:41879/","UpstreamTemplate":"/","UpstreamHttpMethod":"Get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null}]}

View File

@ -1,8 +0,0 @@
ReRoutes:
- DownstreamTemplate: http://localhost:41879/
UpstreamTemplate: /
UpstreamHttpMethod: Get
AddHeadersToRequest: {}
AddClaimsToRequest: {}
RouteClaimsRequirement: {}
AddQueriesToRequest: {}

View File

@ -4,7 +4,7 @@
"buildOptions": { "buildOptions": {
"copyToOutput": { "copyToOutput": {
"include": [ "include": [
"middlewareConfiguration.yaml" "configuration.json"
] ]
} }
}, },
@ -22,7 +22,7 @@
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.AspNetCore.Http": "1.0.0", "Microsoft.AspNetCore.Http": "1.0.0",
"Ocelot": "1.0.0-*", "Ocelot": "1.0.0-*",
"xunit": "2.1.0", "xunit": "2.2.0-beta2-build3300",
"dotnet-test-xunit": "2.2.0-preview2-build1029", "dotnet-test-xunit": "2.2.0-preview2-build1029",
"Ocelot.ManualTest": "1.0.0-*", "Ocelot.ManualTest": "1.0.0-*",
"Microsoft.AspNetCore.TestHost": "1.0.0", "Microsoft.AspNetCore.TestHost": "1.0.0",
@ -34,15 +34,12 @@
"type": "platform" "type": "platform"
}, },
"Shouldly": "2.8.2", "Shouldly": "2.8.2",
"TestStack.BDDfy": "4.3.2", "TestStack.BDDfy": "4.3.2"
"YamlDotNet": "4.0.0"
}, },
"frameworks": { "frameworks": {
"netcoreapp1.4": { "netcoreapp1.4": {
"imports": [ "imports": [
"dotnet5.6",
"portable-net45+win8"
] ]
} }
} }

View File

@ -16,8 +16,6 @@
"frameworks": { "frameworks": {
"netcoreapp1.4": { "netcoreapp1.4": {
"imports": [ "imports": [
"dotnet5.6",
"portable-net45+win8"
] ]
} }
} }

View File

@ -16,7 +16,7 @@ namespace Ocelot.ManualTest
.SetBasePath(env.ContentRootPath) .SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddYamlFile("configuration.yaml") .AddJsonFile("configuration.json")
.AddEnvironmentVariables(); .AddEnvironmentVariables();
Configuration = builder.Build(); Configuration = builder.Build();
@ -27,7 +27,7 @@ namespace Ocelot.ManualTest
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddOcelotYamlConfiguration(Configuration); services.AddOcelotFileConfiguration(Configuration);
services.AddOcelot(); services.AddOcelot();
} }

View File

@ -0,0 +1,81 @@
{
"ReRoutes": [
{
"DownstreamTemplate": "http://localhost:52876/",
"UpstreamTemplate": "/identityserverexample",
"UpstreamHttpMethod": "Get",
"AuthenticationOptions": {
"Provider": "IdentityServer",
"ProviderRootUrl": "http://localhost:52888",
"ScopeName": "api",
"AdditionalScopes": [
"openid",
"offline_access"
],
"ScopeSecret": "secret"
},
"AddHeadersToRequest": {
"CustomerId": "Claims[CustomerId] > value",
"LocationId": "Claims[LocationId] > value",
"UserType": "Claims[sub] > value[0] > |",
"UserId": "Claims[sub] > value[1] > |"
},
"AddClaimsToRequest": {
"CustomerId": "Claims[CustomerId] > value",
"LocationId": "Claims[LocationId] > value",
"UserType": "Claims[sub] > value[0] > |",
"UserId": "Claims[sub] > value[1] > |"
},
"AddQueriesToRequest": {
"CustomerId": "Claims[CustomerId] > value",
"LocationId": "Claims[LocationId] > value",
"UserType": "Claims[sub] > value[0] > |",
"UserId": "Claims[sub] > value[1] > |"
},
"RouteClaimsRequirement": {
"UserType": "registered"
},
"RequestIdKey": "OcRequestId"
},
{
"DownstreamTemplate": "http://jsonplaceholder.typicode.com/posts",
"UpstreamTemplate": "/posts",
"UpstreamHttpMethod": "Get"
},
{
"DownstreamTemplate": "http://jsonplaceholder.typicode.com/posts/{postId}",
"UpstreamTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Get"
},
{
"DownstreamTemplate": "http://jsonplaceholder.typicode.com/posts/{postId}/comments",
"UpstreamTemplate": "/posts/{postId}/comments",
"UpstreamHttpMethod": "Get"
},
{
"DownstreamTemplate": "http://jsonplaceholder.typicode.com/comments",
"UpstreamTemplate": "/comments",
"UpstreamHttpMethod": "Get"
},
{
"DownstreamTemplate": "http://jsonplaceholder.typicode.com/posts",
"UpstreamTemplate": "/posts",
"UpstreamHttpMethod": "Post"
},
{
"DownstreamTemplate": "http://jsonplaceholder.typicode.com/posts/{postId}",
"UpstreamTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Put"
},
{
"DownstreamTemplate": "http://jsonplaceholder.typicode.com/posts/{postId}",
"UpstreamTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Patch"
},
{
"DownstreamTemplate": "http://jsonplaceholder.typicode.com/posts/{postId}",
"UpstreamTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Delete"
}
]
}

View File

@ -1,88 +0,0 @@
ReRoutes:
# The url we are forwarding the request to
- DownstreamTemplate: http://localhost:52876/
# The path we are listening on for this re route
UpstreamTemplate: /identityserverexample
# The method we are listening for on this re route
UpstreamHttpMethod: Get
# Only support identity server at the moment
AuthenticationOptions:
Provider: IdentityServer
ProviderRootUrl: http://localhost:52888
ScopeName: api
AdditionalScopes:
- openid
- offline_access
# Required if using reference tokens
ScopeSecret: secret
# WARNING - will overwrite any headers already in the request with these values.
# Ocelot will look in the user claims for the key in [] then return the value and save
# it as a header with the given key before the colon (:). The index selection on value
# means that Ocelot will use the delimiter specified after the next > to split the
# claim value and return the index specified.
AddHeadersToRequest:
CustomerId: Claims[CustomerId] > value
LocationId: Claims[LocationId] > value
UserType: Claims[sub] > value[0] > |
UserId: Claims[sub] > value[1] > |
# WARNING - will overwrite any claims already in the request with these values.
# Ocelot will look in the user claims for the key in [] then return the value and save
# it as a claim with the given key before the colon (:). The index selection on value
# means that Ocelot will use the delimiter specified after the next > to split the
# claim value and return the index specified.
AddClaimsToRequest:
CustomerId: Claims[CustomerId] > value
LocationId: Claims[LocationId] > value
UserType: Claims[sub] > value[0] > |
UserId: Claims[sub] > value[1] > |
# WARNING - will overwrite any query string entries already in the request with these values.
# Ocelot will look in the user claims for the key in [] then return the value and save
# it as a query string with the given key before the colon (:). The index selection on value
# means that Ocelot will use the delimiter specified after the next > to split the
# claim value and return the index specified.
AddQueriesToRequest:
CustomerId: Claims[CustomerId] > value
LocationId: Claims[LocationId] > value
UserType: Claims[sub] > value[0] > |
UserId: Claims[sub] > value[1] > |
# This specifies any claims that are required for the user to access this re route.
# In this example the user must have the claim type UserType and
# the value must be registered
RouteClaimsRequirement:
UserType: registered
# This tells Ocelot to look for a header and use its value as a request/correlation id.
# If it is set here then the id will be forwarded to the downstream service. If it
# does not then it will not be forwarded
RequestIdKey: OcRequestId
# The next re route...
- DownstreamTemplate: http://jsonplaceholder.typicode.com/posts
UpstreamTemplate: /posts
UpstreamHttpMethod: Get
# The next re route...
- DownstreamTemplate: http://jsonplaceholder.typicode.com/posts/{postId}
UpstreamTemplate: /posts/{postId}
UpstreamHttpMethod: Get
# The next re route...
- DownstreamTemplate: http://jsonplaceholder.typicode.com/posts/{postId}/comments
UpstreamTemplate: /posts/{postId}/comments
UpstreamHttpMethod: Get
# The next re route...
- DownstreamTemplate: http://jsonplaceholder.typicode.com/comments
UpstreamTemplate: /comments
UpstreamHttpMethod: Get
# The next re route...
- DownstreamTemplate: http://jsonplaceholder.typicode.com/posts
UpstreamTemplate: /posts
UpstreamHttpMethod: Post
# The next re route...
- DownstreamTemplate: http://jsonplaceholder.typicode.com/posts/{postId}
UpstreamTemplate: /posts/{postId}
UpstreamHttpMethod: Put
# The next re route...
- DownstreamTemplate: http://jsonplaceholder.typicode.com/posts/{postId}
UpstreamTemplate: /posts/{postId}
UpstreamHttpMethod: Patch
# The next re route...
- DownstreamTemplate: http://jsonplaceholder.typicode.com/posts/{postId}
UpstreamTemplate: /posts/{postId}
UpstreamHttpMethod: Delete

View File

@ -17,8 +17,7 @@
"Microsoft.NETCore.App": { "Microsoft.NETCore.App": {
"version": "1.0.1", "version": "1.0.1",
"type": "platform" "type": "platform"
}, }
"NetEscapades.Configuration.Yaml": "1.2.0"
}, },
"tools": { "tools": {
@ -28,8 +27,6 @@
"frameworks": { "frameworks": {
"netcoreapp1.4": { "netcoreapp1.4": {
"imports": [ "imports": [
"dotnet5.6",
"portable-net45+win8"
] ]
} }
}, },
@ -39,8 +36,7 @@
"preserveCompilationContext": true, "preserveCompilationContext": true,
"copyToOutput": { "copyToOutput": {
"include": [ "include": [
"middlewareConfiguration.yaml", "configuration.json"
"configuration.yaml"
] ]
} }
}, },
@ -58,8 +54,7 @@
"Areas/**/Views", "Areas/**/Views",
"appsettings.json", "appsettings.json",
"web.config", "web.config",
"middlewareConfiguration.yaml", "configuration.json"
"configuration.yaml"
] ]
}, },

View File

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Ocelot.Configuration.File;
using Ocelot.Configuration.Validator; using Ocelot.Configuration.Validator;
using Ocelot.Configuration.Yaml;
using Ocelot.Responses; using Ocelot.Responses;
using Shouldly; using Shouldly;
using TestStack.BDDfy; using TestStack.BDDfy;
@ -10,23 +10,23 @@ namespace Ocelot.UnitTests.Configuration
{ {
public class ConfigurationValidationTests public class ConfigurationValidationTests
{ {
private YamlConfiguration _yamlConfiguration; private FileConfiguration _fileConfiguration;
private readonly IConfigurationValidator _configurationValidator; private readonly IConfigurationValidator _configurationValidator;
private Response<ConfigurationValidationResult> _result; private Response<ConfigurationValidationResult> _result;
public ConfigurationValidationTests() public ConfigurationValidationTests()
{ {
_configurationValidator = new YamlConfigurationValidator(); _configurationValidator = new FileConfigurationValidator();
} }
[Fact] [Fact]
public void configuration_is_valid_with_one_reroute() public void configuration_is_valid_with_one_reroute()
{ {
this.Given(x => x.GivenAConfiguration(new YamlConfiguration() this.Given(x => x.GivenAConfiguration(new FileConfiguration()
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://www.bbc.co.uk", DownstreamTemplate = "http://www.bbc.co.uk",
UpstreamTemplate = "http://asdf.com" UpstreamTemplate = "http://asdf.com"
@ -41,15 +41,15 @@ namespace Ocelot.UnitTests.Configuration
[Fact] [Fact]
public void configuration_is_valid_with_valid_authentication_provider() public void configuration_is_valid_with_valid_authentication_provider()
{ {
this.Given(x => x.GivenAConfiguration(new YamlConfiguration() this.Given(x => x.GivenAConfiguration(new FileConfiguration()
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://www.bbc.co.uk", DownstreamTemplate = "http://www.bbc.co.uk",
UpstreamTemplate = "http://asdf.com", UpstreamTemplate = "http://asdf.com",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
Provider = "IdentityServer" Provider = "IdentityServer"
} }
@ -64,15 +64,15 @@ namespace Ocelot.UnitTests.Configuration
[Fact] [Fact]
public void configuration_is_invalid_with_invalid_authentication_provider() public void configuration_is_invalid_with_invalid_authentication_provider()
{ {
this.Given(x => x.GivenAConfiguration(new YamlConfiguration() this.Given(x => x.GivenAConfiguration(new FileConfiguration()
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://www.bbc.co.uk", DownstreamTemplate = "http://www.bbc.co.uk",
UpstreamTemplate = "http://asdf.com", UpstreamTemplate = "http://asdf.com",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
Provider = "BootyBootyBottyRockinEverywhere" Provider = "BootyBootyBottyRockinEverywhere"
} }
@ -88,16 +88,16 @@ namespace Ocelot.UnitTests.Configuration
[Fact] [Fact]
public void configuration_is_not_valid_with_duplicate_reroutes() public void configuration_is_not_valid_with_duplicate_reroutes()
{ {
this.Given(x => x.GivenAConfiguration(new YamlConfiguration() this.Given(x => x.GivenAConfiguration(new FileConfiguration()
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://www.bbc.co.uk", DownstreamTemplate = "http://www.bbc.co.uk",
UpstreamTemplate = "http://asdf.com" UpstreamTemplate = "http://asdf.com"
}, },
new YamlReRoute new FileReRoute
{ {
DownstreamTemplate = "http://www.bbc.co.uk", DownstreamTemplate = "http://www.bbc.co.uk",
UpstreamTemplate = "http://asdf.com" UpstreamTemplate = "http://asdf.com"
@ -110,14 +110,14 @@ namespace Ocelot.UnitTests.Configuration
.BDDfy(); .BDDfy();
} }
private void GivenAConfiguration(YamlConfiguration yamlConfiguration) private void GivenAConfiguration(FileConfiguration fileConfiguration)
{ {
_yamlConfiguration = yamlConfiguration; _fileConfiguration = fileConfiguration;
} }
private void WhenIValidateTheConfiguration() private void WhenIValidateTheConfiguration()
{ {
_result = _configurationValidator.IsValid(_yamlConfiguration); _result = _configurationValidator.IsValid(_fileConfiguration);
} }
private void ThenTheResultIsValid() private void ThenTheResultIsValid()

View File

@ -5,9 +5,9 @@ using Moq;
using Ocelot.Configuration; using Ocelot.Configuration;
using Ocelot.Configuration.Builder; using Ocelot.Configuration.Builder;
using Ocelot.Configuration.Creator; using Ocelot.Configuration.Creator;
using Ocelot.Configuration.File;
using Ocelot.Configuration.Parser; using Ocelot.Configuration.Parser;
using Ocelot.Configuration.Validator; using Ocelot.Configuration.Validator;
using Ocelot.Configuration.Yaml;
using Ocelot.Responses; using Ocelot.Responses;
using Shouldly; using Shouldly;
using TestStack.BDDfy; using TestStack.BDDfy;
@ -15,34 +15,34 @@ using Xunit;
namespace Ocelot.UnitTests.Configuration namespace Ocelot.UnitTests.Configuration
{ {
public class YamlConfigurationCreatorTests public class FileConfigurationCreatorTests
{ {
private readonly Mock<IOptions<YamlConfiguration>> _yamlConfig; private readonly Mock<IOptions<FileConfiguration>> _fileConfig;
private readonly Mock<IConfigurationValidator> _validator; private readonly Mock<IConfigurationValidator> _validator;
private Response<IOcelotConfiguration> _config; private Response<IOcelotConfiguration> _config;
private YamlConfiguration _yamlConfiguration; private FileConfiguration _fileConfiguration;
private readonly Mock<IClaimToThingConfigurationParser> _configParser; private readonly Mock<IClaimToThingConfigurationParser> _configParser;
private readonly Mock<ILogger<YamlOcelotConfigurationCreator>> _logger; private readonly Mock<ILogger<FileOcelotConfigurationCreator>> _logger;
private readonly YamlOcelotConfigurationCreator _ocelotConfigurationCreator; private readonly FileOcelotConfigurationCreator _ocelotConfigurationCreator;
public YamlConfigurationCreatorTests() public FileConfigurationCreatorTests()
{ {
_logger = new Mock<ILogger<YamlOcelotConfigurationCreator>>(); _logger = new Mock<ILogger<FileOcelotConfigurationCreator>>();
_configParser = new Mock<IClaimToThingConfigurationParser>(); _configParser = new Mock<IClaimToThingConfigurationParser>();
_validator = new Mock<IConfigurationValidator>(); _validator = new Mock<IConfigurationValidator>();
_yamlConfig = new Mock<IOptions<YamlConfiguration>>(); _fileConfig = new Mock<IOptions<FileConfiguration>>();
_ocelotConfigurationCreator = new YamlOcelotConfigurationCreator( _ocelotConfigurationCreator = new FileOcelotConfigurationCreator(
_yamlConfig.Object, _validator.Object, _configParser.Object, _logger.Object); _fileConfig.Object, _validator.Object, _configParser.Object, _logger.Object);
} }
[Fact] [Fact]
public void should_create_template_pattern_that_matches_anything_to_end_of_string() public void should_create_template_pattern_that_matches_anything_to_end_of_string()
{ {
this.Given(x => x.GivenTheYamlConfigIs(new YamlConfiguration this.Given(x => x.GivenTheConfigIs(new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
UpstreamTemplate = "/api/products/{productId}", UpstreamTemplate = "/api/products/{productId}",
DownstreamTemplate = "/products/{productId}", DownstreamTemplate = "/products/{productId}",
@ -50,7 +50,7 @@ namespace Ocelot.UnitTests.Configuration
} }
} }
})) }))
.And(x => x.GivenTheYamlConfigIsValid()) .And(x => x.GivenTheConfigIsValid())
.When(x => x.WhenICreateTheConfig()) .When(x => x.WhenICreateTheConfig())
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute> .Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
{ {
@ -86,16 +86,16 @@ namespace Ocelot.UnitTests.Configuration
.Build() .Build()
}; };
this.Given(x => x.GivenTheYamlConfigIs(new YamlConfiguration this.Given(x => x.GivenTheConfigIs(new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
UpstreamTemplate = "/api/products/{productId}", UpstreamTemplate = "/api/products/{productId}",
DownstreamTemplate = "/products/{productId}", DownstreamTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get", UpstreamHttpMethod = "Get",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string>(), AdditionalScopes = new List<string>(),
Provider = "IdentityServer", Provider = "IdentityServer",
@ -111,7 +111,7 @@ namespace Ocelot.UnitTests.Configuration
} }
} }
})) }))
.And(x => x.GivenTheYamlConfigIsValid()) .And(x => x.GivenTheConfigIsValid())
.And(x => x.GivenTheConfigHeaderExtractorReturns(new ClaimToThing("CustomerId", "CustomerId", "", 0))) .And(x => x.GivenTheConfigHeaderExtractorReturns(new ClaimToThing("CustomerId", "CustomerId", "", 0)))
.When(x => x.WhenICreateTheConfig()) .When(x => x.WhenICreateTheConfig())
.Then(x => x.ThenTheReRoutesAre(expected)) .Then(x => x.ThenTheReRoutesAre(expected))
@ -144,16 +144,16 @@ namespace Ocelot.UnitTests.Configuration
.Build() .Build()
}; };
this.Given(x => x.GivenTheYamlConfigIs(new YamlConfiguration this.Given(x => x.GivenTheConfigIs(new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
UpstreamTemplate = "/api/products/{productId}", UpstreamTemplate = "/api/products/{productId}",
DownstreamTemplate = "/products/{productId}", DownstreamTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get", UpstreamHttpMethod = "Get",
AuthenticationOptions = new YamlAuthenticationOptions AuthenticationOptions = new FileAuthenticationOptions
{ {
AdditionalScopes = new List<string>(), AdditionalScopes = new List<string>(),
Provider = "IdentityServer", Provider = "IdentityServer",
@ -165,7 +165,7 @@ namespace Ocelot.UnitTests.Configuration
} }
} }
})) }))
.And(x => x.GivenTheYamlConfigIsValid()) .And(x => x.GivenTheConfigIsValid())
.When(x => x.WhenICreateTheConfig()) .When(x => x.WhenICreateTheConfig())
.Then(x => x.ThenTheReRoutesAre(expected)) .Then(x => x.ThenTheReRoutesAre(expected))
.And(x => x.ThenTheAuthenticationOptionsAre(expected)) .And(x => x.ThenTheAuthenticationOptionsAre(expected))
@ -175,11 +175,11 @@ namespace Ocelot.UnitTests.Configuration
[Fact] [Fact]
public void should_create_template_pattern_that_matches_more_than_one_placeholder() public void should_create_template_pattern_that_matches_more_than_one_placeholder()
{ {
this.Given(x => x.GivenTheYamlConfigIs(new YamlConfiguration this.Given(x => x.GivenTheConfigIs(new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
UpstreamTemplate = "/api/products/{productId}/variants/{variantId}", UpstreamTemplate = "/api/products/{productId}/variants/{variantId}",
DownstreamTemplate = "/products/{productId}", DownstreamTemplate = "/products/{productId}",
@ -187,7 +187,7 @@ namespace Ocelot.UnitTests.Configuration
} }
} }
})) }))
.And(x => x.GivenTheYamlConfigIsValid()) .And(x => x.GivenTheConfigIsValid())
.When(x => x.WhenICreateTheConfig()) .When(x => x.WhenICreateTheConfig())
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute> .Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
{ {
@ -204,11 +204,11 @@ namespace Ocelot.UnitTests.Configuration
[Fact] [Fact]
public void should_create_template_pattern_that_matches_more_than_one_placeholder_with_trailing_slash() public void should_create_template_pattern_that_matches_more_than_one_placeholder_with_trailing_slash()
{ {
this.Given(x => x.GivenTheYamlConfigIs(new YamlConfiguration this.Given(x => x.GivenTheConfigIs(new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
UpstreamTemplate = "/api/products/{productId}/variants/{variantId}/", UpstreamTemplate = "/api/products/{productId}/variants/{variantId}/",
DownstreamTemplate = "/products/{productId}", DownstreamTemplate = "/products/{productId}",
@ -216,7 +216,7 @@ namespace Ocelot.UnitTests.Configuration
} }
} }
})) }))
.And(x => x.GivenTheYamlConfigIsValid()) .And(x => x.GivenTheConfigIsValid())
.When(x => x.WhenICreateTheConfig()) .When(x => x.WhenICreateTheConfig())
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute> .Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
{ {
@ -233,11 +233,11 @@ namespace Ocelot.UnitTests.Configuration
[Fact] [Fact]
public void should_create_template_pattern_that_matches_to_end_of_string() public void should_create_template_pattern_that_matches_to_end_of_string()
{ {
this.Given(x => x.GivenTheYamlConfigIs(new YamlConfiguration this.Given(x => x.GivenTheConfigIs(new FileConfiguration
{ {
ReRoutes = new List<YamlReRoute> ReRoutes = new List<FileReRoute>
{ {
new YamlReRoute new FileReRoute
{ {
UpstreamTemplate = "/", UpstreamTemplate = "/",
DownstreamTemplate = "/api/products/", DownstreamTemplate = "/api/products/",
@ -245,7 +245,7 @@ namespace Ocelot.UnitTests.Configuration
} }
} }
})) }))
.And(x => x.GivenTheYamlConfigIsValid()) .And(x => x.GivenTheConfigIsValid())
.When(x => x.WhenICreateTheConfig()) .When(x => x.WhenICreateTheConfig())
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute> .Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
{ {
@ -259,19 +259,19 @@ namespace Ocelot.UnitTests.Configuration
.BDDfy(); .BDDfy();
} }
private void GivenTheYamlConfigIsValid() private void GivenTheConfigIsValid()
{ {
_validator _validator
.Setup(x => x.IsValid(It.IsAny<YamlConfiguration>())) .Setup(x => x.IsValid(It.IsAny<FileConfiguration>()))
.Returns(new OkResponse<ConfigurationValidationResult>(new ConfigurationValidationResult(false))); .Returns(new OkResponse<ConfigurationValidationResult>(new ConfigurationValidationResult(false)));
} }
private void GivenTheYamlConfigIs(YamlConfiguration yamlConfiguration) private void GivenTheConfigIs(FileConfiguration fileConfiguration)
{ {
_yamlConfiguration = yamlConfiguration; _fileConfiguration = fileConfiguration;
_yamlConfig _fileConfig
.Setup(x => x.Value) .Setup(x => x.Value)
.Returns(_yamlConfiguration); .Returns(_fileConfiguration);
} }
private void WhenICreateTheConfig() private void WhenICreateTheConfig()

View File

@ -15,14 +15,14 @@ using Xunit;
namespace Ocelot.UnitTests.Configuration namespace Ocelot.UnitTests.Configuration
{ {
public class YamlConfigurationProviderTests public class FileConfigurationProviderTests
{ {
private readonly IOcelotConfigurationProvider _ocelotConfigurationProvider; private readonly IOcelotConfigurationProvider _ocelotConfigurationProvider;
private readonly Mock<IOcelotConfigurationRepository> _configurationRepository; private readonly Mock<IOcelotConfigurationRepository> _configurationRepository;
private readonly Mock<IOcelotConfigurationCreator> _creator; private readonly Mock<IOcelotConfigurationCreator> _creator;
private Response<IOcelotConfiguration> _result; private Response<IOcelotConfiguration> _result;
public YamlConfigurationProviderTests() public FileConfigurationProviderTests()
{ {
_creator = new Mock<IOcelotConfigurationCreator>(); _creator = new Mock<IOcelotConfigurationCreator>();
_configurationRepository = new Mock<IOcelotConfigurationRepository>(); _configurationRepository = new Mock<IOcelotConfigurationRepository>();

View File

@ -14,7 +14,7 @@
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.AspNetCore.Http": "1.0.0", "Microsoft.AspNetCore.Http": "1.0.0",
"Ocelot": "1.0.0-*", "Ocelot": "1.0.0-*",
"xunit": "2.1.0", "xunit": "2.2.0-beta2-build3300",
"dotnet-test-xunit": "2.2.0-preview2-build1029", "dotnet-test-xunit": "2.2.0-preview2-build1029",
"Moq": "4.6.38-alpha", "Moq": "4.6.38-alpha",
"Microsoft.AspNetCore.TestHost": "1.0.0", "Microsoft.AspNetCore.TestHost": "1.0.0",
@ -25,15 +25,12 @@
"type": "platform" "type": "platform"
}, },
"Shouldly": "2.8.2", "Shouldly": "2.8.2",
"TestStack.BDDfy": "4.3.2", "TestStack.BDDfy": "4.3.2"
"YamlDotNet": "4.0.0"
}, },
"frameworks": { "frameworks": {
"netcoreapp1.4": { "netcoreapp1.4": {
"imports": [ "imports": [
"dotnet5.6",
"portable-net45+win8"
] ]
} }
} }