Skip to content

Commit 1be0e13

Browse files
authored
Only assert HTTP 400 for bad cookies since behavior is flaky in App Service (#8981)
* Make the rejected cookie test less sensitive * Set TLS 1.2 in static constructor to make ad hoc testing easier
1 parent f2c1759 commit 1be0e13

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

tests/NuGetGallery.FunctionalTests.Core/Helpers/UrlHelper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Net;
56

67
namespace NuGetGallery.FunctionalTests
78
{
@@ -10,6 +11,12 @@ namespace NuGetGallery.FunctionalTests
1011
/// </summary>
1112
public class UrlHelper
1213
{
14+
static UrlHelper()
15+
{
16+
// This test suite hits the gallery which requires TLS 1.2 (at least in some environments).
17+
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
18+
}
19+
1320
private const string _logonPageUrlSuffix = "users/account/LogOnNuGetAccount";
1421
private const string _editUrlSuffix = "packages/{0}/{1}/Edit";
1522
private const string _cancelUrlSuffix = "packages/manage/cancel-upload";

tests/NuGetGallery.FunctionalTests/ErrorHandling/ErrorHandlingTests.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public ErrorHandlingTests(ITestOutputHelper testOutputHelper) : base(testOutputH
3737
[Theory]
3838
[Priority(2)]
3939
[Category("P2Tests")]
40-
[InlineData("/", "__Controller::TempData", "Message=You successfully uploaded z̡̜͍̈̍̐̃̊͋́a̜̣͍̬̞̝͉̽ͧ͗l̸̖͕̤̠̹̘͖̃̌ͤg͓̝͓̰̀ͪo͈͌ 1.0.0.", 400, false)]
41-
[InlineData("/", "__Controller::TempData", "Message=<script>alert(1)</script>", 400, false)]
42-
[InlineData("/", "__Controller::TempData", "<script>alert(1)</script>", 400, false)]
43-
[InlineData("/packages", "nugetab", "<script>alert(1)</script>", 400, true)]
44-
[InlineData("/packages", "nugetab", "z̡̜͍̈̍̐̃̊͋́a̜̣͍̬̞̝͉̽ͧ͗l̸̖͕̤̠̹̘͖̃̌ͤg͓̝͓̰̀ͪo͈͌", 400, false)]
45-
public async Task RejectedCookie(string relativePath, string name, string value, int statusCode, bool pretty)
40+
[InlineData("/", "__Controller::TempData", "Message=You successfully uploaded z̡̜͍̈̍̐̃̊͋́a̜̣͍̬̞̝͉̽ͧ͗l̸̖͕̤̠̹̘͖̃̌ͤg͓̝͓̰̀ͪo͈͌ 1.0.0.", 400)]
41+
[InlineData("/", "__Controller::TempData", "Message=<script>alert(1)</script>", 400)]
42+
[InlineData("/", "__Controller::TempData", "<script>alert(1)</script>", 400)]
43+
[InlineData("/packages", "nugetab", "<script>alert(1)</script>", 400)]
44+
[InlineData("/packages", "nugetab", "z̡̜͍̈̍̐̃̊͋́a̜̣͍̬̞̝͉̽ͧ͗l̸̖͕̤̠̹̘͖̃̌ͤg͓̝͓̰̀ͪo͈͌", 400)]
45+
public async Task RejectedCookie(string relativePath, string name, string value, int statusCode)
4646
{
4747
// Arrange
4848
_httpClientHandler.UseCookies = false;
@@ -55,14 +55,7 @@ public async Task RejectedCookie(string relativePath, string name, string value,
5555
var response = await GetTestResponseAsync(relativePath, request);
5656

5757
// Assert
58-
if (pretty)
59-
{
60-
Validator.PrettyHtml((HttpStatusCode)statusCode)(response);
61-
}
62-
else
63-
{
64-
Validator.SimpleHtml((HttpStatusCode)statusCode)(response);
65-
}
58+
Assert.Equal((HttpStatusCode)statusCode, response.StatusCode);
6659
}
6760
}
6861

0 commit comments

Comments
 (0)