From 3506f99c5d9b45214ef9405708dba5224bd731aa Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Thu, 11 Jul 2024 20:09:32 -0700 Subject: [PATCH 01/19] Bring changes from feautre branch --- .../Microsoft.Sbom.Targets.targets | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.targets b/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.targets index 5ae9c17c..79169c96 100644 --- a/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.targets +++ b/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.targets @@ -20,7 +20,23 @@ - + + false + $(OutDir) + $(MSBuildProjectDirectory) + $(Authors) + $(AssemblyName) + $(PackageId) + $(AssemblyName) + $(Version) + 1.0.0 + http://spdx.org/spdxdocs/$(SbomGenerationPackageName) + false + false + information + SPDX:2.2 + true + From 2e264a2bf06a22227fa0510aebf84f0e7137607a Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Thu, 11 Jul 2024 20:14:34 -0700 Subject: [PATCH 02/19] Make the Targets.Tests project also target .NET Framework --- Directory.Packages.props | 3 +- .../AbstractGenerateSBomTaskInputTests.cs | 15 ++++----- .../AbstractGenerateSbomTaskTests.cs | 32 +++++++++++-------- .../GenerateSbomTaskSPDX_2_2InputTests.cs | 4 +-- .../GenerateSbomTaskSPDX_2_2Tests.cs | 6 ++-- .../Microsoft.Sbom.Targets.Tests.csproj | 14 +++++--- .../Utility/GeneratedSbomValidator.cs | 13 ++++---- 7 files changed, 47 insertions(+), 40 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 939606e8..d4f4fded 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -16,6 +16,7 @@ + @@ -57,4 +58,4 @@ - + \ No newline at end of file diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs index 7afe52e5..aedb06d7 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs @@ -6,7 +6,6 @@ using System.IO; using System.Text.RegularExpressions; using Microsoft.Build.Framework; -using Microsoft.Sbom.Contracts; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -15,7 +14,7 @@ namespace Microsoft.Sbom.Targets.Tests; [TestClass] public abstract class AbstractGenerateSBomTaskInputTests { - internal abstract SbomSpecification SbomSpecification { get; } + internal abstract string SbomSpecification { get; } internal static readonly string CurrentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); internal static readonly string DefaultManifestDirectory = Path.Combine(CurrentDirectory, "_manifest"); @@ -78,7 +77,7 @@ public void Sbom_Fails_With_Null_Empty_And_WhiteSpace_Required_Params( PackageName = packageName, PackageVersion = packageVersion, NamespaceBaseUri = namespaceBaseUri, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, BuildEngine = this.buildEngine.Object }; @@ -137,7 +136,7 @@ public void Sbom_Fails_With_Invalid_NamespaceBaseUri(string namespaceBaseUri) PackageName = PackageName, PackageVersion = PackageVersion, NamespaceBaseUri = namespaceBaseUri, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, BuildEngine = this.buildEngine.Object }; @@ -173,7 +172,7 @@ public void Sbom_Generation_Fails_For_Invalid_NamespaceUriUniquePart(string name PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, NamespaceUriUniquePart = namespaceUriUniquePart, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, BuildEngine = this.buildEngine.Object }; @@ -204,7 +203,7 @@ public void Sbom_Generation_Succeeds_For_Null_Verbosity() PackageName = PackageName, PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, Verbosity = null, BuildEngine = this.buildEngine.Object }; @@ -239,7 +238,7 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, Verbosity = "Invalid Verbosity", - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, BuildEngine = this.buildEngine.Object }; @@ -277,7 +276,7 @@ public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVer PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, Verbosity = inputVerbosity, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, BuildEngine = this.buildEngine.Object }; diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs index c43d072d..f7b9889c 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.IO; using Microsoft.Build.Framework; -using Microsoft.Sbom.Contracts; using Microsoft.Sbom.Targets.Tests.Utility; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -17,7 +16,9 @@ namespace Microsoft.Sbom.Targets.Tests; [TestClass] public abstract class AbstractGenerateSbomTaskTests { - internal abstract SbomSpecification SbomSpecification { get; } + internal abstract string SbomSpecificationName { get; } + + internal abstract string SbomSpecificationVersion { get; } internal static readonly string CurrentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); internal static readonly string DefaultManifestDirectory = Path.Combine(CurrentDirectory, "_manifest"); @@ -32,7 +33,9 @@ public abstract class AbstractGenerateSbomTaskTests internal string ManifestPath; internal GeneratedSbomValidator GeneratedSbomValidator; - internal string SbomSpecificationDirectoryName => $"{this.SbomSpecification.Name}_{this.SbomSpecification.Version}".ToLowerInvariant(); + internal string SbomSpecification => $"{this.SbomSpecificationName}:{this.SbomSpecificationVersion}"; + + internal string SbomSpecificationDirectoryName => $"{this.SbomSpecificationName}_{this.SbomSpecificationVersion}".ToLowerInvariant(); [TestInitialize] public void Startup() @@ -70,7 +73,10 @@ public void Sbom_Is_Successfully_Generated() PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = "C:\\Users\\gustavoca\\Repos\\github\\sbom-tool\\src\\Microsoft.Sbom.Tool\\bin\\Debug\\net8.0", +#endif }; // Act @@ -100,7 +106,7 @@ public void Sbom_Is_Successfully_Generated_Valid_URI(string namespaceBaseUri) PackageVersion = PackageVersion, NamespaceBaseUri = namespaceBaseUri, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, }; // Act @@ -126,7 +132,7 @@ public void Sbom_Is_Successfully_Generated_Valid_RequiredParams(string packageSu PackageVersion = packageVersion, NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, }; // Act @@ -176,7 +182,7 @@ public void Sbom_Is_Successfully_Generated_In_Specified_Location() PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, }; // Act @@ -201,7 +207,7 @@ public void Sbom_Generation_Fails_With_NotFound_BuildDropPath() PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, }; // Act @@ -224,7 +230,7 @@ public void Sbom_Generation_Fails_With_NotFound_BuildComponentPath() PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, }; // Act @@ -248,7 +254,7 @@ public void Sbom_Generation_Fails_With_NotFound_ExternalDocumentListFile() PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, }; // Act @@ -272,7 +278,7 @@ public void Sbom_Generation_Fails_With_NotFound_ManifestDirPath() PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, }; // Act @@ -299,7 +305,7 @@ public void Sbom_Is_Successfully_Generated_With_Component_Path() PackageVersion = PackageVersion, NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, }; // Act @@ -327,7 +333,7 @@ public void Sbom_Is_Successfully_Generated_With_Unique_Namespace_Part_Defined(st NamespaceBaseUri = NamespaceBaseUri, NamespaceUriUniquePart = uniqueNamespacePart, BuildEngine = this.BuildEngine.Object, - ManifestInfo = this.SbomSpecification.ToString(), + ManifestInfo = this.SbomSpecification, }; // Act diff --git a/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2InputTests.cs b/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2InputTests.cs index 92431f09..b7d48a72 100644 --- a/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2InputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2InputTests.cs @@ -3,8 +3,6 @@ namespace Microsoft.Sbom.Targets.Tests; -using Microsoft.Sbom.Api.Utils; -using Microsoft.Sbom.Contracts; using Microsoft.VisualStudio.TestTools.UnitTesting; /// @@ -13,5 +11,5 @@ namespace Microsoft.Sbom.Targets.Tests; [TestClass] public class GenerateSbomTaskSPDX_2_2InputTests : AbstractGenerateSBomTaskInputTests { - internal override SbomSpecification SbomSpecification => Constants.SPDX22Specification; + internal override string SbomSpecification => "SPDX:2.2"; } diff --git a/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2Tests.cs b/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2Tests.cs index a3acf920..63e66701 100644 --- a/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2Tests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2Tests.cs @@ -8,8 +8,6 @@ namespace Microsoft.Sbom.Targets.Tests; using System.Linq; using System.Text; using System.Threading.Tasks; -using Microsoft.Sbom.Api.Utils; -using Microsoft.Sbom.Contracts; using Microsoft.VisualStudio.TestTools.UnitTesting; /// @@ -18,5 +16,7 @@ namespace Microsoft.Sbom.Targets.Tests; [TestClass] public class GenerateSbomTaskSPDX_2_2Tests : AbstractGenerateSbomTaskTests { - internal override SbomSpecification SbomSpecification => Constants.SPDX22Specification; + internal override string SbomSpecificationName => "SPDX"; + + internal override string SbomSpecificationVersion => "2.2"; } diff --git a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj index 4278eba1..f5465388 100644 --- a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj +++ b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj @@ -1,11 +1,10 @@ - net8.0 + net8.0;net472 false True Microsoft.Sbom.Targets.Tests - $(StrongNameSigningKeyFilePath) @@ -13,12 +12,17 @@ + + + + - - - + + + + diff --git a/test/Microsoft.Sbom.Targets.Tests/Utility/GeneratedSbomValidator.cs b/test/Microsoft.Sbom.Targets.Tests/Utility/GeneratedSbomValidator.cs index 5e775811..aaf01f63 100644 --- a/test/Microsoft.Sbom.Targets.Tests/Utility/GeneratedSbomValidator.cs +++ b/test/Microsoft.Sbom.Targets.Tests/Utility/GeneratedSbomValidator.cs @@ -10,8 +10,6 @@ namespace Microsoft.Sbom.Targets.Tests.Utility; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using Microsoft.Sbom.Api.Utils; -using Microsoft.Sbom.Contracts; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; @@ -21,9 +19,10 @@ namespace Microsoft.Sbom.Targets.Tests.Utility; #pragma warning disable CA5350 // Suppress Do Not Use Weak Cryptographic Algorithms as we use SHA1 intentionally internal class GeneratedSbomValidator { - private readonly SbomSpecification sbomSpecification; + private const string SPDX22Specification = "SPDX:2.2"; + private readonly string sbomSpecification; - public GeneratedSbomValidator(SbomSpecification sbomSpecification) + public GeneratedSbomValidator(string sbomSpecification) { this.sbomSpecification = sbomSpecification; } @@ -36,7 +35,7 @@ internal void AssertSbomIsValid(string manifestPath, string buildDropPath, strin var manifestContent = File.ReadAllText(manifestPath); var manifest = JsonConvert.DeserializeObject(manifestContent); - if (this.sbomSpecification.Equals(Constants.SPDX22Specification)) + if (this.sbomSpecification.Equals(SPDX22Specification)) { // Check the manifest has expected file data var filesValue = manifest["files"]; @@ -92,7 +91,7 @@ internal void AssertSbomIsValid(string manifestPath, string buildDropPath, strin } else { - Assert.IsTrue(namespaceValue.Contains($"{expectedNamespaceUriBase.Trim()}/{expectedPackageName}/{expectedPackageVersion}", StringComparison.InvariantCultureIgnoreCase)); + Assert.IsTrue(namespaceValue.Contains($"{expectedNamespaceUriBase.Trim()}/{expectedPackageName}/{expectedPackageVersion}")); } } } @@ -128,7 +127,7 @@ private IDictionary> GetBuildDropFileHashes( private IList<(string, Func)> GetListOfHashAlgorithmCreators() { - if (this.sbomSpecification.Equals(Constants.SPDX22Specification)) + if (this.sbomSpecification.Equals(SPDX22Specification)) { return [("SHA1", SHA1.Create), ("SHA256", SHA256.Create)]; } From 3cbcde3d0e45ea9c6d161e17af9810eb80cdbe05 Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Fri, 12 Jul 2024 21:11:55 -0700 Subject: [PATCH 03/19] Remove props file --- .../Microsoft.Sbom.Targets.csproj | 1 - .../Microsoft.Sbom.Targets.props | 21 ------------------- 2 files changed, 22 deletions(-) delete mode 100644 src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.props diff --git a/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.csproj b/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.csproj index f51b5928..be7eabbc 100644 --- a/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.csproj +++ b/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.csproj @@ -59,7 +59,6 @@ - diff --git a/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.props b/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.props deleted file mode 100644 index 4593f8db..00000000 --- a/src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.props +++ /dev/null @@ -1,21 +0,0 @@ - - - false - - $(OutDir) - $(MSBuildProjectDirectory) - $(Authors) - $(AssemblyName) - $(PackageId) - $(AssemblyName) - $(Version) - 1.0.0 - http://spdx.org/spdxdocs/$(SbomGenerationPackageName)" - false - false - LogAlways - SPDX:2.2 - true - - From 8fa8adf340d4eff2fbf7a721e586a8aaf3d043f8 Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Fri, 12 Jul 2024 21:14:08 -0700 Subject: [PATCH 04/19] Implement tests for MSBuild Full version of the task --- src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs | 3 +- .../AbstractGenerateSBomTaskInputTests.cs | 99 ++++++++++++++----- .../AbstractGenerateSbomTaskTests.cs | 91 +++++++++++++++-- .../Microsoft.Sbom.Targets.Tests.csproj | 7 +- .../Utility/GeneratedSbomValidator.cs | 2 +- 5 files changed, 162 insertions(+), 40 deletions(-) diff --git a/src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs b/src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs index a050412a..3a6aa065 100644 --- a/src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs +++ b/src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs @@ -3,6 +3,7 @@ namespace Microsoft.Sbom.Targets; +using System; using System.Diagnostics.Tracing; using System.IO; using Microsoft.Build.Utilities; @@ -93,7 +94,7 @@ private void SetOutputImportance() { this.StandardOutputImportance = "High"; - if (this.Verbosity.ToLower().Equals("Fatal")) + if (this.Verbosity.ToLower().Equals("fatal")) { this.StandardOutputImportance = "Low"; } diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs index aedb06d7..5d5ee902 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -16,16 +17,20 @@ public abstract class AbstractGenerateSBomTaskInputTests { internal abstract string SbomSpecification { get; } - internal static readonly string CurrentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + internal static readonly string CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); internal static readonly string DefaultManifestDirectory = Path.Combine(CurrentDirectory, "_manifest"); internal static readonly string TemporaryDirectory = Path.Combine(CurrentDirectory, "_temporary"); internal static readonly string BuildComponentPath = Path.Combine(CurrentDirectory, "..", "..", ".."); internal static readonly string ExternalDocumentListFile = Path.GetRandomFileName(); + private static readonly AssemblyConfigurationAttribute AssemblyConfigurationAttribute = typeof(AbstractGenerateSBomTaskInputTests).Assembly.GetCustomAttribute(); + private static readonly string BuildConfigurationName = AssemblyConfigurationAttribute?.Configuration; internal const string PackageSupplier = "Test-Microsoft"; internal const string PackageName = "CoseSignTool"; internal const string PackageVersion = "0.0.1"; internal const string NamespaceBaseUri = "https://base0.uri"; + internal static string SbomToolPath = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "..", "src", "Microsoft.Sbom.Tool", "bin", BuildConfigurationName, "net8.0", "publish"); + private Mock buildEngine; private List errors; @@ -67,7 +72,8 @@ public void Sbom_Fails_With_Null_Empty_And_WhiteSpace_Required_Params( string packageSupplier, string packageName, string packageVersion, - string namespaceBaseUri) + string namespaceBaseUri, + string sbomToolPath) { // Arrange. var task = new GenerateSbom @@ -78,7 +84,10 @@ public void Sbom_Fails_With_Null_Empty_And_WhiteSpace_Required_Params( PackageVersion = packageVersion, NamespaceBaseUri = namespaceBaseUri, ManifestInfo = this.SbomSpecification, - BuildEngine = this.buildEngine.Object + BuildEngine = this.buildEngine.Object, +#if NET472 + SbomToolPath = sbomToolPath, +#endif }; // Act @@ -90,29 +99,38 @@ public void Sbom_Fails_With_Null_Empty_And_WhiteSpace_Required_Params( private static IEnumerable GetNullRequiredParamsData() { - yield return new object[] { null, PackageSupplier, PackageName, PackageVersion, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, null, PackageName, PackageVersion, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, PackageSupplier, null, PackageVersion, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, null, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, PackageVersion, null }; + yield return new object[] { null, PackageSupplier, PackageName, PackageVersion, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, null, PackageName, PackageVersion, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, PackageSupplier, null, PackageVersion, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, null, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, PackageVersion, null, SbomToolPath }; +#if NET472 + yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, PackageVersion, NamespaceBaseUri, null }; +#endif } private static IEnumerable GetEmptyRequiredParamsData() { - yield return new object[] { string.Empty, PackageSupplier, PackageName, PackageVersion, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, string.Empty, PackageName, PackageVersion, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, PackageSupplier, string.Empty, PackageVersion, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, string.Empty, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, PackageVersion, string.Empty }; + yield return new object[] { string.Empty, PackageSupplier, PackageName, PackageVersion, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, string.Empty, PackageName, PackageVersion, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, PackageSupplier, string.Empty, PackageVersion, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, string.Empty, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, PackageVersion, string.Empty, SbomToolPath }; +#if NET472 + yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, PackageVersion, NamespaceBaseUri, string.Empty }; +#endif } private static IEnumerable GetWhiteSpace_Tabs_NewLineParamsData() { - yield return new object[] { " ", PackageSupplier, PackageName, PackageVersion, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, "\n", PackageName, PackageVersion, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, PackageSupplier, "\t", PackageVersion, NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, " \n \t \n \t \n ", NamespaceBaseUri }; - yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, PackageVersion, "\t \t \t " }; + yield return new object[] { " ", PackageSupplier, PackageName, PackageVersion, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, "\n", PackageName, PackageVersion, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, PackageSupplier, "\t", PackageVersion, NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, " \n \t \n \t \n ", NamespaceBaseUri, SbomToolPath }; + yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, PackageVersion, "\t \t \t ", SbomToolPath }; +#if NET472 + yield return new object[] { CurrentDirectory, PackageSupplier, PackageName, PackageVersion, NamespaceBaseUri, "\t \t \t " }; +#endif } /// @@ -137,7 +155,10 @@ public void Sbom_Fails_With_Invalid_NamespaceBaseUri(string namespaceBaseUri) PackageVersion = PackageVersion, NamespaceBaseUri = namespaceBaseUri, ManifestInfo = this.SbomSpecification, - BuildEngine = this.buildEngine.Object + BuildEngine = this.buildEngine.Object, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -173,7 +194,10 @@ public void Sbom_Generation_Fails_For_Invalid_NamespaceUriUniquePart(string name NamespaceBaseUri = NamespaceBaseUri, NamespaceUriUniquePart = namespaceUriUniquePart, ManifestInfo = this.SbomSpecification, - BuildEngine = this.buildEngine.Object + BuildEngine = this.buildEngine.Object, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -193,7 +217,9 @@ public void Sbom_Generation_Succeeds_For_Null_Verbosity() // Arrange // If Verbosity is null, the default value should be Verbose and is printed in the // tool's standard output. +#if !NET472 var pattern = new Regex("Verbosity=.*Value=Verbose"); +#endif var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var task = new GenerateSbom @@ -205,7 +231,10 @@ public void Sbom_Generation_Succeeds_For_Null_Verbosity() NamespaceBaseUri = NamespaceBaseUri, ManifestInfo = this.SbomSpecification, Verbosity = null, - BuildEngine = this.buildEngine.Object + BuildEngine = this.buildEngine.Object, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -214,7 +243,9 @@ public void Sbom_Generation_Succeeds_For_Null_Verbosity() // Assert Assert.IsTrue(result); +#if !NET472 Assert.IsTrue(pattern.IsMatch(output)); +#endif } /// @@ -225,9 +256,11 @@ public void Sbom_Generation_Succeeds_For_Null_Verbosity() public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() { // Arrange - // If an invalid Verbosity is specified, the default value should be Verbose and is printed in the - // tool's standard output. + // If an invalid Verbosity is specified, the default value should be Verbose. It is also printed in the + // tool's standard output for the MSBuild Core task. +#if !NET472 var pattern = new Regex("Verbosity=.*Value=Verbose"); +#endif var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var task = new GenerateSbom @@ -239,7 +272,10 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() NamespaceBaseUri = NamespaceBaseUri, Verbosity = "Invalid Verbosity", ManifestInfo = this.SbomSpecification, - BuildEngine = this.buildEngine.Object + BuildEngine = this.buildEngine.Object, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -248,7 +284,9 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() // Assert Assert.IsTrue(result); +#if !NET472 Assert.IsTrue(pattern.IsMatch(output)); +#endif } /// @@ -265,7 +303,9 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVerbosity, string mappedVerbosity) { // Arrange +#if !NET472 var pattern = new Regex($"Verbosity=.*Value={mappedVerbosity}"); +#endif var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var task = new GenerateSbom @@ -277,7 +317,10 @@ public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVer NamespaceBaseUri = NamespaceBaseUri, Verbosity = inputVerbosity, ManifestInfo = this.SbomSpecification, - BuildEngine = this.buildEngine.Object + BuildEngine = this.buildEngine.Object, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -285,7 +328,9 @@ public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVer var output = stringWriter.ToString(); // Assert - Assert.IsTrue(result); - Assert.IsTrue(pattern.IsMatch(output)); + Assert.IsTrue(result, $"result: {result} is not set to true"); +#if !NET472 + Assert.IsTrue(pattern.IsMatch(output), $"output: `{output}` doesnt contain {pattern}"); +#endif } } diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs index f7b9889c..85be4b26 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; +using System.Reflection; using Microsoft.Build.Framework; using Microsoft.Sbom.Targets.Tests.Utility; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -20,9 +21,14 @@ public abstract class AbstractGenerateSbomTaskTests internal abstract string SbomSpecificationVersion { get; } - internal static readonly string CurrentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + internal static readonly string CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); internal static readonly string DefaultManifestDirectory = Path.Combine(CurrentDirectory, "_manifest"); internal static readonly string TemporaryDirectory = Path.Combine(CurrentDirectory, "_temp"); + internal static readonly string ExternalDocumentListFile = Path.GetRandomFileName(); + private static readonly AssemblyConfigurationAttribute AssemblyConfigurationAttribute = typeof(AbstractGenerateSBomTaskInputTests).Assembly.GetCustomAttribute(); + private static readonly string BuildConfigurationName = AssemblyConfigurationAttribute?.Configuration; + internal static string SbomToolPath = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "..", "src", "Microsoft.Sbom.Tool", "bin", BuildConfigurationName, "net8.0", "publish"); + internal const string PackageSupplier = "Test-Microsoft"; internal const string PackageName = "CoseSignTool"; internal const string PackageVersion = "0.0.1"; @@ -37,14 +43,8 @@ public abstract class AbstractGenerateSbomTaskTests internal string SbomSpecificationDirectoryName => $"{this.SbomSpecificationName}_{this.SbomSpecificationVersion}".ToLowerInvariant(); - [TestInitialize] - public void Startup() + private void CleanupManifestDirectory() { - // Setup the build engine - this.BuildEngine = new Mock(); - this.Errors = new List(); - this.BuildEngine.Setup(x => x.LogErrorEvent(It.IsAny())).Callback(e => Errors.Add(e)); - // Clean up the manifest directory if (Directory.Exists(DefaultManifestDirectory)) { @@ -56,11 +56,28 @@ public void Startup() { Directory.Delete(TemporaryDirectory, true); } + } + + [TestInitialize] + public void Startup() + { + // Setup the build engine + this.BuildEngine = new Mock(); + this.Errors = new List(); + this.BuildEngine.Setup(x => x.LogErrorEvent(It.IsAny())).Callback(e => Errors.Add(e)); + + this.CleanupManifestDirectory(); this.ManifestPath = Path.Combine(DefaultManifestDirectory, this.SbomSpecificationDirectoryName, "manifest.spdx.json"); this.GeneratedSbomValidator = new(this.SbomSpecification); } + [TestCleanup] + public void Cleanup() + { + this.CleanupManifestDirectory(); + } + [TestMethod] public void Sbom_Is_Successfully_Generated() { @@ -75,7 +92,7 @@ public void Sbom_Is_Successfully_Generated() BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, #if NET472 - SbomToolPath = "C:\\Users\\gustavoca\\Repos\\github\\sbom-tool\\src\\Microsoft.Sbom.Tool\\bin\\Debug\\net8.0", + SbomToolPath = SbomToolPath, #endif }; @@ -107,6 +124,9 @@ public void Sbom_Is_Successfully_Generated_Valid_URI(string namespaceBaseUri) NamespaceBaseUri = namespaceBaseUri, BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -133,6 +153,9 @@ public void Sbom_Is_Successfully_Generated_Valid_RequiredParams(string packageSu NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -183,6 +206,9 @@ public void Sbom_Is_Successfully_Generated_In_Specified_Location() NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -208,6 +234,9 @@ public void Sbom_Generation_Fails_With_NotFound_BuildDropPath() NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -231,6 +260,9 @@ public void Sbom_Generation_Fails_With_NotFound_BuildComponentPath() NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -255,6 +287,9 @@ public void Sbom_Generation_Fails_With_NotFound_ExternalDocumentListFile() NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -279,6 +314,9 @@ public void Sbom_Generation_Fails_With_NotFound_ManifestDirPath() NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -306,6 +344,9 @@ public void Sbom_Is_Successfully_Generated_With_Component_Path() NamespaceBaseUri = NamespaceBaseUri, BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act @@ -334,13 +375,43 @@ public void Sbom_Is_Successfully_Generated_With_Unique_Namespace_Part_Defined(st NamespaceUriUniquePart = uniqueNamespacePart, BuildEngine = this.BuildEngine.Object, ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif }; // Act var result = task.Execute(); // Assert - Assert.IsTrue(result); + Assert.IsTrue(result, $"{result} is not set to true."); this.GeneratedSbomValidator.AssertSbomIsValid(this.ManifestPath, CurrentDirectory, PackageName, PackageVersion, PackageSupplier, NamespaceBaseUri, expectedNamespaceUriUniquePart: uniqueNamespacePart); } + + // TODO: Add test for SBOM Tool not found +#if NET472 + [TestMethod] + public void Sbom_Generation_Fails_With_Tool_Path_Not_Found() + { + // Arrange + var task = new GenerateSbom + { + BuildDropPath = CurrentDirectory, + PackageSupplier = PackageSupplier, + PackageName = PackageName, + PackageVersion = PackageVersion, + NamespaceBaseUri = NamespaceBaseUri, + BuildEngine = this.BuildEngine.Object, + ManifestInfo = this.SbomSpecification, + SbomToolPath = "C:\\Not-Found\\Path\\", + }; + + // Act + var result = task.Execute(); + + // Assert + Assert.IsFalse(result); + Assert.IsFalse(Directory.Exists(DefaultManifestDirectory)); + } +#endif } diff --git a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj index f5465388..bed60279 100644 --- a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj +++ b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj @@ -5,6 +5,7 @@ false True Microsoft.Sbom.Targets.Tests + net8.0 @@ -17,7 +18,11 @@ - + + + + + diff --git a/test/Microsoft.Sbom.Targets.Tests/Utility/GeneratedSbomValidator.cs b/test/Microsoft.Sbom.Targets.Tests/Utility/GeneratedSbomValidator.cs index aaf01f63..1ee8c094 100644 --- a/test/Microsoft.Sbom.Targets.Tests/Utility/GeneratedSbomValidator.cs +++ b/test/Microsoft.Sbom.Targets.Tests/Utility/GeneratedSbomValidator.cs @@ -42,7 +42,7 @@ internal void AssertSbomIsValid(string manifestPath, string buildDropPath, strin Assert.IsNotNull(filesValue); var expectedFilesHashes = this.GetBuildDropFileHashes(buildDropPath); - Assert.AreEqual(expectedFilesHashes.Count, filesValue.Count); + Assert.AreEqual(expectedFilesHashes.Count, filesValue.Count, $"Manifest {manifestPath} has {filesValue.Count} files instead of {expectedFilesHashes.Count}"); foreach (var file in filesValue) { var filePath = Path.GetFullPath(Path.Combine(buildDropPath, (string)file["fileName"])); From 02e2a1c58ec3484585ab59c4b8d8bc4aa34549c7 Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Tue, 16 Jul 2024 18:24:14 -0700 Subject: [PATCH 05/19] Simplify how the CLI tool is called from the tests. --- .../AbstractGenerateSBomTaskInputTests.cs | 6 +----- .../AbstractGenerateSbomTaskTests.cs | 4 +--- .../Microsoft.Sbom.Targets.Tests.csproj | 9 ++++++++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs index 5d5ee902..fe562576 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs @@ -22,15 +22,11 @@ public abstract class AbstractGenerateSBomTaskInputTests internal static readonly string TemporaryDirectory = Path.Combine(CurrentDirectory, "_temporary"); internal static readonly string BuildComponentPath = Path.Combine(CurrentDirectory, "..", "..", ".."); internal static readonly string ExternalDocumentListFile = Path.GetRandomFileName(); - private static readonly AssemblyConfigurationAttribute AssemblyConfigurationAttribute = typeof(AbstractGenerateSBomTaskInputTests).Assembly.GetCustomAttribute(); - private static readonly string BuildConfigurationName = AssemblyConfigurationAttribute?.Configuration; + internal static string SbomToolPath = Path.Combine(Directory.GetCurrentDirectory(), "sbom-tool"); internal const string PackageSupplier = "Test-Microsoft"; internal const string PackageName = "CoseSignTool"; internal const string PackageVersion = "0.0.1"; internal const string NamespaceBaseUri = "https://base0.uri"; - - internal static string SbomToolPath = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "..", "src", "Microsoft.Sbom.Tool", "bin", BuildConfigurationName, "net8.0", "publish"); - private Mock buildEngine; private List errors; diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs index 85be4b26..2dacf4a1 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs @@ -25,9 +25,7 @@ public abstract class AbstractGenerateSbomTaskTests internal static readonly string DefaultManifestDirectory = Path.Combine(CurrentDirectory, "_manifest"); internal static readonly string TemporaryDirectory = Path.Combine(CurrentDirectory, "_temp"); internal static readonly string ExternalDocumentListFile = Path.GetRandomFileName(); - private static readonly AssemblyConfigurationAttribute AssemblyConfigurationAttribute = typeof(AbstractGenerateSBomTaskInputTests).Assembly.GetCustomAttribute(); - private static readonly string BuildConfigurationName = AssemblyConfigurationAttribute?.Configuration; - internal static string SbomToolPath = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "..", "src", "Microsoft.Sbom.Tool", "bin", BuildConfigurationName, "net8.0", "publish"); + internal static string SbomToolPath = Path.Combine(Directory.GetCurrentDirectory(), "sbom-tool"); internal const string PackageSupplier = "Test-Microsoft"; internal const string PackageName = "CoseSignTool"; diff --git a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj index bed60279..1c2f8025 100644 --- a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj +++ b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj @@ -6,6 +6,7 @@ True Microsoft.Sbom.Targets.Tests net8.0 + $(MSBuildThisFileDirectory)..\..\src\Microsoft.Sbom.Tool\ @@ -20,7 +21,13 @@ - + + + <_SbomToolFiles Include="$(SBOMCLIToolProjectDir)bin\$(Configuration)\$(SbomCLIToolTargetFramework)\publish\**\*.*"> + false + + + From fbc822f203815af6407e6fb872984fe6e86890fa Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Tue, 16 Jul 2024 19:41:07 -0700 Subject: [PATCH 06/19] Add test for file being in use. --- .../AbstractGenerateSbomTaskTests.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs index 2dacf4a1..5a9c0236 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs @@ -412,4 +412,42 @@ public void Sbom_Generation_Fails_With_Tool_Path_Not_Found() Assert.IsFalse(Directory.Exists(DefaultManifestDirectory)); } #endif + + // This test is failing due to this issue: https://github.com/microsoft/sbom-tool/issues/615 + [TestMethod] + public void Sbom_Fails_To_Generate_Due_To_File_In_Use() + { + var manifestDirPath = Path.Combine(TemporaryDirectory, "sub-directory"); + this.ManifestPath = Path.Combine(manifestDirPath, "_manifest", this.SbomSpecificationDirectoryName, "manifest.spdx.json"); + Directory.CreateDirectory(manifestDirPath); + // Arrange + var task = new GenerateSbom + { + BuildDropPath = CurrentDirectory, + ManifestDirPath = manifestDirPath, + PackageSupplier = PackageSupplier, + PackageName = PackageName, + PackageVersion = PackageVersion, + NamespaceBaseUri = NamespaceBaseUri, + BuildEngine = this.BuildEngine.Object, + ManifestInfo = this.SbomSpecification, +#if NET472 + SbomToolPath = SbomToolPath, +#endif + }; + + // Write JSON content to the manifest file, and create the directory if it doesn't exist + var jsonContent = "{}"; + Directory.CreateDirectory(Path.GetDirectoryName(ManifestPath)); + File.WriteAllText(ManifestPath, jsonContent); + // Open a handle to the manifest file to simulate it being in use + using (var fileStream = File.Open(this.ManifestPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) + { + // Act + var result = task.Execute(); + + // Assert + Assert.IsFalse(result); + } + } } From 770707deabb8f34a99e00cdfc2fff87e696ea25a Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Tue, 16 Jul 2024 20:38:39 -0700 Subject: [PATCH 07/19] Test the output of the ToolTask. --- .../AbstractGenerateSBomTaskInputTests.cs | 73 ++++++++++++++----- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs index fe562576..6aa2e3eb 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using Microsoft.Build.Framework; @@ -29,6 +30,7 @@ public abstract class AbstractGenerateSBomTaskInputTests internal const string NamespaceBaseUri = "https://base0.uri"; private Mock buildEngine; private List errors; + private List messages; [TestInitialize] public void Startup() @@ -36,7 +38,9 @@ public void Startup() // Setup the build engine this.buildEngine = new Mock(); this.errors = new List(); + this.messages = new List(); this.buildEngine.Setup(x => x.LogErrorEvent(It.IsAny())).Callback(e => errors.Add(e)); + this.buildEngine.Setup(x => x.LogMessageEvent(It.IsAny())).Callback(msg => messages.Add(msg)); } [TestCleanup] @@ -254,9 +258,7 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() // Arrange // If an invalid Verbosity is specified, the default value should be Verbose. It is also printed in the // tool's standard output for the MSBuild Core task. -#if !NET472 var pattern = new Regex("Verbosity=.*Value=Verbose"); -#endif var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var task = new GenerateSbom @@ -280,28 +282,68 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() // Assert Assert.IsTrue(result); -#if !NET472 +#if NET472 + Assert.IsTrue(this.messages.Any(msg => pattern.IsMatch(msg.Message))); +#else Assert.IsTrue(pattern.IsMatch(output)); #endif } +#if !NET472 /// /// Test to ensure GenerateSbom correctly parses and provides each EventLevel verbosity /// values to the SBOM API. /// + // Cases where the input Verbosity is more restrictive than `Information` are failing due to this issue: https://github.com/microsoft/sbom-tool/issues/616 [TestMethod] - [DataRow("FATAL", "Fatal")] - [DataRow("information", "Information")] - [DataRow("vErBose", "Verbose")] - [DataRow("Warning", "Warning")] - [DataRow("eRRor", "Error")] - [DataRow("Debug", "Verbose")] - public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVerbosity, string mappedVerbosity) + [DataRow("FATAL", "Fatal", false)] + [DataRow("information", "Information", true)] + [DataRow("vErBose", "Verbose", true)] + [DataRow("Warning", "Warning", false)] + [DataRow("eRRor", "Error", false)] + [DataRow("DeBug", "Verbose", true)] + public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVerbosity, string mappedVerbosity, bool messageShouldBeLogged) + { + // Arrange + var pattern = new Regex($"Verbosity=.*Value={mappedVerbosity}"); + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + var task = new GenerateSbom + { + BuildDropPath = CurrentDirectory, + PackageSupplier = PackageSupplier, + PackageName = PackageName, + PackageVersion = PackageVersion, + NamespaceBaseUri = NamespaceBaseUri, + Verbosity = inputVerbosity, + ManifestInfo = this.SbomSpecification, + BuildEngine = this.buildEngine.Object, + }; + + // Act + var result = task.Execute(); + var output = stringWriter.ToString(); + + // Assert + Assert.IsTrue(result, $"result: {result} is not set to true"); + Assert.AreEqual(messageShouldBeLogged, pattern.IsMatch(output)); + } +#else + /// + /// Test to ensure GenerateSbom correctly parses and provides each EventLevel verbosity + /// values to the SBOM API. + /// + [TestMethod] + [DataRow("FATAL", "Fatal", false)] + [DataRow("information", "Information", true)] + [DataRow("vErBose", "Verbose", true)] + [DataRow("Warning", "Warning", false)] + [DataRow("eRRor", "Error", false)] + [DataRow("DeBug", "Debug", true)] + public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVerbosity, string mappedVerbosity, bool messageShouldBeLogged) { // Arrange -#if !NET472 var pattern = new Regex($"Verbosity=.*Value={mappedVerbosity}"); -#endif var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var task = new GenerateSbom @@ -314,9 +356,7 @@ public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVer Verbosity = inputVerbosity, ManifestInfo = this.SbomSpecification, BuildEngine = this.buildEngine.Object, -#if NET472 SbomToolPath = SbomToolPath, -#endif }; // Act @@ -325,8 +365,7 @@ public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVer // Assert Assert.IsTrue(result, $"result: {result} is not set to true"); -#if !NET472 - Assert.IsTrue(pattern.IsMatch(output), $"output: `{output}` doesnt contain {pattern}"); -#endif + Assert.AreEqual(messageShouldBeLogged, this.messages.Any(msg => pattern.IsMatch(msg.Message))); } +#endif } From 358d25e84d0980507b0165a0e318de7512c8b47d Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Tue, 16 Jul 2024 20:44:45 -0700 Subject: [PATCH 08/19] Change the name of AbstractGenerateSBomTaskInputTests to AbstractGenerateSbomTaskInputTests --- .../AbstractGenerateSBomTaskInputTests.cs | 2 +- .../GenerateSbomTaskSPDX_2_2InputTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs index 6aa2e3eb..b965394b 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs @@ -14,7 +14,7 @@ namespace Microsoft.Sbom.Targets.Tests; [TestClass] -public abstract class AbstractGenerateSBomTaskInputTests +public abstract class AbstractGenerateSbomTaskInputTests { internal abstract string SbomSpecification { get; } diff --git a/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2InputTests.cs b/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2InputTests.cs index b7d48a72..1efe7e8a 100644 --- a/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2InputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/GenerateSbomTaskSPDX_2_2InputTests.cs @@ -9,7 +9,7 @@ namespace Microsoft.Sbom.Targets.Tests; /// Class to test the generation of SBOM using SPDX 2.2 specification. /// [TestClass] -public class GenerateSbomTaskSPDX_2_2InputTests : AbstractGenerateSBomTaskInputTests +public class GenerateSbomTaskSPDX_2_2InputTests : AbstractGenerateSbomTaskInputTests { internal override string SbomSpecification => "SPDX:2.2"; } From 7a9ab73f3eea7c1001a5e29c2a5db54ecf47a96e Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Tue, 16 Jul 2024 21:15:00 -0700 Subject: [PATCH 09/19] Include .NET Framework output in Sbom_Generation_Succeeds_For_Null_Verbosity --- .../AbstractGenerateSBomTaskInputTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs index b965394b..592657a0 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs @@ -217,9 +217,7 @@ public void Sbom_Generation_Succeeds_For_Null_Verbosity() // Arrange // If Verbosity is null, the default value should be Verbose and is printed in the // tool's standard output. -#if !NET472 var pattern = new Regex("Verbosity=.*Value=Verbose"); -#endif var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var task = new GenerateSbom @@ -243,7 +241,9 @@ public void Sbom_Generation_Succeeds_For_Null_Verbosity() // Assert Assert.IsTrue(result); -#if !NET472 +#if NET472 + Assert.IsTrue(this.messages.Any(msg => pattern.IsMatch(msg.Message))); +#else Assert.IsTrue(pattern.IsMatch(output)); #endif } @@ -294,7 +294,7 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() /// Test to ensure GenerateSbom correctly parses and provides each EventLevel verbosity /// values to the SBOM API. /// - // Cases where the input Verbosity is more restrictive than `Information` are failing due to this issue: https://github.com/microsoft/sbom-tool/issues/616 + // Cases where the input Verbosity is more restrictive than `Information` are failing due to this issue: https://github.com/microsoft/sbom-tool/issues/616 [TestMethod] [DataRow("FATAL", "Fatal", false)] [DataRow("information", "Information", true)] From af1e9d63998cd1a4420244ee4aeabdc5194f6010 Mon Sep 17 00:00:00 2001 From: Gustavo Castellanos Alfonzo Date: Fri, 19 Jul 2024 20:11:21 -0700 Subject: [PATCH 10/19] Update src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs Co-authored-by: Dave Tryon <45672944+DaveTryon@users.noreply.github.com> --- src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs b/src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs index 3a6aa065..99f3692e 100644 --- a/src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs +++ b/src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs @@ -3,7 +3,6 @@ namespace Microsoft.Sbom.Targets; -using System; using System.Diagnostics.Tracing; using System.IO; using Microsoft.Build.Utilities; From 47f4d78ab6bceea2e08aad6fa421e36937ae76a2 Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Fri, 19 Jul 2024 20:35:02 -0700 Subject: [PATCH 11/19] Skip tests that are failing due to known issues --- .../AbstractGenerateSBomTaskInputTests.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs index 592657a0..511db948 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs @@ -294,7 +294,6 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() /// Test to ensure GenerateSbom correctly parses and provides each EventLevel verbosity /// values to the SBOM API. /// - // Cases where the input Verbosity is more restrictive than `Information` are failing due to this issue: https://github.com/microsoft/sbom-tool/issues/616 [TestMethod] [DataRow("FATAL", "Fatal", false)] [DataRow("information", "Information", true)] @@ -304,6 +303,11 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() [DataRow("DeBug", "Verbose", true)] public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVerbosity, string mappedVerbosity, bool messageShouldBeLogged) { + if (!messageShouldBeLogged) + { + Assert.Inconclusive("Cases where the input Verbosity is more restrictive than `Information` are failing due to this issue: https://github.com/microsoft/sbom-tool/issues/616"); + } + // Arrange var pattern = new Regex($"Verbosity=.*Value={mappedVerbosity}"); var stringWriter = new StringWriter(); From c21fcb3069e314a0343a88c351f38eee2bbf493c Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Fri, 19 Jul 2024 20:52:44 -0700 Subject: [PATCH 12/19] Add debug messages for the test pipeline --- .../AbstractGenerateSbomTaskTests.cs | 1 + .../Microsoft.Sbom.Targets.Tests.csproj | 1 + 2 files changed, 2 insertions(+) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs index 5a9c0236..fe4995cd 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs @@ -68,6 +68,7 @@ public void Startup() this.ManifestPath = Path.Combine(DefaultManifestDirectory, this.SbomSpecificationDirectoryName, "manifest.spdx.json"); this.GeneratedSbomValidator = new(this.SbomSpecification); + Assert.IsTrue(Directory.Exists(SbomToolPath)); } [TestCleanup] diff --git a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj index 1c2f8025..8a5ece48 100644 --- a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj +++ b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj @@ -21,6 +21,7 @@ + <_SbomToolFiles Include="$(SBOMCLIToolProjectDir)bin\$(Configuration)\$(SbomCLIToolTargetFramework)\publish\**\*.*"> From 7a3f4f06d29abc0e85b616f7266f458dd5bae969 Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Fri, 19 Jul 2024 21:02:44 -0700 Subject: [PATCH 13/19] Fix .net core tests --- .../AbstractGenerateSbomTaskTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs index fe4995cd..454d153c 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs @@ -68,7 +68,9 @@ public void Startup() this.ManifestPath = Path.Combine(DefaultManifestDirectory, this.SbomSpecificationDirectoryName, "manifest.spdx.json"); this.GeneratedSbomValidator = new(this.SbomSpecification); +#if NET472 Assert.IsTrue(Directory.Exists(SbomToolPath)); +#endif } [TestCleanup] From 8b43205780abbc145580a80ab2dec0f32db9d92c Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Fri, 19 Jul 2024 21:23:42 -0700 Subject: [PATCH 14/19] Target .NET Framework only on Windows --- .../Microsoft.Sbom.Targets.Tests.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj index 8a5ece48..73da9053 100644 --- a/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj +++ b/test/Microsoft.Sbom.Targets.Tests/Microsoft.Sbom.Targets.Tests.csproj @@ -1,7 +1,8 @@ - net8.0;net472 + net8.0;net472 + net8.0 false True Microsoft.Sbom.Targets.Tests From 2fee783392f12b912ee54076235b5a115496ee02 Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Tue, 23 Jul 2024 11:12:56 -0700 Subject: [PATCH 15/19] Remove unnecessary comment. --- .../AbstractGenerateSbomTaskTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs index 454d153c..3008bd84 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskTests.cs @@ -389,7 +389,6 @@ public void Sbom_Is_Successfully_Generated_With_Unique_Namespace_Part_Defined(st this.GeneratedSbomValidator.AssertSbomIsValid(this.ManifestPath, CurrentDirectory, PackageName, PackageVersion, PackageSupplier, NamespaceBaseUri, expectedNamespaceUriUniquePart: uniqueNamespacePart); } - // TODO: Add test for SBOM Tool not found #if NET472 [TestMethod] public void Sbom_Generation_Fails_With_Tool_Path_Not_Found() From 1e50b1a3bb7c3df73bb2d192f3bdb7ad9ce7e40e Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Tue, 23 Jul 2024 17:34:00 -0700 Subject: [PATCH 16/19] Update default Verbosity. --- src/Microsoft.Sbom.Targets/SbomInputValidator.cs | 11 +++++++---- .../AbstractGenerateSBomTaskInputTests.cs | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.Sbom.Targets/SbomInputValidator.cs b/src/Microsoft.Sbom.Targets/SbomInputValidator.cs index 6076c34c..853d1c1d 100644 --- a/src/Microsoft.Sbom.Targets/SbomInputValidator.cs +++ b/src/Microsoft.Sbom.Targets/SbomInputValidator.cs @@ -13,6 +13,9 @@ namespace Microsoft.Sbom.Targets; /// public partial class GenerateSbom { + private const string DefaultVerbosity = "Information"; + private const EventLevel DefaultEventLevel = EventLevel.Informational; + /// /// Ensure all required arguments are non-null/empty, /// and do not contain whitespaces, tabs, or newline characters. @@ -75,8 +78,8 @@ public EventLevel ValidateAndAssignVerbosity() if (string.IsNullOrWhiteSpace(this.Verbosity)) { Log.LogWarning($"No verbosity level specified. Setting verbosity level at Verbose"); - this.Verbosity = "Verbose"; - return EventLevel.Verbose; + this.Verbosity = DefaultVerbosity; + return DefaultEventLevel; } switch (this.Verbosity.ToLower().Trim()) @@ -95,8 +98,8 @@ public EventLevel ValidateAndAssignVerbosity() return EventLevel.Critical; default: Log.LogWarning($"Unrecognized verbosity level specified. Setting verbosity level at Verbose"); - this.Verbosity = "Verbose"; - return EventLevel.Verbose; + this.Verbosity = DefaultVerbosity; + return DefaultEventLevel; } } diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs index 511db948..ad96fb28 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs @@ -217,7 +217,7 @@ public void Sbom_Generation_Succeeds_For_Null_Verbosity() // Arrange // If Verbosity is null, the default value should be Verbose and is printed in the // tool's standard output. - var pattern = new Regex("Verbosity=.*Value=Verbose"); + var pattern = new Regex("Verbosity=.*Value=Information"); var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var task = new GenerateSbom @@ -258,7 +258,7 @@ public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() // Arrange // If an invalid Verbosity is specified, the default value should be Verbose. It is also printed in the // tool's standard output for the MSBuild Core task. - var pattern = new Regex("Verbosity=.*Value=Verbose"); + var pattern = new Regex("Verbosity=.*Value=Information"); var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var task = new GenerateSbom From 03aef5ecad1f8de466765467a44c6ef9d5086c9f Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Tue, 23 Jul 2024 17:36:47 -0700 Subject: [PATCH 17/19] Address comments. --- .../AbstractGenerateSBomTaskInputTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs index ad96fb28..9618605f 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs @@ -334,8 +334,8 @@ public void Sbom_Generation_Assigns_Correct_Verbosity_IgnoreCase(string inputVer } #else /// - /// Test to ensure GenerateSbom correctly parses and provides each EventLevel verbosity - /// values to the SBOM API. + /// Test to ensure GenerateSbom correctly parses and provides each verbosity option + /// to the SBOM CLI. /// [TestMethod] [DataRow("FATAL", "Fatal", false)] From 0104e7344a90d6ae96366c702ed704da56f246ec Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Tue, 23 Jul 2024 17:48:49 -0700 Subject: [PATCH 18/19] Change name of AbstractGenerateSbomTaskInputTests --- ...BomTaskInputTests.cs => AbstractGenerateSbomTaskInputTests.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/Microsoft.Sbom.Targets.Tests/{AbstractGenerateSBomTaskInputTests.cs => AbstractGenerateSbomTaskInputTests.cs} (100%) diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskInputTests.cs similarity index 100% rename from test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSBomTaskInputTests.cs rename to test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskInputTests.cs From e968302eefdfd075248b6a9aa6c4eb0e7694b4b3 Mon Sep 17 00:00:00 2001 From: gustavoaca1997 Date: Wed, 24 Jul 2024 11:01:34 -0700 Subject: [PATCH 19/19] Address PR Comments --- src/Microsoft.Sbom.Targets/SbomInputValidator.cs | 4 ++-- .../AbstractGenerateSbomTaskInputTests.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.Sbom.Targets/SbomInputValidator.cs b/src/Microsoft.Sbom.Targets/SbomInputValidator.cs index 853d1c1d..747595ee 100644 --- a/src/Microsoft.Sbom.Targets/SbomInputValidator.cs +++ b/src/Microsoft.Sbom.Targets/SbomInputValidator.cs @@ -77,7 +77,7 @@ public EventLevel ValidateAndAssignVerbosity() // EventLevel value for the API. if (string.IsNullOrWhiteSpace(this.Verbosity)) { - Log.LogWarning($"No verbosity level specified. Setting verbosity level at Verbose"); + Log.LogWarning($"No verbosity level specified. Setting verbosity level at {DefaultVerbosity}."); this.Verbosity = DefaultVerbosity; return DefaultEventLevel; } @@ -97,7 +97,7 @@ public EventLevel ValidateAndAssignVerbosity() case "fatal": return EventLevel.Critical; default: - Log.LogWarning($"Unrecognized verbosity level specified. Setting verbosity level at Verbose"); + Log.LogWarning($"Unrecognized verbosity level specified. Setting verbosity level at {DefaultVerbosity}."); this.Verbosity = DefaultVerbosity; return DefaultEventLevel; } diff --git a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskInputTests.cs b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskInputTests.cs index 9618605f..5274dbf5 100644 --- a/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskInputTests.cs +++ b/test/Microsoft.Sbom.Targets.Tests/AbstractGenerateSbomTaskInputTests.cs @@ -215,7 +215,7 @@ public void Sbom_Generation_Fails_For_Invalid_NamespaceUriUniquePart(string name public void Sbom_Generation_Succeeds_For_Null_Verbosity() { // Arrange - // If Verbosity is null, the default value should be Verbose and is printed in the + // If Verbosity is null, the default value should be Information and is printed in the // tool's standard output. var pattern = new Regex("Verbosity=.*Value=Information"); var stringWriter = new StringWriter(); @@ -256,7 +256,7 @@ public void Sbom_Generation_Succeeds_For_Null_Verbosity() public void Sbom_Generation_Succeeds_For_Invalid_Verbosity() { // Arrange - // If an invalid Verbosity is specified, the default value should be Verbose. It is also printed in the + // If an invalid Verbosity is specified, the default value should be Information. It is also printed in the // tool's standard output for the MSBuild Core task. var pattern = new Regex("Verbosity=.*Value=Information"); var stringWriter = new StringWriter();