Skip to content

Commit

Permalink
Check that Content-Type is correct before accessing the Form (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcliment authored and 304NotModified committed Oct 4, 2018
1 parent 7088c9f commit 3ebb807
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ namespace NLog.Web.Tests.LayoutRenderers
{
public class AspNetRequestFormLayoutRendererTests : TestInvolvingAspNetHttpContext
{
[Fact]
public void ShouldReturnEmptyForNonValidContentTypes()
{
// Arrange
var expectedResult = "";
#if ASP_NET_CORE
var httpContext = this.HttpContext;
#else
var httpContext = Substitute.For<HttpContextBase>();
#endif
var renderer = new AspNetRequestFormLayoutRenderer
{
HttpContextAccessor = new FakeHttpContextAccessor(httpContext)
};

// Act
string result = renderer.Render(new LogEventInfo());

// Assert
Assert.Equal(expectedResult, result);
}

[Fact]
public void ShouldReturnEmptyIfFormCollectionIsEmpty()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ private IEnumerable<KeyValuePair<string, string>> GetPairsToInclude()
var httpRequest = HttpContextAccessor?.HttpContext?.TryGetRequest();
var pairs = new List<KeyValuePair<string, string>>();

#if ASP_NET_CORE
if (httpRequest.HasFormContentType && httpRequest.Form != null)
#else
if (httpRequest.Form != null)
#endif
{
foreach (string key in httpRequest.Form.Keys)
{
Expand Down

0 comments on commit 3ebb807

Please sign in to comment.