Skip to content

Commit 206c214

Browse files
authored
400 errors shouln't show 500 page (#7048)
1 parent 9f65fe8 commit 206c214

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/NuGetGallery/Web.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@
330330
<customErrors mode="RemoteOnly" defaultRedirect="~/Errors/500" redirectMode="ResponseRedirect">
331331
<!-- Adding ? at the end of the redirect URL prevents the illegal request to be passed
332332
as a query parameter to the redirect URL and causing additional failures -->
333+
<error statusCode="400" redirect="~/Errors/400"/>
333334
<error statusCode="404" redirect="~/Errors/404"/>
334335
<error statusCode="500" redirect="~/Errors/500"/>
335336
</customErrors>

tests/NuGetGallery.FunctionalTests/ErrorHandling/ErrorHandlingTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public ErrorHandlingTests(ITestOutputHelper testOutputHelper) : base(testOutputH
3232
/// Verify the behavior when a corrupted cookie is sent back to the server.
3333
/// </summary>
3434
[Theory]
35+
[Priority(2)]
36+
[Category("P2Tests")]
3537
[InlineData("__Controller::TempData", "Message=You successfully uploaded z̡̜͍̈̍̐̃̊͋́a̜̣͍̬̞̝͉̽ͧ͗l̸̖͕̤̠̹̘͖̃̌ͤg͓̝͓̰̀ͪo͈͌ 1.0.0.")]
3638
public async Task RejectedCookie(string name, string value)
3739
{
@@ -54,6 +56,8 @@ public async Task RejectedCookie(string name, string value)
5456
/// Verify the behavior when a URL with restricted characters is used.
5557
/// </summary>
5658
[Theory]
59+
[Priority(2)]
60+
[Category("P2Tests")]
5761
[InlineData("/api/v2/lazy/%3E=1.0.5%20%3C1.1")]
5862
[InlineData("/api/v2/mysql/*")]
5963
[InlineData("/api/v2/comb/%3E=0.0.2")]
@@ -67,13 +71,15 @@ public async Task RejectedUrl(string relativePath)
6771
// Assert
6872
// Since the HTTP client is configured to not follow redirects, the response we get back is not the
6973
// error page itself but instead a redirect to an error page.
70-
Validator.Redirect("500")(response);
74+
Validator.Redirect("400")(response);
7175
}
7276

7377
/// <summary>
7478
/// Verify simple 404 behavior.
7579
/// </summary>
7680
[Theory]
81+
[Priority(2)]
82+
[Category("P2Tests")]
7783
[InlineData("/api/does-not-exist")]
7884
[InlineData("/pages/does-not-exist")]
7985
[InlineData("/api/v2/curated-feed/microsoftdotnet/DoesNotExist()")]
@@ -91,6 +97,8 @@ public async Task PageThatDoesNotExist(string relativePath)
9197
/// Simulate cases where application code throws different sorts of exceptions.
9298
/// </summary>
9399
[Theory]
100+
[Priority(2)]
101+
[Category("P2Tests")]
94102
[MemberData(nameof(AllTestData))]
95103
public async Task SimulateError(EndpointType endpointType, SimulatedErrorType simulatedErrorType)
96104
{
@@ -160,7 +168,7 @@ public static IEnumerable<object[]> AllTestData
160168
{ SER(EndpointType.OData, SimulatedErrorType.Result500), Validator.Empty(HttpStatusCode.InternalServerError, SimulatedErrorType.Result500) },
161169
{ SER(EndpointType.OData, SimulatedErrorType.Result503), Validator.Empty(HttpStatusCode.ServiceUnavailable, SimulatedErrorType.Result503) },
162170
{ SER(EndpointType.OData, SimulatedErrorType.UserSafeException), Validator.Xml() },
163-
{ SER(EndpointType.Pages, SimulatedErrorType.HttpException400), Validator.Redirect("500") },
171+
{ SER(EndpointType.Pages, SimulatedErrorType.HttpException400), Validator.Redirect("400") },
164172
{ SER(EndpointType.Pages, SimulatedErrorType.HttpException404), Validator.Redirect("404") },
165173
{ SER(EndpointType.Pages, SimulatedErrorType.HttpException503), Validator.Redirect("500") },
166174
{ SER(EndpointType.Pages, SimulatedErrorType.ReadOnlyMode), Validator.PrettyHtml(HttpStatusCode.ServiceUnavailable) },

0 commit comments

Comments
 (0)