Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #255 from NuGet/dev
Browse files Browse the repository at this point in the history
[ReleasePrep][2017.10.30]RI of dev into master
  • Loading branch information
loic-sharma authored Oct 30, 2017
2 parents 9fc5905 + b6fb97e commit 90d4f9b
Show file tree
Hide file tree
Showing 17 changed files with 427 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Catalog/Helpers/NuGetVersionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static string NormalizeVersion(string version)

return parsedVersion.ToNormalizedString();
}

public static string NormalizeVersionRange(string versionRange)
public static string NormalizeVersionRange(string versionRange, string defaultValue)
{
VersionRange parsedVersionRange;
if (!VersionRange.TryParse(versionRange, out parsedVersionRange))
{
return versionRange;
return defaultValue;
}

return parsedVersionRange.ToNormalizedString();
Expand Down
9 changes: 8 additions & 1 deletion src/Catalog/Helpers/XsltHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace NuGet.Services.Metadata.Catalog
{
public class XsltHelper
{
/// <summary>
/// Default to an empty string if the dependency version range is invalid or missing. This is meant to be a
/// predictable signal to the client that they need to handle this invalid version case. The official NuGet
/// client treats this as a dependency of any version.
/// </summary>
private static readonly string DefaultVersionRange = string.Empty;

public XPathNavigator Split(string original)
{
char[] trimChar = { ',', ' ', '\t', '|', ';' };
Expand Down Expand Up @@ -52,7 +59,7 @@ public string GetFullVersionString(string original)

public string NormalizeVersionRange(string original)
{
return NuGetVersionUtility.NormalizeVersionRange(original);
return NuGetVersionUtility.NormalizeVersionRange(original, DefaultVersionRange);
}

public string IsPrerelease(string original)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<Compile Include="Validation\Test\Endpoint\FlatContainerEndpoint.cs" />
<Compile Include="Validation\Test\Exceptions\MetadataFieldInconsistencyException.cs" />
<Compile Include="Validation\Test\Exceptions\MetadataInconsistencyException.cs" />
<Compile Include="Validation\Test\Exceptions\TimestampComparisonException.cs" />
<Compile Include="Validation\Test\Exceptions\ValidationException.cs" />
<Compile Include="Validation\Test\IAggregateValidator.cs" />
<Compile Include="Validation\Test\IValidator.cs" />
Expand Down Expand Up @@ -208,4 +209,4 @@
<NuGetBuildPath Condition="'$(NuGetBuildPath)' == ''">..\..\build</NuGetBuildPath>
</PropertyGroup>
<Import Project="$(NuGetBuildPath)\sign.targets" Condition="Exists('$(NuGetBuildPath)\sign.targets')" />
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.

using System;
using Newtonsoft.Json;

namespace NuGet.Services.Metadata.Catalog.Monitoring
{
public class TimestampComparisonException : ValidationException
{
public PackageTimestampMetadata TimestampV2 { get; }
public PackageTimestampMetadata TimestampCatalog { get; }

public TimestampComparisonException(PackageTimestampMetadata timestampV2, PackageTimestampMetadata timestampCatalog, string message)
: base(message)
{
TimestampV2 = timestampV2;
TimestampCatalog = timestampCatalog;

Data.Add(nameof(TimestampV2), JsonConvert.SerializeObject(TimestampV2));
Data.Add(nameof(TimestampCatalog), JsonConvert.SerializeObject(TimestampCatalog));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace NuGet.Services.Metadata.Catalog.Monitoring
{
/// <summary>
/// Base class for exceptions throw by <see cref="IValidator.Run(ValidationContext)"/>.
/// Base class for exceptions throw by <see cref="IValidator.ValidateAsync(ValidationContext)"/>.
/// </summary>
public class ValidationException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,20 @@ protected virtual async Task<bool> ShouldRun(ValidationContext data)

if (!timestampV2.Last.HasValue)
{
throw new ValidationException("Cannot get timestamp data for package from the V2 feed!");
throw new TimestampComparisonException(timestampV2, timestampCatalog,
"Cannot get timestamp data for package from the V2 feed!");
}

if (!timestampCatalog.Last.HasValue)
{
throw new ValidationException("Cannot get timestamp data for package from the catalog!");
throw new TimestampComparisonException(timestampV2, timestampCatalog,
"Cannot get timestamp data for package from the catalog!");
}

if (timestampCatalog.Last > timestampV2.Last)
{
throw new ValidationException("The timestamp in the catalog is newer than the timestamp in the feed! This should never happen because all data flows from the catalog into the feed!");
throw new TimestampComparisonException(timestampV2, timestampCatalog,
"The timestamp in the catalog is newer than the timestamp in the feed! This should never happen because all data flows from the feed into the catalog!");
}

// If the timestamp metadata in the catalog is LESS than that of the feed, we must not be looking at the latest entry that corresponds with this package, so skip the test for now.
Expand Down
24 changes: 24 additions & 0 deletions tests/CatalogTests/CatalogTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,24 @@
<None Include="TestData\EmptyDependencyIdWithGroups.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\EmptyDependencyVersionRange.0.1.0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\EmptyDependencyVersionRange.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\InvalidDependencyVersionRange.0.1.0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\InvalidDependencyVersionRange.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\MissingDependencyVersionRange.0.1.0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\MissingDependencyVersionRange.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\Newtonsoft.Json.9.0.2-beta1.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -224,6 +242,12 @@
<None Include="TestData\WhitespaceDependencyId.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\WhitespaceDependencyVersionRange.0.1.0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\WhitespaceDependencyVersionRange.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
21 changes: 19 additions & 2 deletions tests/CatalogTests/Helpers/NuGetVersionUtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,30 @@ public void NormalizeVersion(string input, string expected)
[InlineData("invalid", "invalid")]
public void NormalizeVersionRange(string input, string expected)
{
// Arrange & Act
var actual = NuGetVersionUtility.NormalizeVersionRange(input);
// Arrange
var defaultValue = input;

// Arrange
var actual = NuGetVersionUtility.NormalizeVersionRange(input, defaultValue);

// Assert
Assert.Equal(expected, actual);
}

[Fact]
public void NormalizeVersionRange_UsesDifferentDefault()
{
// Arrange
var input = "invalid";
var defaultValue = "(, )";

// Act
var actual = NuGetVersionUtility.NormalizeVersionRange(input, defaultValue);

// Assert
Assert.Equal(defaultValue, actual);
}

[Theory]
[InlineData("1.0.0-alpha.1", "1.0.0-alpha.1")]
[InlineData("1.0.0-alpha+githash", "1.0.0-alpha+githash")]
Expand Down
4 changes: 4 additions & 0 deletions tests/CatalogTests/PackageCatalogItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class PackageCatalogItemTests
[InlineData("OneValidDependencyOneEmptyId.0.1.0")] // One valid dependency and one with empty string ID
[InlineData("OneValidDependencyOneEmptyIdWithGroups.0.1.0")] // Using dependency groups, one valid dependency and one with empty string ID
[InlineData("WhitespaceDependencyId.0.1.0")] // One dependency with an ID only containing whitespace
[InlineData("EmptyDependencyVersionRange.0.1.0")] // A dependency with a version range that is an empty string
[InlineData("InvalidDependencyVersionRange.0.1.0")] //A dependency with a version range that is invalid
[InlineData("MissingDependencyVersionRange.0.1.0")] // A dependency with no version range attribute
[InlineData("WhitespaceDependencyVersionRange.0.1.0")] // A dependency with a version range that is whitespace
public void CreateContent_ProducesExpectedJson(string packageName)
{
// Arrange
Expand Down
84 changes: 84 additions & 0 deletions tests/CatalogTests/TestData/EmptyDependencyVersionRange.0.1.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"@id": "http://example/data/2017.01.04.08.15.00/emptydependencyversionrange.0.1.0.json",
"@type": [
"PackageDetails",
"catalog:Permalink"
],
"authors": "EmptyDependencyVersionRange",
"catalog:commitId": "4aee0ef4-a039-4460-bd5f-98f944e33289",
"catalog:commitTimeStamp": "2017-01-04T08:15:00Z",
"created": "2017-01-01T08:15:00Z",
"description": "EmptyDependencyVersionRange",
"id": "EmptyDependencyVersionRange",
"isPrerelease": false,
"lastEdited": "2017-01-02T08:15:00Z",
"listed": true,
"packageHash": "J1NrM0aeDXk3kdjY3Aby8duP+mAt1JN/srVW5AMDIFXJXhWjZgmwAnAKBBrO6VDWXg2hi1x+uaWLHI0dUXraUg==",
"packageHashAlgorithm": "SHA512",
"packageSize": 450,
"published": "2017-01-03T08:15:00Z",
"title": "EmptyDependencyVersionRange",
"verbatimVersion": "0.1.0",
"version": "0.1.0",
"dependencyGroups": [
{
"@id": "http://example/data/2017.01.04.08.15.00/emptydependencyversionrange.0.1.0.json#dependencygroup",
"@type": "PackageDependencyGroup",
"dependencies": [
{
"@id": "http://example/data/2017.01.04.08.15.00/emptydependencyversionrange.0.1.0.json#dependencygroup/nuget.versioning",
"@type": "PackageDependency",
"id": "NuGet.Versioning",
"range": ""
}
]
}
],
"packageEntries": [
{
"@id": "http://example/data/2017.01.04.08.15.00/emptydependencyversionrange.0.1.0.json#EmptyDependencyVersionRange.nuspec",
"@type": "PackageEntry",
"compressedLength": 248,
"fullName": "EmptyDependencyVersionRange.nuspec",
"length": 504,
"name": "EmptyDependencyVersionRange.nuspec"
}
],
"@context": {
"@vocab": "http://schema.nuget.org/schema#",
"catalog": "http://schema.nuget.org/catalog#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"dependencies": {
"@id": "dependency",
"@container": "@set"
},
"dependencyGroups": {
"@id": "dependencyGroup",
"@container": "@set"
},
"packageEntries": {
"@id": "packageEntry",
"@container": "@set"
},
"supportedFrameworks": {
"@id": "supportedFramework",
"@container": "@set"
},
"tags": {
"@id": "tag",
"@container": "@set"
},
"published": {
"@type": "xsd:dateTime"
},
"created": {
"@type": "xsd:dateTime"
},
"lastEdited": {
"@type": "xsd:dateTime"
},
"catalog:commitTimeStamp": {
"@type": "xsd:dateTime"
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"@id": "http://example/data/2017.01.04.08.15.00/invaliddependencyversionrange.0.1.0.json",
"@type": [
"PackageDetails",
"catalog:Permalink"
],
"authors": "InvalidDependencyVersionRange",
"catalog:commitId": "4aee0ef4-a039-4460-bd5f-98f944e33289",
"catalog:commitTimeStamp": "2017-01-04T08:15:00Z",
"created": "2017-01-01T08:15:00Z",
"description": "InvalidDependencyVersionRange",
"id": "InvalidDependencyVersionRange",
"isPrerelease": false,
"lastEdited": "2017-01-02T08:15:00Z",
"listed": true,
"packageHash": "RFCB7aV+m/vj0CYW3SmnLUd8jMYYJpOw+fz7hDNERlwUjz2rU+6lCVA2bdIko3YYc68jJN3n07S2OgKrUDwPBg==",
"packageHashAlgorithm": "SHA512",
"packageSize": 473,
"published": "2017-01-03T08:15:00Z",
"title": "InvalidDependencyVersionRange",
"verbatimVersion": "0.1.0",
"version": "0.1.0",
"dependencyGroups": [
{
"@id": "http://example/data/2017.01.04.08.15.00/invaliddependencyversionrange.0.1.0.json#dependencygroup",
"@type": "PackageDependencyGroup",
"dependencies": [
{
"@id": "http://example/data/2017.01.04.08.15.00/invaliddependencyversionrange.0.1.0.json#dependencygroup/nuget.versioning",
"@type": "PackageDependency",
"id": "NuGet.Versioning",
"range": ""
}
]
}
],
"packageEntries": [
{
"@id": "http://example/data/2017.01.04.08.15.00/invaliddependencyversionrange.0.1.0.json#InvalidDependencyVersionRange.nuspec",
"@type": "PackageEntry",
"compressedLength": 267,
"fullName": "InvalidDependencyVersionRange.nuspec",
"length": 530,
"name": "InvalidDependencyVersionRange.nuspec"
}
],
"@context": {
"@vocab": "http://schema.nuget.org/schema#",
"catalog": "http://schema.nuget.org/catalog#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"dependencies": {
"@id": "dependency",
"@container": "@set"
},
"dependencyGroups": {
"@id": "dependencyGroup",
"@container": "@set"
},
"packageEntries": {
"@id": "packageEntry",
"@container": "@set"
},
"supportedFrameworks": {
"@id": "supportedFramework",
"@container": "@set"
},
"tags": {
"@id": "tag",
"@container": "@set"
},
"published": {
"@type": "xsd:dateTime"
},
"created": {
"@type": "xsd:dateTime"
},
"lastEdited": {
"@type": "xsd:dateTime"
},
"catalog:commitTimeStamp": {
"@type": "xsd:dateTime"
}
}
}
Binary file not shown.
Loading

0 comments on commit 90d4f9b

Please sign in to comment.