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 21, 2016
1 parent f129324 commit e1fbc62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ 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);
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 e1fbc62

Please sign in to comment.