Skip to content
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

Fix for empty Ref Exception #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Src/CoreTests/VulnerabilityReportsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using NuGetDefense;
using NuGetDefense.Core;
using Xunit;

namespace CoreTests
{
public class VulnerabilityReportsTest
{
[Fact]
public void ReportVulnerabilityWithNullReferences()
{
var vulnDict = new Dictionary<string, Dictionary<string, Vulnerability>>()
{
{
"TestPkg", new Dictionary<string, Vulnerability>()
{
{
"CVE-Test", new Vulnerability()
{
Cve = "CVE-Test",
Cwe = "CWE-Test",
CvssScore = 6.6,
Description = "Test Description",
References = null,
Vendor = "Test Vendor",
Vector = Vulnerability.AccessVectorType.NETWORK,
}
}
}

}
};

var pkgs = new NuGetPackage[] {new NuGetPackage() {LineNumber = 1, Id = "TestPkg", Version = "1.0.1"}};

VulnerabilityReports.ReportVulnerabilities(vulnDict, pkgs, "NuGetDefense.dll", false, 0D);
}
}
}
8 changes: 6 additions & 2 deletions Src/NuGetDefense.Core/VulnerabilityReports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ public static void ReportVulnerabilities(
Console.WriteLine($"CWE: {vulnerabilities[cve].Cwe}");
Console.WriteLine($"CVSS Score: {vulnerabilities[cve].CvssScore}");
Console.WriteLine($"CVSS Vector: {vulnerabilities[cve].Vector}");
Console.WriteLine("References:");
foreach (var reference in vulnerabilities[cve].References) Console.WriteLine(reference);
if (vulnerabilities[cve].References != null && vulnerabilities[cve].References.Any())
{
Console.WriteLine("References:");
foreach (var reference in vulnerabilities[cve].References) Console.WriteLine(reference);
}

Console.WriteLine("---------------------------");
}

Expand Down