diff --git a/src/Microsoft.Sbom.Adapters/Adapters/ComponentDetection/ScannedComponentExtensions.cs b/src/Microsoft.Sbom.Adapters/Adapters/ComponentDetection/ScannedComponentExtensions.cs index eb758e38..9fcf58ee 100644 --- a/src/Microsoft.Sbom.Adapters/Adapters/ComponentDetection/ScannedComponentExtensions.cs +++ b/src/Microsoft.Sbom.Adapters/Adapters/ComponentDetection/ScannedComponentExtensions.cs @@ -22,6 +22,7 @@ public static class ScannedComponentExtensions return component.Component switch { CargoComponent cargoComponent => cargoComponent.ToSbomPackage(component), + ConanComponent conanComponent => conanComponent.ToSbomPackage(), CondaComponent condaComponent => condaComponent.ToSbomPackage(), DockerImageComponent dockerImageComponent => dockerImageComponent.ToSbomPackage(), GitComponent gitComponent => gitComponent.ToSbomPackage(), diff --git a/test/Microsoft.Sbom.Adapters.Tests/ComponentDetectionToSBOMPackageAdapterTests.cs b/test/Microsoft.Sbom.Adapters.Tests/ComponentDetectionToSBOMPackageAdapterTests.cs index 55a1561b..f3a19b66 100644 --- a/test/Microsoft.Sbom.Adapters.Tests/ComponentDetectionToSBOMPackageAdapterTests.cs +++ b/test/Microsoft.Sbom.Adapters.Tests/ComponentDetectionToSBOMPackageAdapterTests.cs @@ -128,6 +128,26 @@ public void CargoComponent_ToSbomPackage() Assert.AreEqual(cargoComponent.Version, sbomPackage.PackageVersion); } + [TestMethod] + public void ConanComponent_ToSbomPackage() + { + var md5 = Guid.NewGuid().ToString(); + var sha1Hash = Guid.NewGuid().ToString(); + + var conanComponent = new ConanComponent("name", "version", md5, sha1Hash); + var scannedComponent = new ExtendedScannedComponent() { Component = conanComponent }; + + var sbomPackage = scannedComponent.ToSbomPackage(new AdapterReport()); + + Assert.IsNotNull(sbomPackage.Id); + Assert.IsNotNull(sbomPackage.PackageUrl); + Assert.AreEqual(conanComponent.Name, sbomPackage.PackageName); + Assert.AreEqual(conanComponent.Version, sbomPackage.PackageVersion); + Assert.IsNotNull(sbomPackage.Checksum.First(x => x.ChecksumValue == conanComponent.Md5Hash)); + Assert.IsNotNull(sbomPackage.Checksum.First(x => x.ChecksumValue == conanComponent.Sha1Hash)); + Assert.AreEqual(conanComponent.PackageSourceURL, sbomPackage.PackageSource); + } + [TestMethod] public void CondaComponent_ToSbomPackage() {