This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 528
Support PathBase (#214). #412
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 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 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 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 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 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
113 changes: 113 additions & 0 deletions
113
test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs
This file contains 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,113 @@ | ||
// 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.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Hosting; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.AspNet.Testing.xunit; | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests | ||
{ | ||
public class PathBaseTests | ||
{ | ||
[ConditionalTheory] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/base", "/base", "")] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/base/", "/base", "/")] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/base/something", "/base", "/something")] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/base/something/", "/base", "/something/")] | ||
[InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more", "/base/more", "")] | ||
[InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more/something", "/base/more", "/something")] | ||
[InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more/something/", "/base/more", "/something/")] | ||
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] | ||
public Task RequestPathBaseIsServerPathBase(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) | ||
{ | ||
return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath); | ||
} | ||
|
||
[ConditionalTheory] | ||
[InlineData("http://localhost:8791", "http://localhost:8791/", "", "/")] | ||
[InlineData("http://localhost:8791", "http://localhost:8791/something", "", "/something")] | ||
[InlineData("http://localhost:8791/", "http://localhost:8791/", "", "/")] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/", "", "/")] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/something", "", "/something")] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/baseandsomething", "", "/baseandsomething")] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/ba", "", "/ba")] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/ba/se", "", "/ba/se")] | ||
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] | ||
public Task DefaultPathBaseIsEmpty(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) | ||
{ | ||
return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath); | ||
} | ||
|
||
[ConditionalTheory] | ||
[InlineData("http://localhost:8791", "http://localhost:8791/", "", "/")] | ||
[InlineData("http://localhost:8791/", "http://localhost:8791/", "", "/")] | ||
[InlineData("http://localhost:8791/base", "http://localhost:8791/base/", "/base", "/")] | ||
[InlineData("http://localhost:8791/base/", "http://localhost:8791/base", "/base", "")] | ||
[InlineData("http://localhost:8791/base/", "http://localhost:8791/base/", "/base", "/")] | ||
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] | ||
public Task PathBaseNeverEndsWithSlash(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) | ||
{ | ||
return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath); | ||
} | ||
|
||
[ConditionalFact] | ||
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] | ||
public Task PathBaseAndPathPreserveRequestCasing() | ||
{ | ||
return TestPathBase("http://localhost:8791/base", "http://localhost:8791/Base/Something", "/Base", "/Something"); | ||
} | ||
|
||
[ConditionalFact] | ||
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] | ||
public Task PathBaseCanHaveUTF8Characters() | ||
{ | ||
return TestPathBase("http://localhost:8791/b♫se", "http://localhost:8791/b♫se/something", "/b♫se", "/something"); | ||
} | ||
|
||
private async Task TestPathBase(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) | ||
{ | ||
var config = new ConfigurationBuilder().AddInMemoryCollection( | ||
new Dictionary<string, string> { | ||
{ "server.urls", registerAddress } | ||
}).Build(); | ||
|
||
var builder = new WebHostBuilder(config) | ||
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") | ||
.UseStartup(app => | ||
{ | ||
app.Run(async context => | ||
{ | ||
await context.Response.WriteAsync(JsonConvert.SerializeObject(new | ||
{ | ||
PathBase = context.Request.PathBase.Value, | ||
Path = context.Request.Path.Value | ||
})); | ||
}); | ||
}); | ||
|
||
using (var app = builder.Build().Start()) | ||
{ | ||
using (var client = new HttpClient()) | ||
{ | ||
var response = await client.GetAsync(requestAddress); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HttpClient will always turn http://localhost to http://localhost/, so you can't test that senario here. |
||
response.EnsureSuccessStatusCode(); | ||
|
||
var responseText = await response.Content.ReadAsStringAsync(); | ||
Assert.NotEmpty(responseText); | ||
|
||
var pathFacts = JsonConvert.DeserializeObject<JObject>(responseText); | ||
Assert.Equal(expectedPathBase, pathFacts["PathBase"].Value<string>()); | ||
Assert.Equal(expectedPath, pathFacts["Path"].Value<string>()); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.
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.
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.
I'm going to rewrite this to use iterators and also avoid scanning the string multiple times.