Skip to content

Commit

Permalink
Align package ID validation with the client (#3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Bommarito committed Oct 24, 2016
1 parent acc5cde commit 708a586
Show file tree
Hide file tree
Showing 32 changed files with 1,394 additions and 1,548 deletions.
10 changes: 0 additions & 10 deletions src/NuGetGallery.Core/CoreConstants.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/NuGetGallery.Core/Entities/PackageDependency.cs
Expand Up @@ -15,7 +15,7 @@ public class PackageDependency
/// We insert a record with a null Id to indicate an empty package dependency set. In such a case, the Id would be empty and hence
/// we cannot mandate that it is required.
/// </remarks>
[StringLength(CoreConstants.MaxPackageIdLength)]
[StringLength(Packaging.PackagingConstants.PackageIdDatabaseLength)]
public string Id { get; set; }

[StringLength(256)]
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery.Core/Entities/PackageLicense.cs
Expand Up @@ -12,7 +12,7 @@ public class PackageLicense
public int Key { get; set; }

[Required]
[StringLength(CoreConstants.MaxPackageIdLength)]
[StringLength(128)]
public string Name { get; set; }

public virtual ICollection<PackageLicenseReport> Reports { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion src/NuGetGallery.Core/Entities/PackageRegistration.cs
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using NuGet.Packaging;

namespace NuGetGallery
{
Expand All @@ -15,7 +16,7 @@ public PackageRegistration()
Packages = new HashSet<Package>();
}

[StringLength(CoreConstants.MaxPackageIdLength)]
[StringLength(Packaging.PackagingConstants.PackageIdDatabaseLength)]
[Required]
public string Id { get; set; }

Expand Down
27 changes: 13 additions & 14 deletions src/NuGetGallery.Core/NuGetGallery.Core.csproj
Expand Up @@ -80,33 +80,33 @@
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Common, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Common.3.5.0-rc1-final\lib\net45\NuGet.Common.dll</HintPath>
<Reference Include="NuGet.Common, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Common.3.6.0-rc-1997\lib\net45\NuGet.Common.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Frameworks, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Frameworks.3.5.0-rc1-final\lib\net45\NuGet.Frameworks.dll</HintPath>
<Reference Include="NuGet.Frameworks, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Frameworks.3.6.0-rc-1997\lib\net45\NuGet.Frameworks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Logging, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\NuGet.Logging.3.5.0-beta-1160\lib\net45\NuGet.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Packaging, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Packaging.3.5.0-rc1-final\lib\net45\NuGet.Packaging.dll</HintPath>
<Reference Include="NuGet.Packaging, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Packaging.3.6.0-rc-1997\lib\net45\NuGet.Packaging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Packaging.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Packaging.Core.3.5.0-rc1-final\lib\net45\NuGet.Packaging.Core.dll</HintPath>
<Reference Include="NuGet.Packaging.Core, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Packaging.Core.3.6.0-rc-1997\lib\net45\NuGet.Packaging.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Packaging.Core.Types, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Packaging.Core.Types.3.5.0-rc1-final\lib\net45\NuGet.Packaging.Core.Types.dll</HintPath>
<Reference Include="NuGet.Packaging.Core.Types, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Packaging.Core.Types.3.6.0-rc-1997\lib\net45\NuGet.Packaging.Core.Types.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Versioning, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Versioning.3.5.0-rc1-final\lib\net45\NuGet.Versioning.dll</HintPath>
<Reference Include="NuGet.Versioning, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Versioning.3.6.0-rc-1997\lib\net45\NuGet.Versioning.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down Expand Up @@ -148,7 +148,6 @@
<Compile Include="Auditing\PackageAuditRecord.cs" />
<Compile Include="Auditing\UserAuditAction.cs" />
<Compile Include="Auditing\UserAuditRecord.cs" />
<Compile Include="CoreConstants.cs" />
<Compile Include="CredentialTypes.cs" />
<Compile Include="Completion.cs" />
<Compile Include="DisposableAction.cs" />
Expand Down Expand Up @@ -187,10 +186,10 @@
<Compile Include="Packaging\ManifestEdit.cs" />
<Compile Include="Packaging\ManifestValidator.cs" />
<Compile Include="Packaging\NupkgRewriter.cs" />
<Compile Include="Packaging\PackageIdValidator.cs" />
<Compile Include="Packaging\PackageMetadata.cs" />
<Compile Include="Packaging\PackageMetadataStrings.cs" />
<Compile Include="Packaging\PackageStreamMetadata.cs" />
<Compile Include="Packaging\PackagingConstants.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NuGetVersionExtensions.cs" />
<Compile Include="StreamExtensions.cs" />
Expand Down
5 changes: 1 addition & 4 deletions src/NuGetGallery.Core/Packaging/ManifestValidator.cs
Expand Up @@ -14,9 +14,6 @@ namespace NuGetGallery.Packaging
{
public class ManifestValidator
{
// Copy-pasta from NuGet: src/Core/Utility/PackageIdValidator.cs because that constant is internal :(
public static readonly int MaxPackageIdLength = 100;

public static IEnumerable<ValidationResult> Validate(Stream nuspecStream, out NuspecReader nuspecReader)
{
try
Expand Down Expand Up @@ -46,7 +43,7 @@ private static IEnumerable<ValidationResult> ValidateCore(PackageMetadata packag
}
else
{
if (packageMetadata.Id.Length > MaxPackageIdLength)
if (packageMetadata.Id.Length > PackageIdValidator.MaxPackageIdLength)
{
yield return new ValidationResult(Strings.Manifest_IdTooLong);
}
Expand Down
50 changes: 0 additions & 50 deletions src/NuGetGallery.Core/Packaging/PackageIdValidator.cs

This file was deleted.

15 changes: 15 additions & 0 deletions src/NuGetGallery.Core/Packaging/PackagingConstants.cs
@@ -0,0 +1,15 @@
// 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.

namespace NuGetGallery.Packaging
{
public static class PackagingConstants
{
/// <summary>
/// The maximum package ID length enforced by the database.
/// This is not equal to the maximum package length that can be submitted to the gallery.
/// See <see cref="NuGet.Packaging.PackageIdValidator.MaxPackageIdLength"/> for the maximum length that is enforced by the gallery.
/// </summary>
public const int PackageIdDatabaseLength = 128;
}
}
13 changes: 7 additions & 6 deletions src/NuGetGallery.Core/packages.config
Expand Up @@ -7,13 +7,14 @@
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net452" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.1.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" />
<package id="NuGet.Common" version="3.5.0-rc1-final" targetFramework="net452" />
<package id="NuGet.Frameworks" version="3.5.0-rc1-final" targetFramework="net452" />
<package id="NuGet.Common" version="3.6.0-rc-1997" targetFramework="net452" />
<package id="NuGet.Frameworks" version="3.6.0-rc-1997" targetFramework="net452" />
<package id="NuGet.Logging" version="3.5.0-beta-1160" targetFramework="net452" />
<package id="NuGet.Packaging" version="3.5.0-rc1-final" targetFramework="net452" />
<package id="NuGet.Packaging.Core" version="3.5.0-rc1-final" targetFramework="net452" />
<package id="NuGet.Packaging.Core.Types" version="3.5.0-rc1-final" targetFramework="net452" />
<package id="NuGet.Versioning" version="3.5.0-rc1-final" targetFramework="net452" />
<package id="NuGet.Packaging" version="3.6.0-rc-1997" targetFramework="net452" />
<package id="NuGet.Packaging.Core" version="3.6.0-rc-1997" targetFramework="net452" />
<package id="NuGet.Packaging.Core.Types" version="3.6.0-rc-1997" targetFramework="net452" />
<package id="NuGet.Services.Build" version="3.0.13" targetFramework="net452" developmentDependency="true" />
<package id="NuGet.Versioning" version="3.6.0-rc-1997" targetFramework="net452" />
<package id="System.Spatial" version="5.6.5-beta" targetFramework="net452" />
<package id="WindowsAzure.Storage" version="4.3.0" targetFramework="net452" />
</packages>
30 changes: 12 additions & 18 deletions src/NuGetGallery.Operations/NuGetGallery.Operations.csproj
Expand Up @@ -132,39 +132,33 @@
<HintPath>..\..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Common, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\NuGet.Common.3.5.0-beta-final\lib\net45\NuGet.Common.dll</HintPath>
<Reference Include="NuGet.Common, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Common.3.6.0-rc-1997\lib\net45\NuGet.Common.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Frameworks, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\NuGet.Frameworks.3.5.0-beta-final\lib\net45\NuGet.Frameworks.dll</HintPath>
<Reference Include="NuGet.Frameworks, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Frameworks.3.6.0-rc-1997\lib\net45\NuGet.Frameworks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Logging, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\NuGet.Logging.3.5.0-beta-1160\lib\net45\NuGet.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Packaging, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\NuGet.Packaging.3.5.0-beta-final\lib\net45\NuGet.Packaging.dll</HintPath>
<Reference Include="NuGet.Packaging, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Packaging.3.6.0-rc-1997\lib\net45\NuGet.Packaging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Packaging.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\NuGet.Packaging.Core.3.5.0-beta-final\lib\net45\NuGet.Packaging.Core.dll</HintPath>
<Reference Include="NuGet.Packaging.Core, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Packaging.Core.3.6.0-rc-1997\lib\net45\NuGet.Packaging.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Packaging.Core.Types, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\NuGet.Packaging.Core.Types.3.5.0-beta-final\lib\net45\NuGet.Packaging.Core.Types.dll</HintPath>
<Reference Include="NuGet.Packaging.Core.Types, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Packaging.Core.Types.3.6.0-rc-1997\lib\net45\NuGet.Packaging.Core.Types.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Versioning, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\NuGet.Versioning.3.5.0-beta-final\lib\net45\NuGet.Versioning.dll</HintPath>
<Reference Include="NuGet.Versioning, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Versioning.3.6.0-rc-1997\lib\net45\NuGet.Versioning.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
Expand Down
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json.Linq;
using NuGet.Packaging;
using NuGetGallery.Operations.Common;

namespace NuGetGallery.Operations
Expand Down Expand Up @@ -255,7 +256,7 @@ private void CreatePackageReport(string packageId)

private JObject CreateJsonContent(string packageId)
{
Tuple<string[], List<object[]>> data = ExecuteSql("NuGetGallery.Operations.Scripts.DownloadReport_RecentPopularityDetailByPackage.sql", new Tuple<string, int, string>("@packageId", 128, packageId));
Tuple<string[], List<object[]>> data = ExecuteSql("NuGetGallery.Operations.Scripts.DownloadReport_RecentPopularityDetailByPackage.sql", new Tuple<string, int, string>("@packageId", PackageIdValidator.MaxPackageIdLength, packageId));
JObject content = MakeReportJson(data);
TotalDownloads(content);
SortItems(content);
Expand Down

0 comments on commit 708a586

Please sign in to comment.