Skip to content

Commit

Permalink
Fix #53, avoid unexpected response when the request object is malformed
Browse files Browse the repository at this point in the history
  • Loading branch information
natenho committed Dec 13, 2020
1 parent ee36b77 commit d847083
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Mockaco/Middlewares/RequestMatchingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ IEnumerable<IRequestMatcher> requestMatchers
{
await LogHttpContext(httpContext);

AttachRequestToScriptContext(httpContext, mockacoContext, scriptContext);
await AttachRequestToScriptContext(httpContext, mockacoContext, scriptContext);

if (mockacoContext.Errors.Any())
{
Expand Down Expand Up @@ -65,11 +65,11 @@ IEnumerable<IRequestMatcher> requestMatchers
}

//TODO Remove redundant code
private void AttachRequestToScriptContext(HttpContext httpContext, IMockacoContext mockacoContext, IScriptContext scriptContext)
private async Task AttachRequestToScriptContext(HttpContext httpContext, IMockacoContext mockacoContext, IScriptContext scriptContext)
{
try
{
scriptContext.AttachRequest(httpContext.Request);
await scriptContext.AttachRequest(httpContext.Request);
}
catch (Exception ex)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Mockaco/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class Startup

public Startup(IConfiguration configuration)
{
_configuration = configuration;
_configuration = configuration;
}

public void ConfigureServices(IServiceCollection services)
Expand All @@ -29,7 +29,7 @@ public void ConfigureServices(IServiceCollection services)
.AddTransient<IGlobalVariableStorage, ScriptContextGlobalVariableStorage>()

.AddSingleton<IScriptRunnerFactory, ScriptRunnerFactory>()

.AddSingleton<IFakerFactory, LocalizedFakerFactory>()
.AddSingleton<IMockProvider, MockProvider>()
.AddSingleton<ITemplateProvider, TemplateFileProvider>()
Expand All @@ -40,9 +40,9 @@ public void ConfigureServices(IServiceCollection services)

.AddTransient<IRequestBodyFactory, RequestBodyFactory>()

.AddTransient<IRequestBodyStrategy, FormRequestBodyStrategy>()
.AddTransient<IRequestBodyStrategy, JsonRequestBodyStrategy>()
.AddTransient<IRequestBodyStrategy, XmlRequestBodyStrategy>()
.AddTransient<IRequestBodyStrategy, FormRequestBodyStrategy>()

.AddTransient<IResponseBodyFactory, ResponseBodyFactory>()

Expand Down
14 changes: 7 additions & 7 deletions src/Mockaco/Templating/Request/RequestConditionMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
namespace Mockaco
{
public class RequestConditionMatcher : IRequestMatcher
{
{
private readonly ITemplateTransformer _templateTransformer;
private readonly IFakerFactory _fakerFactory;
private readonly IRequestBodyFactory _requestBodyFactory;
private readonly IMockacoContext _mockacoContext;
private readonly IGlobalVariableStorage _globalVarialeStorage;
private readonly ILogger _logger;

public RequestConditionMatcher(
public RequestConditionMatcher(
ITemplateTransformer templateTransformer,
IFakerFactory fakerFactory,
IRequestBodyFactory requestBodyFactory,
IMockacoContext mockacoContext,
IGlobalVariableStorage globalVariableStoreage,
ILogger<RequestConditionMatcher> logger)
{
{
_templateTransformer = templateTransformer;
_fakerFactory = fakerFactory;
_requestBodyFactory = requestBodyFactory;
Expand All @@ -34,8 +34,8 @@ public RequestConditionMatcher(
public async Task<bool> IsMatch(HttpRequest httpRequest, Mock mock)
{
var conditionMatcherScriptContext = new ScriptContext(_fakerFactory, _requestBodyFactory, _globalVarialeStorage);

AttachRequestToScriptContext(httpRequest.HttpContext, _mockacoContext, conditionMatcherScriptContext);
await AttachRequestToScriptContext(httpRequest.HttpContext, _mockacoContext, conditionMatcherScriptContext);

if (_mockacoContext.Errors.Any())
{
Expand All @@ -52,11 +52,11 @@ public async Task<bool> IsMatch(HttpRequest httpRequest, Mock mock)
}

//TODO Remove redundant code
private void AttachRequestToScriptContext(HttpContext httpContext, IMockacoContext mockacoContext, IScriptContext scriptContext)
private async Task AttachRequestToScriptContext(HttpContext httpContext, IMockacoContext mockacoContext, IScriptContext scriptContext)
{
try
{
scriptContext.AttachRequest(httpContext.Request);
await scriptContext.AttachRequest(httpContext.Request);
}
catch (Exception ex)
{
Expand Down

0 comments on commit d847083

Please sign in to comment.