Add negative path tests.

This commit is contained in:
Chris R 2016-06-01 15:58:49 -07:00
parent 58410bf016
commit 6e36bbe32c
2 changed files with 15 additions and 5 deletions

View File

@ -11,23 +11,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public class RequestTargetProcessingTests
{
[Fact]
public async Task RequestPathIsNormalized()
public async Task RequestPathIsNotNormalized()
{
var testContext = new TestServiceContext();
using (var server = new TestServer(async context =>
{
Assert.Equal("/A", context.Request.PathBase.Value);
Assert.Equal("/B/C", context.Request.Path.Value);
Assert.Equal("/\u0041\u030A", context.Request.PathBase.Value);
Assert.Equal("/B/\u0041\u030A", context.Request.Path.Value);
context.Response.Headers["Content-Length"] = new[] { "11" };
await context.Response.WriteAsync("Hello World");
}, testContext, "http://127.0.0.1:0/A"))
}, testContext, "http://127.0.0.1:0/\u0041\u030A"))
{
using (var connection = server.CreateConnection())
{
await connection.SendEnd(
"GET /A/0/../B/C HTTP/1.0",
"GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.0",
"",
"");
await connection.ReceiveEnd(

View File

@ -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.Text;
using Microsoft.AspNetCore.Server.Kestrel;
using Xunit;
@ -67,6 +68,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
Assert.Equal(toString ?? url, serverAddress.ToString());
}
[Fact]
public void PathBaseIsNotNormalized()
{
var serverAddres = ServerAddress.FromUrl("http://localhost:8080/p\u0041\u030Athbase");
Assert.False(serverAddres.PathBase.IsNormalized(NormalizationForm.FormC));
Assert.Equal("/p\u0041\u030Athbase", serverAddres.PathBase);
}
[Fact]
public void WithHostReturnsNewInstanceWithDifferentHost()
{