Skip to content

Commit b1e4262

Browse files
author
Daniel Jacinto
authored
Merge pull request #7991 from NuGet/dev
[ReleasePrep][2020.05.12]RI of dev into master
2 parents 7659179 + 020aed8 commit b1e4262

23 files changed

Lines changed: 407 additions & 20 deletions

src/AccountDeleter/AccountDeleter.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,5 @@
125125
</PropertyGroup>
126126
<Import Project="$(SignPath)\sign.targets" Condition="Exists('$(SignPath)\sign.targets')" />
127127
<Import Project="$(SignPath)\sign.microbuild.targets" Condition="Exists('$(SignPath)\sign.microbuild.targets')" />
128+
<Import Project="$(NuGetBuildExtensions)" Condition="'$(NuGetBuildExtensions)' != '' And Exists('$(NuGetBuildExtensions)')" />
128129
</Project>

src/GitHubVulnerabilities2Db/GitHubVulnerabilities2Db.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,5 @@
118118
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
119119
<Import Project="$(SignPath)\sign.targets" Condition="Exists('$(SignPath)\sign.targets')" />
120120
<Import Project="$(SignPath)\sign.microbuild.targets" Condition="Exists('$(SignPath)\sign.microbuild.targets')" />
121+
<Import Project="$(NuGetBuildExtensions)" Condition="'$(NuGetBuildExtensions)' != '' And Exists('$(NuGetBuildExtensions)')" />
121122
</Project>

src/NuGetGallery/Controllers/PackagesController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Collections.Specialized;
67
using System.Diagnostics;
78
using System.Globalization;
89
using System.IO;
@@ -796,6 +797,12 @@ private static async Task<byte[]> ReadPackageFile(PackageArchiveReader packageAr
796797
}
797798
}
798799

800+
// This additional delete action addresses issue https://github.com/NuGet/Engineering/issues/2866 - we need to error out.
801+
[HttpDelete]
802+
public HttpStatusCodeResult DisplayPackage()
803+
=> new HttpStatusCodeWithHeadersResult(HttpStatusCode.MethodNotAllowed, new NameValueCollection() { { "allow", "GET" } });
804+
805+
[HttpGet]
799806
public virtual async Task<ActionResult> DisplayPackage(string id, string version)
800807
{
801808
string normalized = NuGetVersionFormatter.Normalize(version);

src/NuGetGallery/GalleryConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static class GalleryConstants
2727
public const int GravatarCacheDurationSeconds = 300;
2828

2929
public const int MaxEmailSubjectLength = 255;
30-
internal static readonly NuGetVersion MaxSupportedMinClientVersion = new NuGetVersion("5.5.0.0");
30+
internal static readonly NuGetVersion MaxSupportedMinClientVersion = new NuGetVersion("5.6.0.0");
3131
public const string PackageFileDownloadUriTemplate = "packages/{0}/{1}/download";
3232

3333
public const string ReadMeFileSavePathTemplateActive = "active/{0}/{1}{2}";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Linq;
6+
using NuGet.Packaging;
7+
8+
namespace NuGetGallery.Helpers
9+
{
10+
public class ValidationHelper
11+
{
12+
public static bool HasDuplicatedEntries(PackageArchiveReader nuGetPackage)
13+
{
14+
// Normalize paths and ensures case sensitivity is also considered
15+
var packageFiles = nuGetPackage.GetFiles().Select(packageFile => FileNameHelper.GetZipEntryPath(packageFile));
16+
17+
return packageFiles.Count() != packageFiles.Distinct(StringComparer.OrdinalIgnoreCase).Count();
18+
}
19+
}
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Specialized;
5+
using System.Net;
6+
using System.Web.Mvc;
7+
8+
namespace NuGetGallery
9+
{
10+
public class HttpStatusCodeWithHeadersResult : HttpStatusCodeResult
11+
{
12+
public readonly NameValueCollection Headers;
13+
14+
public HttpStatusCodeWithHeadersResult(HttpStatusCode statusCode, NameValueCollection headers)
15+
: base(statusCode)
16+
{
17+
Headers = headers;
18+
}
19+
20+
public override void ExecuteResult(ControllerContext context)
21+
{
22+
base.ExecuteResult(context);
23+
var response = context.RequestContext.HttpContext.Response;
24+
response.Headers.Add(Headers);
25+
}
26+
}
27+
}

src/NuGetGallery/NuGetGallery.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
<Compile Include="Controllers\ManageDeprecationJsonApiController.cs" />
214214
<Compile Include="ExtensionMethods.cs" />
215215
<Compile Include="Extensions\ImageExtensions.cs" />
216+
<Compile Include="Helpers\ValidationHelper.cs" />
216217
<Compile Include="Helpers\ViewModelExtensions\DeleteAccountListPackageItemViewModelFactory.cs" />
217218
<Compile Include="Helpers\ViewModelExtensions\DeletePackageViewModelFactory.cs" />
218219
<Compile Include="Helpers\ViewModelExtensions\DisplayLicenseViewModelFactory.cs" />
@@ -226,6 +227,7 @@
226227
<Compile Include="Infrastructure\ABTestEnrollmentFactory.cs" />
227228
<Compile Include="Infrastructure\CookieBasedABTestService.cs" />
228229
<Compile Include="Infrastructure\RequestValidationExceptionFilter.cs" />
230+
<Compile Include="Infrastructure\HttpStatusCodeWithHeadersResult.cs" />
229231
<Compile Include="Infrastructure\IABTestEnrollmentFactory.cs" />
230232
<Compile Include="Infrastructure\IABTestService.cs" />
231233
<Compile Include="Infrastructure\ILuceneDocumentFactory.cs" />

src/NuGetGallery/Services/PackageUploadService.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ public async Task<PackageValidationResult> ValidateBeforeGeneratePackageAsync(
118118
return result;
119119
}
120120

121+
result = CheckPackageDuplicatedEntries(nuGetPackage);
122+
123+
if (result != null)
124+
{
125+
return result;
126+
}
127+
121128
var nuspecFileEntry = nuGetPackage.GetEntry(nuGetPackage.GetNuspecFile());
122129
using (var nuspecFileStream = await nuGetPackage.GetNuspecAsync(CancellationToken.None))
123130
{
@@ -599,6 +606,16 @@ private async Task<PackageValidationResult> CheckPackageEntryCountAsync(
599606
return null;
600607
}
601608

609+
private PackageValidationResult CheckPackageDuplicatedEntries(PackageArchiveReader nuGetPackage)
610+
{
611+
if (ValidationHelper.HasDuplicatedEntries(nuGetPackage))
612+
{
613+
return PackageValidationResult.Invalid(Strings.UploadPackage_PackageContainsDuplicatedEntries);
614+
}
615+
616+
return null;
617+
}
618+
602619
/// <summary>
603620
/// Validate repository metadata:
604621
/// 1. If the type is "git" - allow the URL scheme "git://" or "https://". We will translate "git://" to "https://" at display time for known domains.

src/NuGetGallery/Services/SymbolPackageUploadService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using NuGet.Frameworks;
1111
using NuGet.Packaging;
1212
using NuGet.Services.Entities;
13+
using NuGetGallery.Helpers;
1314
using NuGetGallery.Packaging;
1415

1516
namespace NuGetGallery
@@ -88,6 +89,12 @@ public async Task<SymbolPackageValidationResult> ValidateUploadedSymbolsPackage(
8889
normalizedVersion));
8990
}
9091

92+
// Check for duplicated entries in symbols package
93+
if (ValidationHelper.HasDuplicatedEntries(packageToPush))
94+
{
95+
return SymbolPackageValidationResult.Invalid(Strings.UploadPackage_PackageContainsDuplicatedEntries);
96+
}
97+
9198
// Do not allow to upload a snupkg to a package which has symbols package pending validations.
9299
if (package.SymbolPackages.Any(sp => sp.StatusKey == PackageStatus.Validating))
93100
{

src/NuGetGallery/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)