-
Notifications
You must be signed in to change notification settings - Fork 697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dotnet list package --vulnerable
uses AuditSources
#6237
base: dev
Are you sure you want to change the base?
Conversation
cb0febb
to
8d2c6eb
Compare
.../NuGet.CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommand.cs
Show resolved
Hide resolved
....CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs
Show resolved
Hide resolved
....CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs
Outdated
Show resolved
Hide resolved
....CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/ListPackageTests.cs
Outdated
Show resolved
Hide resolved
</Project>"; | ||
|
||
// Define the content for assets.json | ||
var assetsContent = @" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use resources for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please elaborate what you meant by resources?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A file like the following: https://github.com/NuGet/NuGet.Client/tree/dev/test/NuGet.Core.Tests/NuGet.Commands.Test/compiler/resources instead of hard coding everything within the test.
} | ||
} | ||
}"; | ||
if (!Directory.Exists(projectFolder)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar feedback on the reability of the tests, consider whether these are needed or if there's a better way to priming all this data.
Does the project structure really matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I have cleaned up the tests to make them more readable. Please let me know if you have more suggestions
....CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs
Outdated
Show resolved
Hide resolved
....CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs
Outdated
Show resolved
Hide resolved
9e32cfa
to
8a89814
Compare
8a89814
to
c04b00f
Compare
.../NuGet.CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommand.cs
Outdated
Show resolved
Hide resolved
{ | ||
projectModel.AddProjectInformation(ProblemType.Error, ex.Message); | ||
await GetVulnerabilitiesFromAuditSourcesAsync(listPackageArgs, listPackageReportModel, projectModel, frameworks); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return seems like a bug.
When we use vulnerability from audit sources, we return and we don't print packages later one.
This should probably be an if/else.
btw, if I'm right and this is a bug, it'd be great to ensure we have a test that would've caught this scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code at
Line 140 in fa6bd36
bool printPackages = FilterPackages(frameworks, listPackageArgs); |
For example, when using --vulnerable
, it removes packages that do not have any reported vulnerabilities.
However, the actual printing occurs at a higher level in the execution flow:
Line 40 in fa6bd36
reportRenderer.Render(reportModel); |
In the new implementation, when retrieving vulnerabilities from AuditSources, only vulnerable packages are added. As a result, there's no need to execute additional filtering logic to remove non-vulnerable packages.
Thus, the printPackages
check is redundant because GetVulnerabilitiesFromAuditSourcesAsync
only adds vulnerable packages.
....CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs
Outdated
Show resolved
Hide resolved
....CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/ListPackageTests.cs
Outdated
Show resolved
Hide resolved
</Project>"; | ||
|
||
// Define the content for assets.json | ||
var assetsContent = @" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A file like the following: https://github.com/NuGet/NuGet.Client/tree/dev/test/NuGet.Core.Tests/NuGet.Commands.Test/compiler/resources instead of hard coding everything within the test.
Bug
Fixes:
Description
Design Spec: https://github.com/NuGet/Home/blob/dev/accepted/2024/Dotnet-list-package-vulnerable-uses-auditsources.md
This PR updates
dotnet list package --vulnerable
to use user configured<AuditSources>
.Currently, the command only looks into
<PackageSources>
to load vulnerability data. However, with the introduction of NuGet Audit, other commands now support<AuditSources>
to specify vulnerability data sources. This PR makes suredotnet list package --vulnerable
is also up to date and supports<AuditSources>
In order to do a manual test, I specified a package that has only one vulnerability data source. That source is only specified as an Audit source. This is what running
dotnet list package --vulnerable
results in before and after this PRBefore
After
PR Checklist
dotnet list package --vulnerable
uses AuditSources Home#14021