This repository was archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 522
Implement IHttpRequestFeature.RawTarget (aspnet/HttpAbstractions#596) #880
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestConnection.cs
This file was deleted.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Server.KestrelTests | ||
{ | ||
public class RequestTargetProcessingTests | ||
{ | ||
[Fact] | ||
public async Task RequestPathIsNormalized() | ||
{ | ||
var testContext = new TestServiceContext(); | ||
|
||
using (var server = new TestServer(async context => | ||
{ | ||
Assert.Equal("/\u00C5", context.Request.PathBase.Value); | ||
Assert.Equal("/B/\u00C5", context.Request.Path.Value); | ||
|
||
context.Response.Headers["Content-Length"] = new[] { "11" }; | ||
await context.Response.WriteAsync("Hello World"); | ||
}, testContext, "http://127.0.0.1/\u0041\u030A")) | ||
{ | ||
using (var connection = server.CreateConnection()) | ||
{ | ||
await connection.SendEnd( | ||
"GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.0", | ||
"", | ||
""); | ||
await connection.ReceiveEnd( | ||
"HTTP/1.1 200 OK", | ||
$"Date: {testContext.DateHeaderValue}", | ||
"Content-Length: 11", | ||
"", | ||
"Hello World"); | ||
} | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("/")] | ||
[InlineData("/.")] | ||
[InlineData("/..")] | ||
[InlineData("/./.")] | ||
[InlineData("/./..")] | ||
[InlineData("/../.")] | ||
[InlineData("/../..")] | ||
[InlineData("/path")] | ||
[InlineData("/path?foo=1&bar=2")] | ||
[InlineData("/hello%20world")] | ||
[InlineData("/hello%20world?foo=1&bar=2")] | ||
[InlineData("/base/path")] | ||
[InlineData("/base/path?foo=1&bar=2")] | ||
[InlineData("/base/hello%20world")] | ||
[InlineData("/base/hello%20world?foo=1&bar=2")] | ||
public async Task RequestFeatureContainsRawTarget(string requestTarget) | ||
{ | ||
var testContext = new TestServiceContext(); | ||
|
||
using (var server = new TestServer(async context => | ||
{ | ||
Assert.Equal(requestTarget, context.Features.Get<IHttpRequestFeature>().RawTarget); | ||
|
||
context.Response.Headers["Content-Length"] = new[] { "11" }; | ||
await context.Response.WriteAsync("Hello World"); | ||
}, testContext)) | ||
{ | ||
using (var connection = server.CreateConnection()) | ||
{ | ||
await connection.SendEnd( | ||
$"GET {requestTarget} HTTP/1.0", | ||
"", | ||
""); | ||
await connection.ReceiveEnd( | ||
"HTTP/1.1 200 OK", | ||
$"Date: {testContext.DateHeaderValue}", | ||
"Content-Length: 11", | ||
"", | ||
"Hello World"); | ||
} | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("*")] | ||
[InlineData("*/?arg=value")] | ||
[InlineData("*?arg=value")] | ||
[InlineData("DoesNotStartWith/")] | ||
[InlineData("DoesNotStartWith/?arg=value")] | ||
[InlineData("DoesNotStartWithSlash?arg=value")] | ||
[InlineData("./")] | ||
[InlineData("../")] | ||
[InlineData("../.")] | ||
[InlineData(".././")] | ||
[InlineData("../..")] | ||
[InlineData("../../")] | ||
public async Task NonPathRequestTargetSetInRawTarget(string requestTarget) | ||
{ | ||
var testContext = new TestServiceContext(); | ||
|
||
using (var server = new TestServer(async context => | ||
{ | ||
Assert.Equal(requestTarget, context.Features.Get<IHttpRequestFeature>().RawTarget); | ||
Assert.Empty(context.Request.Path.Value); | ||
Assert.Empty(context.Request.PathBase.Value); | ||
Assert.Empty(context.Request.QueryString.Value); | ||
|
||
context.Response.Headers["Content-Length"] = new[] { "11" }; | ||
await context.Response.WriteAsync("Hello World"); | ||
}, testContext)) | ||
{ | ||
using (var connection = server.CreateConnection()) | ||
{ | ||
await connection.SendEnd( | ||
$"GET {requestTarget} HTTP/1.0", | ||
"", | ||
""); | ||
await connection.ReceiveEnd( | ||
"HTTP/1.1 200 OK", | ||
$"Date: {testContext.DateHeaderValue}", | ||
"Content-Length: 11", | ||
"", | ||
"Hello World"); | ||
} | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would these test cases pass with WebListenter after you add RawTarget there? I mainly wondering whether Path, PathBase and QueryString would all be an empty string.
Should this be added to ServerTests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WebListener actually rejects those requests. Maybe we should do the same in Kestrel? The only request I was able to make to a target not starting with
/
wasOPTIONS *
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, WebListener turned
*
into/*
inPath
.