Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

Commit

Permalink
#141 Require the MSAspNetCoreToken or send a 400.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Apr 22, 2016
1 parent 4d24efc commit fcdf8dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public async Task Invoke(HttpContext httpContext)
{
if (!string.Equals(_pairingToken, httpContext.Request.Headers[MSAspNetCoreToken], StringComparison.Ordinal))
{
_logger.LogTrace($"'{MSAspNetCoreToken}' does not match the expected pairing token '{_pairingToken}', skipping {nameof(IISMiddleware)}.");
await _next(httpContext);
_logger.LogError($"'{MSAspNetCoreToken}' does not match the expected pairing token '{_pairingToken}', request rejected.");
httpContext.Response.StatusCode = 400;
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -38,12 +39,13 @@ public async Task MiddlewareSkippedIfTokenIsMissing()

var req = new HttpRequestMessage(HttpMethod.Get, "");
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
await server.CreateClient().SendAsync(req);
var response = await server.CreateClient().SendAsync(req);
Assert.True(assertsExecuted);
response.EnsureSuccessStatusCode();
}

[Fact]
public async Task MiddlewareSkippedIfTokenHeaderIsMissing()
public async Task MiddlewareRejectsRequestIfTokenHeaderIsMissing()
{
var assertsExecuted = false;

Expand All @@ -65,8 +67,9 @@ public async Task MiddlewareSkippedIfTokenHeaderIsMissing()
var server = new TestServer(builder);

var req = new HttpRequestMessage(HttpMethod.Get, "");
await server.CreateClient().SendAsync(req);
Assert.True(assertsExecuted);
var response = await server.CreateClient().SendAsync(req);
Assert.False(assertsExecuted);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}

[Fact]
Expand Down

0 comments on commit fcdf8dd

Please sign in to comment.