From 6e36bbe32c4764799d0e5dee1cac98b48b71c7f8 Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 1 Jun 2016 15:58:49 -0700 Subject: [PATCH] Add negative path tests. --- .../RequestTargetProcessingTests.cs | 10 +++++----- .../ServerAddressTests.cs | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index a3c37ff19a..6d6a82ce3b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -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( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs index ee40a855e2..c8920d384b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs @@ -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() {