Skip to content

Commit 12388f4

Browse files
Copilotnkolev92
andcommitted
Fix NuGetAuditSuppress with packages.config only applying first suppression
Co-authored-by: nkolev92 <[email protected]> Agent-Logs-Url: https://github.com/NuGet/NuGet.Client/sessions/95c933f0-4368-4fdd-8e07-f072331801a7
1 parent cb58a2a commit 12388f4

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/NuGet.Clients/NuGet.SolutionRestoreManager/SolutionRestoreJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ static HashSet<string> GetSuppressions(VsMSBuildNuGetProject msbuildProject)
803803
var suppressions = new HashSet<string>(items.Count, StringComparer.Ordinal);
804804
for (int i = 0; i < items.Count; i++)
805805
{
806-
suppressions.Add(items[0].id);
806+
suppressions.Add(items[i].id);
807807
}
808808
return suppressions;
809809
}

test/NuGet.Tests.Apex/NuGet.Tests.Apex/NuGetEndToEndTests/NuGetAuditTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ public class NuGetAuditTests : SharedVisualStudioHostTestClass
2727
[Timeout(DefaultTimeout)]
2828
public async Task PackagesConfig_SuppressAdvisory()
2929
{
30-
// 1. Create Directory.Build.props with suppression for package.A cve1
31-
// 2. Create mock server with package.A with cve1 and cve2
30+
// 1. Create Directory.Build.props with suppression for package.A cve1 and cve2
31+
// 2. Create mock server with package.A with cve1, cve2, and cve3
3232
// 3. Add mock server to nuget.config
3333
// 3. Create packages.config project
3434
// 4. Install package.A
35-
// 5. check error list to see if only cve2 is listed
35+
// 5. check error list to see if only cve3 is listed
3636

3737
// Arrange
3838
SimpleTestPathContext testPathContext = new();
3939
var dbpContents = @"<Project>
4040
<ItemGroup>
4141
<NuGetAuditSuppress Include=""https://cve.test/1"" />
42+
<NuGetAuditSuppress Include=""https://cve.test/2"" />
4243
</ItemGroup>
4344
</Project>";
4445
File.WriteAllText(Path.Combine(testPathContext.SolutionRoot, "Directory.Build.props"), dbpContents);
@@ -48,6 +49,7 @@ public async Task PackagesConfig_SuppressAdvisory()
4849
{
4950
(new Uri("https://cve.test/1"), PackageVulnerabilitySeverity.High, VersionRange.Parse("(, 2.0.0)")),
5051
(new Uri("https://cve.test/2"), PackageVulnerabilitySeverity.High, VersionRange.Parse("(, 2.0.0)")),
52+
(new Uri("https://cve.test/3"), PackageVulnerabilitySeverity.High, VersionRange.Parse("(, 2.0.0)")),
5153
});
5254

5355
await CommonUtility.CreatePackageInSourceAsync(testPathContext.PackageSource, TestPackageName, TestPackageVersionV1);
@@ -71,7 +73,7 @@ public async Task PackagesConfig_SuppressAdvisory()
7173

7274
var errors = VisualStudio.ObjectModel.Shell.ToolWindows.ErrorList.AllItems.Select(i => i.Description).ToList();
7375
errors.Where(msg => msg.Contains(TestPackageName)).Should().ContainSingle();
74-
errors.Single(msg => msg.Contains(TestPackageName)).Should().Contain("https://cve.test/2");
76+
errors.Single(msg => msg.Contains(TestPackageName)).Should().Contain("https://cve.test/3");
7577
}
7678
}
7779
}

0 commit comments

Comments
 (0)