mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:52:51 +08:00
Added a get authentication test, removed the infrastructure name space as it seemed pointless, started thinking about how to pass claims on with the request
This commit is contained in:
parent
ce84ad4fc2
commit
3d60602c7e
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
namespace Ocelot.Library.Authentication
|
||||
{
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
public class AuthenticationHandler
|
||||
{
|
||||
public AuthenticationHandler(string provider, RequestDelegate handler)
|
@ -1,11 +1,11 @@
|
||||
using IdentityServer4.AccessTokenValidation;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
namespace Ocelot.Library.Authentication
|
||||
{
|
||||
using IdentityServer4.AccessTokenValidation;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Responses;
|
||||
using AuthenticationOptions = Configuration.AuthenticationOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Cannot unit test things in this class due to use of extension methods
|
||||
/// </summary>
|
@ -1,11 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
namespace Ocelot.Library.Authentication
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Errors;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Responses;
|
||||
using AuthenticationOptions = Configuration.AuthenticationOptions;
|
||||
|
||||
public class AuthenticationHandlerFactory : IAuthenticationHandlerFactory
|
||||
{
|
||||
private readonly IAuthenticationHandlerCreator _creator;
|
@ -0,0 +1,12 @@
|
||||
namespace Ocelot.Library.Authentication
|
||||
{
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Responses;
|
||||
using AuthenticationOptions = Configuration.AuthenticationOptions;
|
||||
|
||||
public interface IAuthenticationHandlerCreator
|
||||
{
|
||||
Response<RequestDelegate> CreateIdentityServerAuthenticationHandler(IApplicationBuilder app, AuthenticationOptions authOptions);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
namespace Ocelot.Library.Authentication
|
||||
{
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Responses;
|
||||
using AuthenticationOptions = Configuration.AuthenticationOptions;
|
||||
|
||||
public interface IAuthenticationHandlerFactory
|
||||
{
|
||||
Response<AuthenticationHandler> Get(IApplicationBuilder app, AuthenticationOptions authOptions);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
namespace Ocelot.Library.Authentication
|
||||
{
|
||||
public enum SupportAuthenticationProviders
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
namespace Ocelot.Library.Authentication
|
||||
{
|
||||
using Errors;
|
||||
|
||||
public class UnableToCreateAuthenticationHandlerError : Error
|
||||
{
|
||||
public UnableToCreateAuthenticationHandlerError(string message)
|
@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Builder
|
||||
namespace Ocelot.Library.Builder
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Configuration;
|
||||
|
||||
public class ReRouteBuilder
|
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration
|
||||
namespace Ocelot.Library.Configuration
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class AuthenticationOptions
|
||||
{
|
||||
public AuthenticationOptions(string provider, string providerRootUrl, string scopeName, bool requireHttps, List<string> additionalScopes, string scopeSecret)
|
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration
|
||||
namespace Ocelot.Library.Configuration
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public interface IOcelotConfiguration
|
||||
{
|
||||
List<ReRoute> ReRoutes { get; }
|
@ -1,9 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Ocelot.Library.Infrastructure.Configuration.Yaml;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration
|
||||
namespace Ocelot.Library.Configuration
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Yaml;
|
||||
|
||||
public class OcelotConfiguration : IOcelotConfiguration
|
||||
{
|
||||
private readonly IOptions<YamlConfiguration> _options;
|
@ -1,4 +1,4 @@
|
||||
namespace Ocelot.Library.Infrastructure.Configuration
|
||||
namespace Ocelot.Library.Configuration
|
||||
{
|
||||
public class ReRoute
|
||||
{
|
@ -1,9 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
|
||||
namespace Ocelot.Library.Configuration.Yaml
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Errors;
|
||||
|
||||
public class ConfigurationValidationResult
|
||||
{
|
||||
public ConfigurationValidationResult(bool isError)
|
@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ocelot.Library.Infrastructure.Authentication;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
|
||||
namespace Ocelot.Library.Configuration.Yaml
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Authentication;
|
||||
using Errors;
|
||||
using Responses;
|
||||
|
||||
public class ConfigurationValidator : IConfigurationValidator
|
||||
{
|
||||
public Response<ConfigurationValidationResult> IsValid(YamlConfiguration configuration)
|
@ -1,8 +1,7 @@
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
|
||||
namespace Ocelot.Library.Configuration.Yaml
|
||||
{
|
||||
using Errors;
|
||||
|
||||
public class DownstreamTemplateAlreadyUsedError : Error
|
||||
{
|
||||
public DownstreamTemplateAlreadyUsedError(string message) : base(message, OcelotErrorCode.DownstreamTemplateAlreadyUsedError)
|
@ -1,7 +1,7 @@
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
|
||||
namespace Ocelot.Library.Configuration.Yaml
|
||||
{
|
||||
using Responses;
|
||||
|
||||
public interface IConfigurationValidator
|
||||
{
|
||||
Response<ConfigurationValidationResult> IsValid(YamlConfiguration configuration);
|
@ -1,7 +1,7 @@
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
|
||||
namespace Ocelot.Library.Configuration.Yaml
|
||||
{
|
||||
using Errors;
|
||||
|
||||
public class UnsupportedAuthenticationProviderError : Error
|
||||
{
|
||||
public UnsupportedAuthenticationProviderError(string message)
|
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
|
||||
namespace Ocelot.Library.Configuration.Yaml
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class YamlAuthenticationOptions
|
||||
{
|
||||
public string Provider { get; set; }
|
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
|
||||
namespace Ocelot.Library.Configuration.Yaml
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class YamlConfiguration
|
||||
{
|
||||
public YamlConfiguration()
|
@ -1,4 +1,4 @@
|
||||
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
|
||||
namespace Ocelot.Library.Configuration.Yaml
|
||||
{
|
||||
public class YamlReRoute
|
||||
{
|
@ -0,0 +1,44 @@
|
||||
namespace Ocelot.Library.DependencyInjection
|
||||
{
|
||||
using Authentication;
|
||||
using Configuration;
|
||||
using Configuration.Yaml;
|
||||
using DownstreamRouteFinder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Repository;
|
||||
using RequestBuilder;
|
||||
using Requester;
|
||||
using Responder;
|
||||
using UrlMatcher;
|
||||
using UrlTemplateReplacer;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddOcelot(this IServiceCollection services, IConfigurationRoot configurationRoot)
|
||||
{
|
||||
services.Configure<YamlConfiguration>(configurationRoot);
|
||||
|
||||
// Add framework services.
|
||||
services.AddSingleton<IConfigurationValidator, ConfigurationValidator>();
|
||||
services.AddSingleton<IOcelotConfiguration, OcelotConfiguration>();
|
||||
services.AddSingleton<IUrlPathToUrlTemplateMatcher, RegExUrlMatcher>();
|
||||
services.AddSingleton<ITemplateVariableNameAndValueFinder, TemplateVariableNameAndValueFinder>();
|
||||
services.AddSingleton<IDownstreamUrlTemplateVariableReplacer, DownstreamUrlTemplateVariableReplacer>();
|
||||
services.AddSingleton<IDownstreamRouteFinder, DownstreamRouteFinder>();
|
||||
services.AddSingleton<IHttpRequester, HttpClientHttpRequester>();
|
||||
services.AddSingleton<IHttpResponder, HttpContextResponder>();
|
||||
services.AddSingleton<IRequestBuilder, HttpRequestBuilder>();
|
||||
services.AddSingleton<IErrorsToHttpStatusCodeMapper, ErrorsToHttpStatusCodeMapper>();
|
||||
services.AddSingleton<IAuthenticationHandlerFactory, AuthenticationHandlerFactory>();
|
||||
services.AddSingleton<IAuthenticationHandlerCreator, AuthenticationHandlerCreator>();
|
||||
|
||||
// see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
services.AddScoped<IScopedRequestDataRepository, ScopedRequestDataRepository>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
|
||||
namespace Ocelot.Library.DownstreamRouteFinder
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Configuration;
|
||||
using UrlMatcher;
|
||||
|
||||
public class DownstreamRoute
|
||||
{
|
@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Ocelot.Library.Infrastructure.Configuration;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
|
||||
namespace Ocelot.Library.DownstreamRouteFinder
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Configuration;
|
||||
using Errors;
|
||||
using Responses;
|
||||
using UrlMatcher;
|
||||
|
||||
public class DownstreamRouteFinder : IDownstreamRouteFinder
|
||||
{
|
||||
private readonly IOcelotConfiguration _configuration;
|
@ -1,7 +1,7 @@
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
|
||||
namespace Ocelot.Library.DownstreamRouteFinder
|
||||
{
|
||||
using Responses;
|
||||
|
||||
public interface IDownstreamRouteFinder
|
||||
{
|
||||
Response<DownstreamRoute> FindDownstreamRoute(string upstreamUrlPath, string upstreamHttpMethod);
|
@ -0,0 +1,11 @@
|
||||
namespace Ocelot.Library.DownstreamRouteFinder
|
||||
{
|
||||
using Errors;
|
||||
|
||||
public class UnableToFindDownstreamRouteError : Error
|
||||
{
|
||||
public UnableToFindDownstreamRouteError() : base("UnableToFindDownstreamRouteError", OcelotErrorCode.UnableToFindDownstreamRouteError)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace Ocelot.Library.Infrastructure.Errors
|
||||
namespace Ocelot.Library.Errors
|
||||
{
|
||||
public abstract class Error
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace Ocelot.Library.Infrastructure.Errors
|
||||
namespace Ocelot.Library.Errors
|
||||
{
|
||||
public enum OcelotErrorCode
|
||||
{
|
@ -1,12 +0,0 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
public interface IAuthenticationHandlerCreator
|
||||
{
|
||||
Response<RequestDelegate> CreateIdentityServerAuthenticationHandler(IApplicationBuilder app, AuthenticationOptions authOptions);
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Authentication
|
||||
{
|
||||
public interface IAuthenticationHandlerFactory
|
||||
{
|
||||
Response<AuthenticationHandler> Get(IApplicationBuilder app, AuthenticationOptions authOptions);
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
|
||||
{
|
||||
public class UnableToFindDownstreamRouteError : Error
|
||||
{
|
||||
public UnableToFindDownstreamRouteError() : base("UnableToFindDownstreamRouteError", OcelotErrorCode.UnableToFindDownstreamRouteError)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Requester
|
||||
{
|
||||
public interface IHttpRequester
|
||||
{
|
||||
Task<Response<HttpResponseMessage>> GetResponse(Request request);
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responder
|
||||
{
|
||||
public interface IErrorsToHttpStatusCodeMapper
|
||||
{
|
||||
Response<int> Map(List<Error> errors);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.UrlMatcher
|
||||
{
|
||||
public interface IUrlPathToUrlTemplateMatcher
|
||||
{
|
||||
Response<UrlMatch> Match(string upstreamUrlPath, string upstreamUrlPathTemplate);
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.UrlTemplateReplacer
|
||||
{
|
||||
public interface IDownstreamUrlTemplateVariableReplacer
|
||||
{
|
||||
Response<string> ReplaceTemplateVariables(DownstreamRoute downstreamRoute);
|
||||
}
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Authentication;
|
||||
using Ocelot.Library.Infrastructure.Configuration;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Authentication;
|
||||
using Configuration;
|
||||
using DownstreamRouteFinder;
|
||||
using Errors;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Repository;
|
||||
|
||||
public class AuthenticationMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
public static class AuthenticationMiddlewareMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseAuthenticationMiddleware(this IApplicationBuilder builder)
|
23
src/Ocelot.Library/Middleware/ClaimsParserMiddleware.cs
Normal file
23
src/Ocelot.Library/Middleware/ClaimsParserMiddleware.cs
Normal file
@ -0,0 +1,23 @@
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Repository;
|
||||
|
||||
public class ClaimsParserMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
|
||||
public ClaimsParserMiddleware(RequestDelegate next, IScopedRequestDataRepository scopedRequestDataRepository)
|
||||
: base(scopedRequestDataRepository)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
|
||||
await _next.Invoke(context);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
using DownstreamRouteFinder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Repository;
|
||||
|
||||
public class DownstreamRouteFinderMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
public static class DownstreamRouteFinderMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseDownstreamRouteFinderMiddleware(this IApplicationBuilder builder)
|
@ -1,11 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.UrlTemplateReplacer;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
using DownstreamRouteFinder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Repository;
|
||||
using UrlTemplateReplacer;
|
||||
|
||||
public class DownstreamUrlCreatorMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
public static class DownstreamUrlCreatorMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseDownstreamUrlCreatorMiddleware(this IApplicationBuilder builder)
|
@ -1,10 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Repository;
|
||||
using RequestBuilder;
|
||||
|
||||
public class HttpRequestBuilderMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
public static class HttpRequestBuilderMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseHttpRequestBuilderMiddleware(this IApplicationBuilder builder)
|
@ -1,11 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
using Ocelot.Library.Infrastructure.Requester;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Repository;
|
||||
using RequestBuilder;
|
||||
using Requester;
|
||||
|
||||
public class HttpRequesterMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
public static class HttpRequesterMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseHttpRequesterMiddleware(this IApplicationBuilder builder)
|
@ -1,11 +1,11 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.Responder;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Repository;
|
||||
using Responder;
|
||||
|
||||
public class HttpResponderMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
public static class HttpResponderMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseHttpResponderMiddleware(this IApplicationBuilder builder)
|
@ -1,10 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Errors;
|
||||
using Repository;
|
||||
|
||||
public abstract class OcelotMiddleware
|
||||
{
|
||||
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
|
24
src/Ocelot.Library/Middleware/OcelotMiddlewareExtensions.cs
Normal file
24
src/Ocelot.Library/Middleware/OcelotMiddlewareExtensions.cs
Normal file
@ -0,0 +1,24 @@
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
public static class OcelotMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseOcelot(this IApplicationBuilder builder)
|
||||
{
|
||||
builder.UseHttpResponderMiddleware();
|
||||
|
||||
builder.UseDownstreamRouteFinderMiddleware();
|
||||
|
||||
builder.UseAuthenticationMiddleware();
|
||||
|
||||
builder.UseDownstreamUrlCreatorMiddleware();
|
||||
|
||||
builder.UseHttpRequestBuilderMiddleware();
|
||||
|
||||
builder.UseHttpRequesterMiddleware();
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Middleware
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using Errors;
|
||||
|
||||
public class UnauthenticatedError : Error
|
||||
{
|
||||
public UnauthenticatedError(string message) : base(message, OcelotErrorCode.UnauthenticatedError)
|
@ -1,8 +1,7 @@
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Repository
|
||||
namespace Ocelot.Library.Repository
|
||||
{
|
||||
using Errors;
|
||||
|
||||
public class CannotAddDataError : Error
|
||||
{
|
||||
public CannotAddDataError(string message) : base(message, OcelotErrorCode.CannotAddDataError)
|
@ -1,8 +1,7 @@
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Repository
|
||||
namespace Ocelot.Library.Repository
|
||||
{
|
||||
using Errors;
|
||||
|
||||
public class CannotFindDataError : Error
|
||||
{
|
||||
public CannotFindDataError(string message) : base(message, OcelotErrorCode.CannotFindDataError)
|
@ -1,7 +1,7 @@
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Repository
|
||||
namespace Ocelot.Library.Repository
|
||||
{
|
||||
using Responses;
|
||||
|
||||
public interface IScopedRequestDataRepository
|
||||
{
|
||||
Response Add<T>(string key, T value);
|
@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Repository
|
||||
namespace Ocelot.Library.Repository
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Errors;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Responses;
|
||||
|
||||
public class ScopedRequestDataRepository : IScopedRequestDataRepository
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.RequestBuilder
|
||||
namespace Ocelot.Library.RequestBuilder
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Responses;
|
||||
|
||||
public class HttpRequestBuilder : IRequestBuilder
|
||||
{
|
||||
public async Task<Response<Request>> Build(string httpMethod, string downstreamUrl, Stream content, IHeaderDictionary headers,
|
@ -1,10 +1,10 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.RequestBuilder
|
||||
namespace Ocelot.Library.RequestBuilder
|
||||
{
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Responses;
|
||||
|
||||
public interface IRequestBuilder
|
||||
{
|
||||
Task<Response<Request>> Build(string httpMethod,
|
@ -1,8 +1,8 @@
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.RequestBuilder
|
||||
namespace Ocelot.Library.RequestBuilder
|
||||
{
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
||||
public class Request
|
||||
{
|
||||
public Request(HttpRequestMessage httpRequestMessage, CookieContainer cookieContainer)
|
@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Requester
|
||||
namespace Ocelot.Library.Requester
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Errors;
|
||||
using RequestBuilder;
|
||||
using Responses;
|
||||
|
||||
public class HttpClientHttpRequester : IHttpRequester
|
||||
{
|
||||
public async Task<Response<HttpResponseMessage>> GetResponse(Request request)
|
12
src/Ocelot.Library/Requester/IHttpRequester.cs
Normal file
12
src/Ocelot.Library/Requester/IHttpRequester.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace Ocelot.Library.Requester
|
||||
{
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using RequestBuilder;
|
||||
using Responses;
|
||||
|
||||
public interface IHttpRequester
|
||||
{
|
||||
Task<Response<HttpResponseMessage>> GetResponse(Request request);
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Requester
|
||||
namespace Ocelot.Library.Requester
|
||||
{
|
||||
using System;
|
||||
using Errors;
|
||||
|
||||
public class UnableToCompleteRequestError : Error
|
||||
{
|
||||
public UnableToCompleteRequestError(Exception exception)
|
@ -1,10 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responder
|
||||
namespace Ocelot.Library.Responder
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Errors;
|
||||
using Responses;
|
||||
|
||||
public class ErrorsToHttpStatusCodeMapper : IErrorsToHttpStatusCodeMapper
|
||||
{
|
||||
public Response<int> Map(List<Error> errors)
|
@ -1,9 +1,9 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responder
|
||||
namespace Ocelot.Library.Responder
|
||||
{
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
/// <summary>
|
||||
/// Cannot unit test things in this class due to methods not being implemented
|
||||
/// on .net concretes used for testing
|
@ -0,0 +1,11 @@
|
||||
namespace Ocelot.Library.Responder
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Errors;
|
||||
using Responses;
|
||||
|
||||
public interface IErrorsToHttpStatusCodeMapper
|
||||
{
|
||||
Response<int> Map(List<Error> errors);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responder
|
||||
namespace Ocelot.Library.Responder
|
||||
{
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
public interface IHttpResponder
|
||||
{
|
||||
Task<HttpContext> CreateResponse(HttpContext context, HttpResponseMessage response);
|
@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
namespace Ocelot.Library.Responses
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Errors;
|
||||
|
||||
public class ErrorResponse : Response
|
||||
{
|
||||
public ErrorResponse(List<Error> errors) : base(errors)
|
@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
namespace Ocelot.Library.Responses
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Errors;
|
||||
|
||||
public class ErrorResponse<T> : Response<T>
|
||||
{
|
||||
public ErrorResponse(List<Error> errors) : base(errors)
|
@ -1,4 +1,4 @@
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
namespace Ocelot.Library.Responses
|
||||
{
|
||||
public class OkResponse : Response
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
namespace Ocelot.Library.Responses
|
||||
{
|
||||
public class OkResponse<T> : Response<T>
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
namespace Ocelot.Library.Responses
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Errors;
|
||||
|
||||
public abstract class Response
|
||||
{
|
||||
protected Response()
|
@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
namespace Ocelot.Library.Responses
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Errors;
|
||||
|
||||
public abstract class Response<T> : Response
|
||||
{
|
||||
protected Response(T data)
|
@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.UrlMatcher
|
||||
namespace Ocelot.Library.UrlMatcher
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Responses;
|
||||
|
||||
public interface ITemplateVariableNameAndValueFinder
|
||||
{
|
||||
Response<List<TemplateVariableNameAndValue>> Find(string upstreamUrlPath, string upstreamUrlPathTemplate);
|
@ -0,0 +1,9 @@
|
||||
namespace Ocelot.Library.UrlMatcher
|
||||
{
|
||||
using Responses;
|
||||
|
||||
public interface IUrlPathToUrlTemplateMatcher
|
||||
{
|
||||
Response<UrlMatch> Match(string upstreamUrlPath, string upstreamUrlPathTemplate);
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.UrlMatcher
|
||||
namespace Ocelot.Library.UrlMatcher
|
||||
{
|
||||
using System.Text.RegularExpressions;
|
||||
using Responses;
|
||||
|
||||
public class RegExUrlMatcher : IUrlPathToUrlTemplateMatcher
|
||||
{
|
||||
public Response<UrlMatch> Match(string upstreamUrlPath, string upstreamUrlPathTemplate)
|
@ -1,4 +1,4 @@
|
||||
namespace Ocelot.Library.Infrastructure.UrlMatcher
|
||||
namespace Ocelot.Library.UrlMatcher
|
||||
{
|
||||
public class TemplateVariableNameAndValue
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.UrlMatcher
|
||||
namespace Ocelot.Library.UrlMatcher
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Responses;
|
||||
|
||||
public class TemplateVariableNameAndValueFinder : ITemplateVariableNameAndValueFinder
|
||||
{
|
||||
public Response<List<TemplateVariableNameAndValue>> Find(string upstreamUrlPath, string upstreamUrlPathTemplate)
|
@ -1,4 +1,4 @@
|
||||
namespace Ocelot.Library.Infrastructure.UrlMatcher
|
||||
namespace Ocelot.Library.UrlMatcher
|
||||
{
|
||||
public class UrlMatch
|
||||
{
|
@ -1,9 +1,9 @@
|
||||
using System.Text;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.UrlTemplateReplacer
|
||||
namespace Ocelot.Library.UrlTemplateReplacer
|
||||
{
|
||||
using System.Text;
|
||||
using DownstreamRouteFinder;
|
||||
using Responses;
|
||||
|
||||
public class DownstreamUrlTemplateVariableReplacer : IDownstreamUrlTemplateVariableReplacer
|
||||
{
|
||||
public Response<string> ReplaceTemplateVariables(DownstreamRoute downstreamRoute)
|
@ -0,0 +1,10 @@
|
||||
namespace Ocelot.Library.UrlTemplateReplacer
|
||||
{
|
||||
using DownstreamRouteFinder;
|
||||
using Responses;
|
||||
|
||||
public interface IDownstreamUrlTemplateVariableReplacer
|
||||
{
|
||||
Response<string> ReplaceTemplateVariables(DownstreamRoute downstreamRoute);
|
||||
}
|
||||
}
|
@ -1,26 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Ocelot.Library.Infrastructure.Authentication;
|
||||
using Ocelot.Library.Infrastructure.Configuration;
|
||||
using Ocelot.Library.Infrastructure.Configuration.Yaml;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
using Ocelot.Library.Infrastructure.Requester;
|
||||
using Ocelot.Library.Infrastructure.Responder;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
using Ocelot.Library.Infrastructure.UrlTemplateReplacer;
|
||||
|
||||
namespace Ocelot
|
||||
{
|
||||
using Library.DependencyInjection;
|
||||
using Library.Middleware;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env)
|
||||
@ -45,26 +33,7 @@ namespace Ocelot
|
||||
services.AddMvcCore().AddAuthorization().AddJsonFormatters();
|
||||
services.AddAuthentication();
|
||||
services.AddLogging();
|
||||
|
||||
services.Configure<YamlConfiguration>(Configuration);
|
||||
|
||||
// Add framework services.
|
||||
services.AddSingleton<IConfigurationValidator, ConfigurationValidator>();
|
||||
services.AddSingleton<IOcelotConfiguration, OcelotConfiguration>();
|
||||
services.AddSingleton<IUrlPathToUrlTemplateMatcher, RegExUrlMatcher>();
|
||||
services.AddSingleton<ITemplateVariableNameAndValueFinder, TemplateVariableNameAndValueFinder>();
|
||||
services.AddSingleton<IDownstreamUrlTemplateVariableReplacer, DownstreamUrlTemplateVariableReplacer>();
|
||||
services.AddSingleton<IDownstreamRouteFinder, DownstreamRouteFinder>();
|
||||
services.AddSingleton<IHttpRequester, HttpClientHttpRequester>();
|
||||
services.AddSingleton<IHttpResponder, HttpContextResponder>();
|
||||
services.AddSingleton<IRequestBuilder, HttpRequestBuilder>();
|
||||
services.AddSingleton<IErrorsToHttpStatusCodeMapper, ErrorsToHttpStatusCodeMapper>();
|
||||
services.AddSingleton<IAuthenticationHandlerFactory, AuthenticationHandlerFactory>();
|
||||
services.AddSingleton<IAuthenticationHandlerCreator, AuthenticationHandlerCreator>();
|
||||
|
||||
// see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
services.AddScoped<IScopedRequestDataRepository, ScopedRequestDataRepository>();
|
||||
services.AddOcelot(Configuration);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
@ -74,17 +43,7 @@ namespace Ocelot
|
||||
|
||||
loggerFactory.AddDebug();
|
||||
|
||||
app.UseHttpResponderMiddleware();
|
||||
|
||||
app.UseDownstreamRouteFinderMiddleware();
|
||||
|
||||
app.UseAuthenticationMiddleware();
|
||||
|
||||
app.UseDownstreamUrlCreatorMiddleware();
|
||||
|
||||
app.UseHttpRequestBuilderMiddleware();
|
||||
|
||||
app.UseHttpRequesterMiddleware();
|
||||
app.UseOcelot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Newtonsoft.Json;
|
||||
using Ocelot.Library.Infrastructure.Configuration.Yaml;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
@ -21,6 +20,9 @@ using YamlDotNet.Serialization;
|
||||
|
||||
namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
using System.Security.Claims;
|
||||
using Library.Configuration.Yaml;
|
||||
|
||||
public class AuthenticationTests : IDisposable
|
||||
{
|
||||
private TestServer _ocelotServer;
|
||||
@ -28,7 +30,7 @@ namespace Ocelot.AcceptanceTests
|
||||
private HttpResponseMessage _response;
|
||||
private readonly string _configurationPath;
|
||||
private StringContent _postContent;
|
||||
private IWebHost _ocelotBbuilder;
|
||||
private IWebHost _servicebuilder;
|
||||
|
||||
// Sadly we need to change this when we update the netcoreapp version to make the test update the config correctly
|
||||
private double _netCoreAppVersion = 1.4;
|
||||
@ -106,6 +108,42 @@ namespace Ocelot.AcceptanceTests
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_using_identity_server()
|
||||
{
|
||||
|
||||
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.GivenIHaveAToken("http://localhost:51888"))
|
||||
.And(x => x.GivenThereIsAConfiguration(new YamlConfiguration
|
||||
{
|
||||
ReRoutes = new List<YamlReRoute>
|
||||
{
|
||||
new YamlReRoute
|
||||
{
|
||||
DownstreamTemplate = "http://localhost:51876/",
|
||||
UpstreamTemplate = "/",
|
||||
UpstreamHttpMethod = "Get",
|
||||
AuthenticationOptions = new YamlAuthenticationOptions
|
||||
{
|
||||
AdditionalScopes = new List<string>(),
|
||||
Provider = "IdentityServer",
|
||||
ProviderRootUrl = "http://localhost:51888",
|
||||
RequireHttps = false,
|
||||
ScopeName = "api",
|
||||
ScopeSecret = "secret"
|
||||
}
|
||||
}
|
||||
}
|
||||
}))
|
||||
.And(x => x.GivenTheApiGatewayIsRunning())
|
||||
.And(x => x.GivenIHaveAddedATokenToMyRequest())
|
||||
.When(x => x.WhenIGetUrlOnTheApiGateway("/"))
|
||||
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => x.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_201_using_identity_server_access_token()
|
||||
{
|
||||
@ -176,6 +214,21 @@ namespace Ocelot.AcceptanceTests
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void WhenIGetUrlOnTheApiGateway(string url)
|
||||
{
|
||||
_response = _ocelotClient.GetAsync(url).Result;
|
||||
}
|
||||
|
||||
private void WhenIPostUrlOnTheApiGateway(string url)
|
||||
{
|
||||
_response = _ocelotClient.PostAsync(url, _postContent).Result;
|
||||
}
|
||||
|
||||
private void ThenTheResponseBodyShouldBe(string expectedBody)
|
||||
{
|
||||
_response.Content.ReadAsStringAsync().Result.ShouldBe(expectedBody);
|
||||
}
|
||||
|
||||
private void GivenThePostHasContent(string postcontent)
|
||||
{
|
||||
_postContent = new StringContent(postcontent);
|
||||
@ -209,7 +262,7 @@ namespace Ocelot.AcceptanceTests
|
||||
|
||||
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody)
|
||||
{
|
||||
_ocelotBbuilder = new WebHostBuilder()
|
||||
_servicebuilder = new WebHostBuilder()
|
||||
.UseUrls(url)
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
@ -225,7 +278,7 @@ namespace Ocelot.AcceptanceTests
|
||||
})
|
||||
.Build();
|
||||
|
||||
_ocelotBbuilder.Start();
|
||||
_servicebuilder.Start();
|
||||
}
|
||||
|
||||
private void GivenThereIsAnIdentityServerOn(string url, string scopeName, AccessTokenType tokenType)
|
||||
@ -240,7 +293,9 @@ namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
services.AddLogging();
|
||||
services.AddDeveloperIdentityServer()
|
||||
.AddInMemoryScopes(new List<Scope> { new Scope
|
||||
.AddInMemoryScopes(new List<Scope>
|
||||
{
|
||||
new Scope
|
||||
{
|
||||
Name = scopeName,
|
||||
Description = "My API",
|
||||
@ -253,25 +308,34 @@ namespace Ocelot.AcceptanceTests
|
||||
Value = "secret".Sha256()
|
||||
}
|
||||
}
|
||||
}})
|
||||
.AddInMemoryClients(new List<Client> {
|
||||
},
|
||||
|
||||
StandardScopes.OpenId,
|
||||
StandardScopes.OfflineAccess
|
||||
})
|
||||
.AddInMemoryClients(new List<Client>
|
||||
{
|
||||
new Client
|
||||
{
|
||||
ClientId = "client",
|
||||
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
|
||||
ClientSecrets = new List<Secret> { new Secret("secret".Sha256()) },
|
||||
AllowedScopes = new List<string> { scopeName },
|
||||
ClientSecrets = new List<Secret> {new Secret("secret".Sha256())},
|
||||
AllowedScopes = new List<string> { scopeName, "openid", "offline_access" },
|
||||
AccessTokenType = tokenType,
|
||||
Enabled = true,
|
||||
RequireClientSecret = false
|
||||
} })
|
||||
.AddInMemoryUsers(new List<InMemoryUser> { new InMemoryUser
|
||||
}
|
||||
})
|
||||
.AddInMemoryUsers(new List<InMemoryUser>
|
||||
{
|
||||
new InMemoryUser
|
||||
{
|
||||
Username = "test",
|
||||
Password = "test",
|
||||
Enabled = true,
|
||||
Subject = "asdads"
|
||||
}});
|
||||
}
|
||||
});
|
||||
})
|
||||
.Configure(app =>
|
||||
{
|
||||
@ -322,11 +386,6 @@ namespace Ocelot.AcceptanceTests
|
||||
_ocelotClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.AccessToken);
|
||||
}
|
||||
|
||||
private void WhenIPostUrlOnTheApiGateway(string url)
|
||||
{
|
||||
_response = _ocelotClient.PostAsync(url, _postContent).Result;
|
||||
}
|
||||
|
||||
private void ThenTheStatusCodeShouldBe(HttpStatusCode expectedHttpStatusCode)
|
||||
{
|
||||
_response.StatusCode.ShouldBe(expectedHttpStatusCode);
|
||||
@ -334,7 +393,7 @@ namespace Ocelot.AcceptanceTests
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_ocelotBbuilder?.Dispose();
|
||||
_servicebuilder?.Dispose();
|
||||
_ocelotClient?.Dispose();
|
||||
_ocelotServer?.Dispose();
|
||||
_identityServerBuilder?.Dispose();
|
||||
|
@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Ocelot.Library.Infrastructure.Configuration.Yaml;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
@ -15,6 +14,8 @@ using YamlDotNet.Serialization;
|
||||
|
||||
namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
using Library.Configuration.Yaml;
|
||||
|
||||
public class OcelotTests : IDisposable
|
||||
{
|
||||
private TestServer _server;
|
||||
|
@ -3,21 +3,23 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Authentication;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Authentication
|
||||
{
|
||||
using Library.Authentication;
|
||||
using Library.Configuration;
|
||||
using Library.Errors;
|
||||
using Library.Responses;
|
||||
|
||||
public class AuthenticationHandlerFactoryTests
|
||||
{
|
||||
private readonly IAuthenticationHandlerFactory _authenticationHandlerFactory;
|
||||
private readonly Mock<IApplicationBuilder> _app;
|
||||
private readonly Mock<IAuthenticationHandlerCreator> _creator;
|
||||
private Library.Infrastructure.Configuration.AuthenticationOptions _authenticationOptions;
|
||||
private AuthenticationOptions _authenticationOptions;
|
||||
private Response<AuthenticationHandler> _result;
|
||||
|
||||
public AuthenticationHandlerFactoryTests()
|
||||
@ -30,7 +32,7 @@ namespace Ocelot.UnitTests.Authentication
|
||||
[Fact]
|
||||
public void should_return_identity_server_access_token_handler()
|
||||
{
|
||||
this.Given(x => x.GivenTheAuthenticationOptionsAre(new Library.Infrastructure.Configuration.AuthenticationOptions("IdentityServer", "","",false, new List<string>(), "")))
|
||||
this.Given(x => x.GivenTheAuthenticationOptionsAre(new AuthenticationOptions("IdentityServer", "","",false, new List<string>(), "")))
|
||||
.And(x => x.GivenTheCreatorReturns())
|
||||
.When(x => x.WhenIGetFromTheFactory())
|
||||
.Then(x => x.ThenTheHandlerIsReturned("IdentityServer"))
|
||||
@ -40,14 +42,14 @@ namespace Ocelot.UnitTests.Authentication
|
||||
[Fact]
|
||||
public void should_return_error_if_cannot_create_handler()
|
||||
{
|
||||
this.Given(x => x.GivenTheAuthenticationOptionsAre(new Library.Infrastructure.Configuration.AuthenticationOptions("IdentityServer", "", "", false, new List<string>(), "")))
|
||||
this.Given(x => x.GivenTheAuthenticationOptionsAre(new AuthenticationOptions("IdentityServer", "", "", false, new List<string>(), "")))
|
||||
.And(x => x.GivenTheCreatorReturnsAnError())
|
||||
.When(x => x.WhenIGetFromTheFactory())
|
||||
.Then(x => x.ThenAnErrorResponseIsReturned())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheAuthenticationOptionsAre(Library.Infrastructure.Configuration.AuthenticationOptions authenticationOptions)
|
||||
private void GivenTheAuthenticationOptionsAre(AuthenticationOptions authenticationOptions)
|
||||
{
|
||||
_authenticationOptions = authenticationOptions;
|
||||
}
|
||||
@ -55,7 +57,7 @@ namespace Ocelot.UnitTests.Authentication
|
||||
private void GivenTheCreatorReturnsAnError()
|
||||
{
|
||||
_creator
|
||||
.Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny<IApplicationBuilder>(), It.IsAny<Library.Infrastructure.Configuration.AuthenticationOptions>()))
|
||||
.Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny<IApplicationBuilder>(), It.IsAny<AuthenticationOptions>()))
|
||||
.Returns(new ErrorResponse<RequestDelegate>(new List<Error>
|
||||
{
|
||||
new UnableToCreateAuthenticationHandlerError($"Unable to create authentication handler for xxx")
|
||||
@ -65,7 +67,7 @@ namespace Ocelot.UnitTests.Authentication
|
||||
private void GivenTheCreatorReturns()
|
||||
{
|
||||
_creator
|
||||
.Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny<IApplicationBuilder>(), It.IsAny<Library.Infrastructure.Configuration.AuthenticationOptions>()))
|
||||
.Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny<IApplicationBuilder>(), It.IsAny<AuthenticationOptions>()))
|
||||
.Returns(new OkResponse<RequestDelegate>(x => Task.CompletedTask));
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Configuration.Yaml;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
using Library.Configuration.Yaml;
|
||||
using Library.Responses;
|
||||
|
||||
public class ConfigurationValidationTests
|
||||
{
|
||||
private YamlConfiguration _yamlConfiguration;
|
||||
|
@ -1,16 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Builder;
|
||||
using Ocelot.Library.Infrastructure.Configuration;
|
||||
using Ocelot.Library.Infrastructure.Configuration.Yaml;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
using Library.Builder;
|
||||
using Library.Configuration;
|
||||
using Library.Configuration.Yaml;
|
||||
using Library.Responses;
|
||||
|
||||
public class OcelotConfigurationTests
|
||||
{
|
||||
private readonly Mock<IOptions<YamlConfiguration>> _yamlConfig;
|
||||
|
@ -1,16 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Builder;
|
||||
using Ocelot.Library.Infrastructure.Configuration;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
using Library.Builder;
|
||||
using Library.Configuration;
|
||||
using Library.DownstreamRouteFinder;
|
||||
using Library.Responses;
|
||||
using Library.UrlMatcher;
|
||||
|
||||
public class DownstreamRouteFinderTests
|
||||
{
|
||||
private readonly IDownstreamRouteFinder _downstreamRouteFinder;
|
||||
@ -28,7 +29,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
_mockConfig = new Mock<IOcelotConfiguration>();
|
||||
_mockMatcher = new Mock<IUrlPathToUrlTemplateMatcher>();
|
||||
_finder = new Mock<ITemplateVariableNameAndValueFinder>();
|
||||
_downstreamRouteFinder = new Library.Infrastructure.DownstreamRouteFinder.DownstreamRouteFinder(_mockConfig.Object, _mockMatcher.Object, _finder.Object);
|
||||
_downstreamRouteFinder = new DownstreamRouteFinder(_mockConfig.Object, _mockMatcher.Object, _finder.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -6,19 +6,18 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Authentication;
|
||||
using Ocelot.Library.Infrastructure.Builder;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
using Library.Infrastructure.Configuration;
|
||||
using Library.Authentication;
|
||||
using Library.Builder;
|
||||
using Library.DownstreamRouteFinder;
|
||||
using Library.Middleware;
|
||||
using Library.Repository;
|
||||
using Library.Responses;
|
||||
using Library.UrlMatcher;
|
||||
|
||||
public class AuthenticationMiddlewareTests : IDisposable
|
||||
{
|
||||
|
@ -6,17 +6,18 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Builder;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
using Library.Builder;
|
||||
using Library.DownstreamRouteFinder;
|
||||
using Library.Middleware;
|
||||
using Library.Repository;
|
||||
using Library.Responses;
|
||||
using Library.UrlMatcher;
|
||||
|
||||
public class DownstreamRouteFinderMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IDownstreamRouteFinder> _downstreamRouteFinder;
|
||||
|
@ -1,18 +1,16 @@
|
||||
using Ocelot.Library.Infrastructure.Builder;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Library.Infrastructure.Configuration;
|
||||
using Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Library.Infrastructure.Repository;
|
||||
using Library.Infrastructure.Responses;
|
||||
using Library.Infrastructure.UrlMatcher;
|
||||
using Library.Infrastructure.UrlTemplateReplacer;
|
||||
using Library.Builder;
|
||||
using Library.DownstreamRouteFinder;
|
||||
using Library.Middleware;
|
||||
using Library.Repository;
|
||||
using Library.Responses;
|
||||
using Library.UrlMatcher;
|
||||
using Library.UrlTemplateReplacer;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
@ -7,15 +7,16 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
using Library.Middleware;
|
||||
using Library.Repository;
|
||||
using Library.RequestBuilder;
|
||||
using Library.Responses;
|
||||
|
||||
public class HttpRequestBuilderMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IRequestBuilder> _requestBuilder;
|
||||
|
@ -6,16 +6,17 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
using Ocelot.Library.Infrastructure.Requester;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
using Library.Middleware;
|
||||
using Library.Repository;
|
||||
using Library.RequestBuilder;
|
||||
using Library.Requester;
|
||||
using Library.Responses;
|
||||
|
||||
public class HttpRequesterMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IHttpRequester> _requester;
|
||||
|
@ -6,15 +6,16 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.Responder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
using Library.Middleware;
|
||||
using Library.Repository;
|
||||
using Library.Responder;
|
||||
using Library.Responses;
|
||||
|
||||
public class HttpResponderMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IHttpResponder> _responder;
|
||||
|
@ -1,12 +1,13 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Repository
|
||||
{
|
||||
using Library.Repository;
|
||||
using Library.Responses;
|
||||
|
||||
public class ScopedRequestDataRepositoryTests
|
||||
{
|
||||
private IScopedRequestDataRepository _scopedRequestDataRepository;
|
||||
|
@ -5,14 +5,15 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Internal;
|
||||
using Ocelot.Library.Infrastructure.RequestBuilder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.RequestBuilder
|
||||
{
|
||||
using Library.RequestBuilder;
|
||||
using Library.Responses;
|
||||
|
||||
public class RequestBuilderTests
|
||||
{
|
||||
private string _httpMethod;
|
||||
@ -28,7 +29,7 @@ namespace Ocelot.UnitTests.RequestBuilder
|
||||
public RequestBuilderTests()
|
||||
{
|
||||
_content = new StringContent(string.Empty);
|
||||
_requestBuilder = new Library.Infrastructure.RequestBuilder.HttpRequestBuilder();
|
||||
_requestBuilder = new HttpRequestBuilder();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -2,16 +2,17 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Library.Infrastructure.Errors;
|
||||
using Ocelot.Library.Infrastructure.Middleware;
|
||||
using Ocelot.Library.Infrastructure.Responder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Responder
|
||||
{
|
||||
using Library.Errors;
|
||||
using Library.Middleware;
|
||||
using Library.Responder;
|
||||
using Library.Responses;
|
||||
|
||||
public class ErrorsToHttpStatusCodeMapperTests
|
||||
{
|
||||
private readonly IErrorsToHttpStatusCodeMapper _codeMapper;
|
||||
|
@ -1,11 +1,12 @@
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.UrlMatcher
|
||||
{
|
||||
using Library.Responses;
|
||||
using Library.UrlMatcher;
|
||||
|
||||
public class RegExUrlMatcherTests
|
||||
{
|
||||
private readonly IUrlPathToUrlTemplateMatcher _urlMatcher;
|
||||
|
@ -1,13 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.UrlMatcher
|
||||
{
|
||||
using Library.Responses;
|
||||
using Library.UrlMatcher;
|
||||
|
||||
public class UrlPathToUrlTemplateMatcherTests
|
||||
{
|
||||
private readonly ITemplateVariableNameAndValueFinder _finder;
|
||||
|
@ -1,16 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Builder;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
using Ocelot.Library.Infrastructure.UrlMatcher;
|
||||
using Ocelot.Library.Infrastructure.UrlTemplateReplacer;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.UrlTemplateReplacer
|
||||
{
|
||||
using Library.Infrastructure.Configuration;
|
||||
using Library.Builder;
|
||||
using Library.DownstreamRouteFinder;
|
||||
using Library.Responses;
|
||||
using Library.UrlMatcher;
|
||||
using Library.UrlTemplateReplacer;
|
||||
|
||||
public class UpstreamUrlPathTemplateVariableReplacerTests
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user