Skip to content

Commit c45d249

Browse files
committed
Merge branch 'master' into dev
2 parents 4c11862 + 206c214 commit c45d249

8 files changed

Lines changed: 127 additions & 5 deletions

File tree

src/NuGetGallery/App_Start/DefaultDependenciesModule.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,6 @@ private static void ConfigureResilientSearch(ILoggerFactory loggerFactory, IGall
741741
services.AddHttpClient<IHttpClientWrapper, HttpClientWrapper>(searchClient.name, c =>
742742
c.BaseAddress = searchClient.searchUri)
743743
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler() { AllowAutoRedirect = true })
744-
.AddHttpMessageHandler<TracingHttpHandler>()
745744
.AddHttpMessageHandler<CorrelatingHttpClientHandler>()
746745
.AddPolicyHandler(SearchClientPolicies.SearchClientFallBackCircuitBreakerPolicy(logger, searchClient.name, telemetryService))
747746
.AddPolicyHandler(SearchClientPolicies.SearchClientWaitAndRetryPolicy(

src/NuGetGallery/Controllers/PackagesController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ public virtual async Task<ActionResult> DisplayPackage(string id, string version
748748
model.SymbolsPackageValidationIssues = _validationService.GetLatestPackageValidationIssues(model.LatestSymbolsPackage);
749749
model.IsCertificatesUIEnabled = _contentObjectService.CertificatesConfiguration?.IsUIEnabledForUser(currentUser) ?? false;
750750
model.IsAtomFeedEnabled = _featureFlagService.IsPackagesAtomFeedEnabled();
751+
model.IsPackageDeprecationEnabled = currentUser != null && _featureFlagService.IsManageDeprecationEnabled(currentUser);
751752

752753
model.ReadMeHtml = await _readMeService.GetReadMeHtmlAsync(package);
753754

src/NuGetGallery/Scripts/gallery/page-display-package.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ $(function () {
1919
container.removeAttr(expanderAttributes[i]);
2020
}
2121

22+
// The expander should not be clickable when it doesn't have content
23+
container.find('.deprecation-expander').removeAttr('role');
24+
2225
$('#deprecation-expander-icon-right').hide();
2326
}
2427

src/NuGetGallery/ViewModels/DisplayPackageViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ private DisplayPackageViewModel(Package package, User currentUser, string pushed
143143
public bool HasSemVer2Dependency { get; }
144144
public bool IsDotnetToolPackageType { get; set; }
145145
public bool IsAtomFeedEnabled { get; set; }
146+
public bool IsPackageDeprecationEnabled { get; set; }
146147

147148
public bool HasNewerPrerelease
148149
{

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
)
256256
}
257257

258-
@if (Model.DeprecationStatus != PackageDeprecationStatus.NotDeprecated)
258+
@if (Model.IsPackageDeprecationEnabled && Model.DeprecationStatus != PackageDeprecationStatus.NotDeprecated)
259259
{
260260
@Html.Partial("_DisplayPackageDeprecation")
261261
}
@@ -572,7 +572,7 @@
572572
</td>
573573

574574
<td class="package-icon-cell">
575-
@if (packageVersion.DeprecationStatus != PackageDeprecationStatus.NotDeprecated)
575+
@if (Model.IsPackageDeprecationEnabled && packageVersion.DeprecationStatus != PackageDeprecationStatus.NotDeprecated)
576576
{
577577
var deprecationTitle = packageVersion.Version;
578578
var isVulnerable = packageVersion.DeprecationStatus.HasFlag(PackageDeprecationStatus.Vulnerable);

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.Facts/Controllers/PackagesControllerFacts.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,115 @@ public async Task ShowsAtomFeedIfEnabled(bool isAtomFeedEnabled)
10761076
deprecationService.Verify();
10771077
}
10781078

1079+
[Theory]
1080+
[InlineData(false)]
1081+
[InlineData(true)]
1082+
public async Task DoesNotShowDeprecationToLoggedOutUsers(bool isDeprecationEnabled)
1083+
{
1084+
var featureFlagService = new Mock<IFeatureFlagService>();
1085+
var packageService = new Mock<IPackageService>();
1086+
var deprecationService = new Mock<IPackageDeprecationService>();
1087+
var controller = CreateController(
1088+
GetConfigurationService(),
1089+
packageService: packageService,
1090+
featureFlagService: featureFlagService,
1091+
deprecationService: deprecationService);
1092+
1093+
var id = "Foo";
1094+
var package = new Package()
1095+
{
1096+
PackageRegistration = new PackageRegistration()
1097+
{
1098+
Id = id,
1099+
Owners = new List<User>()
1100+
},
1101+
Version = "01.1.01",
1102+
NormalizedVersion = "1.1.1",
1103+
Title = "A test package!"
1104+
};
1105+
1106+
var packages = new[] { package };
1107+
packageService
1108+
.Setup(p => p.FindPackagesById(id, PackageDeprecationFieldsToInclude.Deprecation))
1109+
.Returns(packages);
1110+
1111+
packageService
1112+
.Setup(p => p.FilterLatestPackage(packages, SemVerLevelKey.SemVer2, true))
1113+
.Returns(package);
1114+
1115+
featureFlagService
1116+
.Setup(x => x.IsManageDeprecationEnabled(It.IsAny<User>()))
1117+
.Returns(isDeprecationEnabled);
1118+
1119+
deprecationService
1120+
.Setup(x => x.GetDeprecationByPackage(package))
1121+
.Verifiable();
1122+
1123+
// Arrange and Act
1124+
var result = await controller.DisplayPackage(id, version: null);
1125+
1126+
// Assert
1127+
var model = ResultAssert.IsView<DisplayPackageViewModel>(result);
1128+
Assert.False(model.IsPackageDeprecationEnabled);
1129+
1130+
deprecationService.Verify();
1131+
}
1132+
1133+
[Theory]
1134+
[InlineData(false)]
1135+
[InlineData(true)]
1136+
public async Task ShowsDeprecationIfEnabled(bool isDeprecationEnabled)
1137+
{
1138+
var featureFlagService = new Mock<IFeatureFlagService>();
1139+
var packageService = new Mock<IPackageService>();
1140+
var deprecationService = new Mock<IPackageDeprecationService>();
1141+
var controller = CreateController(
1142+
GetConfigurationService(),
1143+
packageService: packageService,
1144+
featureFlagService: featureFlagService,
1145+
deprecationService: deprecationService);
1146+
controller.SetCurrentUser(TestUtility.FakeUser);
1147+
1148+
var id = "Foo";
1149+
var package = new Package()
1150+
{
1151+
PackageRegistration = new PackageRegistration()
1152+
{
1153+
Id = id,
1154+
Owners = new List<User>()
1155+
},
1156+
Version = "01.1.01",
1157+
NormalizedVersion = "1.1.1",
1158+
Title = "A test package!"
1159+
};
1160+
1161+
var packages = new[] { package };
1162+
packageService
1163+
.Setup(p => p.FindPackagesById(id, PackageDeprecationFieldsToInclude.Deprecation))
1164+
.Returns(packages);
1165+
1166+
packageService
1167+
.Setup(p => p.FilterLatestPackage(packages, SemVerLevelKey.SemVer2, true))
1168+
.Returns(package);
1169+
1170+
featureFlagService
1171+
.Setup(x => x.IsManageDeprecationEnabled(TestUtility.FakeUser))
1172+
.Returns(isDeprecationEnabled);
1173+
1174+
deprecationService
1175+
.Setup(x => x.GetDeprecationByPackage(package))
1176+
.Verifiable();
1177+
1178+
// Arrange and Act
1179+
var result = await controller.DisplayPackage(id, version: null);
1180+
1181+
// Assert
1182+
var model = ResultAssert.IsView<DisplayPackageViewModel>(result);
1183+
Assert.Equal(isDeprecationEnabled, model.IsPackageDeprecationEnabled);
1184+
1185+
deprecationService.Verify();
1186+
}
1187+
10791188
[Fact]
10801189
public async Task SplitsLicenseExpressionWhenProvided()
10811190
{

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)