Skip to content

Commit c08c2c2

Browse files
authored
Add content hash to verify output (#6542)
1 parent 1ac8c51 commit c08c2c2

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/NuGet.Core/NuGet.Commands/Strings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGet.Core/NuGet.Commands/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,4 +1161,7 @@ NuGet requires HTTPS sources. Refer to https://aka.ms/nuget-https-everywhere for
11611161
<value>The following PackageReference item(s) do not have a version specified: {0}</value>
11621162
<comment>0 - List of package names</comment>
11631163
</data>
1164+
<data name="VerifyCommand_ContentHash" xml:space="preserve">
1165+
<value>Content hash: {0}</value>
1166+
</data>
11641167
</root>

src/NuGet.Core/NuGet.Commands/VerifyCommand/VerifyCommandRunner.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ private async Task<int> VerifySignatureForPackageAsync(string packagePath, ILogg
119119
logger.LogMinimal(Environment.NewLine + string.Format(CultureInfo.CurrentCulture,
120120
Strings.VerifyCommand_VerifyingPackage,
121121
packageIdentity.ToString()));
122+
string contentHash = packageReader.GetContentHash(CancellationToken.None);
123+
logger.LogMinimal(string.Format(CultureInfo.CurrentCulture,
124+
Strings.VerifyCommand_ContentHash,
125+
contentHash));
122126
logger.LogInformation($"{packagePath}{Environment.NewLine}");
123127

124128
var logMessages = verificationResult.Results.SelectMany(p => p.Issues).ToList();

test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetVerifyTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using System.Threading;
78
using System.Threading.Tasks;
89
using FluentAssertions;
910
using Microsoft.Internal.NuGet.Testing.SignedPackages;
1011
using Microsoft.Internal.NuGet.Testing.SignedPackages.ChildProcess;
1112
using NuGet.Common;
13+
using NuGet.Packaging;
1214
using NuGet.Test.Utility;
1315
using Test.Utility.Signing;
1416
using Xunit;
@@ -54,6 +56,33 @@ public async Task Verify_UnSignedPackage_Fails()
5456
}
5557
}
5658

59+
[Fact]
60+
public async Task Verify_AnyPackage_OutputsContentHash()
61+
{
62+
// Arrange
63+
using (var packageDir = TestDirectory.Create())
64+
{
65+
var packageId = "Unsigned.PackageX";
66+
var packageVersion = "1.0.0";
67+
var packageFile = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion);
68+
69+
//Act
70+
var result = _dotnetFixture.RunDotnetExpectFailure(
71+
packageDir,
72+
$"nuget verify {packageFile.FullName}",
73+
testOutputHelper: _testOutputHelper);
74+
75+
// Assert
76+
string contentHash;
77+
using (var packageReader = new PackageArchiveReader(packageFile.FullName))
78+
{
79+
contentHash = packageReader.GetContentHash(CancellationToken.None);
80+
}
81+
82+
result.Output.Should().Contain(contentHash);
83+
}
84+
}
85+
5786
[PlatformFact(Platform.Windows, Platform.Linux)]
5887
public void Verify_AuthorSignedAndTimestampedPackageWithOptionAll_Succeeds()
5988
{

0 commit comments

Comments
 (0)