diff --git a/src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs b/src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs index d049e268..338cdc73 100644 --- a/src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs @@ -12,6 +12,7 @@ using LCT.Common.Constants; using Moq; using System.Collections.Generic; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -41,13 +42,19 @@ public void ParsePackageConfig_GivenAMultipleInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); - string[] Includes = { "*_Alpine.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + string[] Includes = { "*_Alpine.cdx.json" }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { ProjectType = "ALPINE", - RemoveDevDependency = true, Alpine = new Config() { Include = Includes }, - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -67,13 +74,18 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Alpine.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations=new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "ALPINE", - RemoveDevDependency = true, - Alpine = new Config() { Include = Includes } - }; + Alpine = new Config() { Include = Includes }, + SW360=new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } + }; //Act Bom listofcomponents = _alpineProcessor.ParsePackageFile(appSettings); @@ -90,17 +102,22 @@ public void ParsePackageConfig_GivenMultipleInputFiles_ReturnsCountOfDuplicates( int duplicateComponents = 2; string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); - - string[] Includes = { "*_Alpine.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + string[] Includes = { "*_Alpine.cdx.json" }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "ALPINE", - RemoveDevDependency = true, - Alpine = new Config() { Include = Includes } + Alpine = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; + //Act _alpineProcessor.ParsePackageFile(appSettings); @@ -118,14 +135,19 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSourceDetails() string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "AlpineSourceDetails_Cyclonedx.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "ALPINE", - RemoveDevDependency = true, - Alpine = new Config() { Include = Includes } + Alpine = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; - + //Act Bom listofcomponents = _alpineProcessor.ParsePackageFile(appSettings); @@ -144,14 +166,19 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo string[] Includes = { "CycloneDX_Alpine.cdx.json", "SBOMTemplate_Alpine.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, ProjectType = "ALPINE", - RemoveDevDependency = true, Alpine = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_AlpineCATemplate.cdx.json" - }; + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles", + CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_AlpineCATemplate.cdx.json" + } + }; //Act Bom listofcomponents = _alpineProcessor.ParsePackageFile(appSettings); @@ -170,15 +197,20 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp string[] Includes = { "CycloneDX_Alpine.cdx.json", "SBOMTemplate_Alpine.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, ProjectType = "ALPINE", - RemoveDevDependency = true, Alpine = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Alpine.cdx.json", + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Alpine.cdx.json" + } }; - + //Act Bom listofcomponents = _alpineProcessor.ParsePackageFile(appSettings); bool isUpdated = listofcomponents.Components.Exists(x => x.Properties != null diff --git a/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs b/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs index 3a0b8f4a..7c64dde1 100644 --- a/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs +++ b/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs @@ -17,6 +17,7 @@ using LCT.Common.Model; using LCT.Services.Interface; using LCT.APICommunications.Model.AQL; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -176,16 +177,25 @@ public async Task GetRepoDetails_GivenProjectTypeAsDebian_ReturnsListOFComponent Version="1", } }; + - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", ProjectType = "DEBIAN", - Debian = new Config() + Debian = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; List aqlResultList = new() { @@ -227,15 +237,24 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents() } }; - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", ProjectType = "NPM", - Debian = new Config() + Npm = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; List aqlResultList = new() { @@ -252,7 +271,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents() mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new NpmProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); @@ -277,16 +296,25 @@ public async Task GetRepoDetails_GivenProjectTypeAsNuget_ReturnsListOFComponents } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", - ProjectType = "NUGET", - Debian = new Config() + ProjectType = "Nuget", + Nuget = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; + List aqlResultList = new() { new() @@ -302,7 +330,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsNuget_ReturnsListOFComponents mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new NugetProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); @@ -327,15 +355,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsPython_ReturnsListOFComponent } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", - ProjectType = "PYTHON", - Debian = new Config() + ProjectType = "Python", + Poetry = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; List aqlResultList = new() { @@ -352,7 +388,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsPython_ReturnsListOFComponent mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new PythonProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); @@ -377,15 +413,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsConan_ReturnsListOFComponents } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", ProjectType = "Conan", - Debian = new Config() + Conan = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; List aqlResultList = new() { @@ -402,7 +446,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsConan_ReturnsListOFComponents mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new ConanProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); @@ -427,15 +471,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsMaven_ReturnsListOFComponents } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", ProjectType = "MAVEN", - Debian = new Config() + Maven = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; List aqlResultList = new() { @@ -452,7 +504,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsMaven_ReturnsListOFComponents mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new MavenProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); diff --git a/src/LCT.PackageIdentifier.UTest/BomValidatorUnitTests.cs b/src/LCT.PackageIdentifier.UTest/BomValidatorUnitTests.cs index 21e5886e..1c8f0dff 100644 --- a/src/LCT.PackageIdentifier.UTest/BomValidatorUnitTests.cs +++ b/src/LCT.PackageIdentifier.UTest/BomValidatorUnitTests.cs @@ -30,10 +30,8 @@ public async Task ValidateAppSettings_ProvidedProjectID_ReturnsProjectName() //Arrange string projectName = "Test"; ProjectReleases projectReleases = new ProjectReleases(); - var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object) - { - SW360ProjectName = "Test" - }; + + mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(), projectReleases)) .ReturnsAsync(projectName); @@ -44,8 +42,17 @@ public async Task ValidateAppSettings_ProvidedProjectID_ReturnsProjectName() mockIFolderAction.Setup(x => x.ValidateFolderPath(It.IsAny())) .Callback((string message) => { }) .Verifiable(); - CommonAppSettings.PackageFilePath = ""; - + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object, mockIFileOperations.Object) + { + SW360 = new SW360() { ProjectName = "Test" }, + Directory = new LCT.Common.Directory(mockIFolderAction.Object, mockIFileOperations.Object) + { + InputFolder = "" + } + }; //Act await BomValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object, projectReleases); @@ -60,10 +67,7 @@ public Task ValidateAppSettings_ProvidedProjectID_ReturnsInvalidDataException() //Arrange string projectName = null; ProjectReleases projectReleases = new ProjectReleases(); - var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object) - { - SW360ProjectName = "Test" - }; + mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(),projectReleases)) .ReturnsAsync(projectName); @@ -74,7 +78,16 @@ public Task ValidateAppSettings_ProvidedProjectID_ReturnsInvalidDataException() mockIFolderAction.Setup(x => x.ValidateFolderPath(It.IsAny())) .Callback((string message) => { }) .Verifiable(); - + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object, mockIFileOperations.Object) + { + SW360 = new SW360() { ProjectName = "Test" }, + Directory = new LCT.Common.Directory(mockIFolderAction.Object, mockIFileOperations.Object) + { + InputFolder = "" + } + }; //Act && Assert Assert.ThrowsAsync(async () => await BomValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object, projectReleases)); return Task.CompletedTask; @@ -87,10 +100,8 @@ public async Task ValidateAppSettings_ProvidedProjectID_EndsTheApplicationOnClos string projectName = "Test"; ProjectReleases projectReleases = new ProjectReleases(); projectReleases.clearingState = "CLOSED"; - var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object) - { - SW360ProjectName = "Test" - }; + + mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(), projectReleases)) .ReturnsAsync(projectName); @@ -101,8 +112,17 @@ public async Task ValidateAppSettings_ProvidedProjectID_EndsTheApplicationOnClos mockIFolderAction.Setup(x => x.ValidateFolderPath(It.IsAny())) .Callback((string message) => { }) .Verifiable(); - CommonAppSettings.PackageFilePath = ""; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object, mockIFileOperations.Object) + { + SW360 = new SW360() { ProjectName = "Test" }, + Directory = new LCT.Common.Directory(mockIFolderAction.Object, mockIFileOperations.Object) + { + InputFolder = "" + } + }; //Act await BomValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object, projectReleases); diff --git a/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs b/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs index 5f747fcb..231c5036 100644 --- a/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs @@ -7,6 +7,7 @@ using CycloneDX.Models; using LCT.APICommunications.Model.AQL; using LCT.Common; +using LCT.Common.Interface; using LCT.Common.Model; using LCT.PackageIdentifier; using LCT.PackageIdentifier.Interface; @@ -33,16 +34,21 @@ public void ParseLockFile_GivenAInputFilePath_ReturnsSuccess() string outFolder = Path.GetDirectoryName(exePath); string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; - string[] Includes = { "conan.lock" }; - Config config = new Config() - { - Include = Includes - }; + string[] Includes = { "conan.lock" }; + - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - Conan = config + + Conan = new Config() { Include = Includes }, + SW360=new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } + }; Mock cycloneDXBomParser = new Mock(); @@ -63,16 +69,20 @@ public void ParseLockFile_GivenAInputFilePath_ReturnDevDependentComp() string outFolder = Path.GetDirectoryName(exePath); string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; - string[] Includes = { "conan.lock" }; - Config config = new Config() + string[] Includes = { "conan.lock" }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - Include = Includes - }; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = packagefilepath, - Conan = config + Conan = new Config() { Include = Includes }, + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } + }; Mock cycloneDXBomParser = new Mock(); @@ -95,18 +105,23 @@ public void ParseLockFile_GivenAInputFilePathExcludeComponent_ReturnComponentCou string outFolder = Path.GetDirectoryName(exePath); string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; - string[] Includes = { "conan.lock" }; - Config config = new Config() - { - Include = Includes, - ExcludedComponents = new List { "openldap:2.6.4-shared-ossl3.1", "libcurl:7.87.0-shared-ossl3.1" } - }; + string[] Includes = { "conan.lock" }; + - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - Conan = config + + Conan = new Config() { Include = Includes }, + SW360 = new SW360() { ExcludeComponents= ["openldap:2.6.4-shared-ossl3.1", "libcurl:7.87.0-shared-ossl3.1"] }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } + }; + Mock cycloneDXBomParser = new Mock(); //Act @@ -145,7 +160,20 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes var components = new List() { component }; ComponentIdentification componentIdentification = new() { comparisonBOMData = components }; string[] repoList = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = repoList }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360=new SW360(), + Conan = new Config + { + Artifactory = new Artifactory + { + InternalRepos = repoList + } + } + }; AqlResult aqlResult = new() { @@ -182,8 +210,20 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() }; var components = new List() { component }; string[] repoList = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Conan = new LCT.Common.Model.Config() { JfrogConanRepoList = repoList }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Conan = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = repoList + } + } + }; AqlResult aqlResult = new() { Name = "index.json", @@ -222,9 +262,21 @@ public async Task GetArtifactoryRepoName_Conan_ReturnsNotFound_ReturnsFailure() Purl = "pkg:conan/securitycommunicationmanager@2.6.5" }; var components = new List() { component }; - string[] repoList = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Conan = new LCT.Common.Model.Config() { JfrogConanRepoList = repoList }; + string[] repoList = { "internalrepo1", "internalrepo2" }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Conan = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = repoList + } + } + }; AqlResult aqlResult = new() { Name = "index.json", @@ -261,17 +313,20 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo ConanProcessor conanProcessor = new ConanProcessor(cycloneDXBomParser.Object); string[] Includes = { "SBOM_ConanCATemplate.cdx.json" }; - string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - - CommonAppSettings appSettings = new CommonAppSettings() + string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, ProjectType = "CONAN", - RemoveDevDependency = true, Conan = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_ConanCATemplate.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; - //Act Bom listofcomponents = conanProcessor.ParsePackageFile(appSettings); diff --git a/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs b/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs index f65bb176..2cc24d09 100644 --- a/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs +++ b/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs @@ -36,8 +36,10 @@ public void SetMetadataInComparisonBOM_GivenBOMWithEmptyMetadata_FillsInMetadata }; CommonAppSettings appSettings = new CommonAppSettings() { - CaVersion = "1.2.3" - }; + SW360=new() + + }; + projectReleases.Version = "1.2.3"; CatoolInfo caToolInformation = new CatoolInfo() { CatoolVersion = "6.0.0", CatoolRunningLocation="" }; //Act Bom files = CycloneBomProcessor.SetMetadataInComparisonBOM(bom, appSettings, projectReleases, caToolInformation); @@ -52,7 +54,7 @@ public void SetMetadataInComparisonBOM_GivenBOMWithMetadata_AddsNewMetadataInfoI //Arrange ProjectReleases projectReleases = new ProjectReleases(); projectReleases.Version= "1.0"; - + Bom bom = new Bom() { Metadata = new Metadata() @@ -70,9 +72,9 @@ public void SetMetadataInComparisonBOM_GivenBOMWithMetadata_AddsNewMetadataInfoI }; CommonAppSettings appSettings = new CommonAppSettings() { - CaVersion = "1.2.3", - SW360ProjectName = "Test", - }; + SW360 = new() { ProjectName= "Test" } + }; + projectReleases.Version = "1.2.3"; Tool tools = new Tool() { @@ -88,7 +90,7 @@ public void SetMetadataInComparisonBOM_GivenBOMWithMetadata_AddsNewMetadataInfoI }; Component component = new Component { - Name = appSettings.SW360ProjectName, + Name = appSettings.SW360.ProjectName, Version = projectReleases.Version, Type = Component.Classification.Application }; diff --git a/src/LCT.PackageIdentifier.UTest/DebianParserTests.cs b/src/LCT.PackageIdentifier.UTest/DebianParserTests.cs index e9511f29..77ba5dd1 100644 --- a/src/LCT.PackageIdentifier.UTest/DebianParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/DebianParserTests.cs @@ -16,6 +16,7 @@ using LCT.PackageIdentifier.Interface; using LCT.Services.Interface; using LCT.APICommunications.Model.AQL; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -127,12 +128,18 @@ public void ParsePackageConfig_GivenAMultipleInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "*_Debian.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { ProjectType = "DEBIAN", - RemoveDevDependency = true, Debian = new Config() { Include = Includes }, - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -152,15 +159,20 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); - string[] Includes = { "CycloneDX_Debian.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + string[] Includes = { "CycloneDX_Debian.cdx.json" }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "DEBIAN", - RemoveDevDependency = true, - Debian = new Config() { Include = Includes } + Debian = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; - //Act Bom listofcomponents = _debianProcessor.ParsePackageFile(appSettings); @@ -175,16 +187,21 @@ public void ParsePackageConfig_GivenMultipleInputFiles_ReturnsCountOfDuplicates( int duplicateComponents = 2; string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); - string[] Includes = { "*_Debian.cdx.json" }; + string[] Includes = { "*_Debian.cdx.json" }; + - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "DEBIAN", - RemoveDevDependency = true, - Debian = new Config() { Include = Includes } + Debian = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; - //Act _debianProcessor.ParsePackageFile(appSettings); @@ -201,12 +218,17 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSourceDetails() string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "SourceDetails_Cyclonedx.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "DEBIAN", - RemoveDevDependency = true, - Debian = new Config() { Include = Includes } + Debian = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -225,14 +247,20 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Debian.cdx.json", "SBOMTemplate_Debian.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; + - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, ProjectType = "DEBIAN", - RemoveDevDependency = true, Debian = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_DebianCATemplate.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + CycloneDxSBomTemplatePath= packagefilepath + "\\SBOMTemplates\\SBOM_DebianCATemplate.cdx.json" + } }; //Act @@ -249,15 +277,21 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Debian.cdx.json", "SBOMTemplate_Debian.cdx.json" }; - string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; + string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; + - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, ProjectType = "DEBIAN", - RemoveDevDependency = true, Debian = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Debian.cdx.json", + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Debian.cdx.json" + } }; //Act diff --git a/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs b/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs index c9c7ebc2..074218e1 100644 --- a/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs @@ -17,6 +17,7 @@ using Moq; using System.Threading.Tasks; using LCT.Common.Constants; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -121,13 +122,19 @@ public void ParsePackageFile_PackageLockWithDuplicateComponents_ReturnsCountOfDu string[] Includes = { "*_Maven.cdx.json" }; string[] Excludes = { "lol" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = filepath, ProjectType = "MAVEN", - RemoveDevDependency = true, - Maven = new Config() { Include = Includes, Exclude = Excludes } + Maven = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath + } }; + Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); @@ -152,8 +159,20 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; - + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-1.0.0.tgz", @@ -188,9 +207,21 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData2_Succe component1.Version = "1.0.0"; var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; - string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + string[] reooListArr = { "internalrepo1", "internalrepo2" }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common_license-1.0.0.tgz", @@ -227,9 +258,21 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe }; var components = new List() { component1 }; ComponentIdentification componentIdentification = new() { comparisonBOMData = components }; - string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + string[] reooListArr = { "internalrepo1", "internalrepo2" }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.tgz", @@ -267,8 +310,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Maven = new Config() { JfrogMavenRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.tgz", @@ -307,8 +361,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully( }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Maven = new Config() { JfrogMavenRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.tgz", @@ -343,13 +408,19 @@ public void DevDependencyIdentificationLogic_ReturnsCountOfDevDependentcomponent string filepath = outFolder + @"\PackageIdentifierUTTestFiles\MavenDevDependency\WithDev"; string[] Includes = { "*.cdx.json" }; string[] Excludes = { "lol" }; + - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = filepath, ProjectType = "MAVEN", - RemoveDevDependency = true, - Maven = new Config() { Include = Includes, Exclude = Excludes } + Maven = new Config() { Include = Includes,Exclude= Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath + } }; Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); @@ -369,15 +440,21 @@ public void DevDependencyIdentificationLogic_ReturnsCountOfComponents_WithoutDev string outFolder = Path.GetDirectoryName(exePath); string filepath = outFolder + @"\PackageIdentifierUTTestFiles\MavenDevDependency\WithOneInputFile"; string[] Includes = { "*.cdx.json" }; - string[] Excludes = { "lol" }; + string[] Excludes = { "lol" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = filepath, ProjectType = "MAVEN", - RemoveDevDependency = true, - Maven = new Config() { Include = Includes, Exclude = Excludes } + Maven = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath + } }; + Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); @@ -399,15 +476,22 @@ public void ParsePackageFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTota string filepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Includes = { "CycloneDX_Maven.cdx.json", "SBOMTemplate_Maven.cdx.json" }; string[] Excludes = { "lol" }; + - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = filepath, ProjectType = "MAVEN", - RemoveDevDependency = true, Maven = new Config() { Include = Includes, Exclude = Excludes }, - CycloneDxSBomTemplatePath = filepath + "\\SBOMTemplates\\SBOM_MavenCATemplate.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + CycloneDxSBomTemplatePath= filepath + "\\SBOMTemplates\\SBOM_MavenCATemplate.cdx.json" + } }; + Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); @@ -427,16 +511,22 @@ public void ParsePackageFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUpda string outFolder = Path.GetDirectoryName(exePath); string filepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Includes = { "CycloneDX_Maven.cdx.json" }; - string[] Excludes = { "lol" }; - - CommonAppSettings appSettings = new CommonAppSettings() + string[] Excludes = { "lol" }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = filepath, ProjectType = "MAVEN", - RemoveDevDependency = true, Maven = new Config() { Include = Includes, Exclude = Excludes }, - CycloneDxSBomTemplatePath = filepath + "\\SBOMTemplates\\SBOMTemplate_Maven.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + CycloneDxSBomTemplatePath = filepath + "\\SBOMTemplates\\SBOMTemplate_Maven.cdx.json" + } }; + Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); diff --git a/src/LCT.PackageIdentifier.UTest/NPMParserTests.cs b/src/LCT.PackageIdentifier.UTest/NPMParserTests.cs index 4d63d7c3..7e5b1009 100644 --- a/src/LCT.PackageIdentifier.UTest/NPMParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/NPMParserTests.cs @@ -13,6 +13,7 @@ using CycloneDX.Models; using LCT.Common.Constants; using Moq; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -28,15 +29,20 @@ public void ParsePackageFile_PackageLockWithDuplicateComponents_ReturnsCountOfDu string outFolder = Path.GetDirectoryName(exePath); string filepath = outFolder + @"\PackageIdentifierUTTestFiles\TestDir"; string[] Includes = { "p*-lock.json" }; - string[] Excludes = { "node_modules" }; + string[] Excludes = { "node_modules" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - BomFolderPath = outFolder, - PackageFilePath = filepath, ProjectType = "NPM", - RemoveDevDependency = true, - Npm = new Config() { Include = Includes, Exclude = Excludes } + Npm = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + OutputFolder=outFolder + } }; Mock cycloneDXBomParser = new Mock(); @@ -58,15 +64,21 @@ public void ParsePackageFile_PackageLockWithangular16_ReturnsCountOfComponents() string filepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Includes = { "p*-lock16.json" }; string[] Excludes = { "node_modules" }; - - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - BomFolderPath = outFolder, - PackageFilePath = filepath, ProjectType = "NPM", - RemoveDevDependency = true, - Npm = new Config() { Include = Includes, Exclude = Excludes } + Npm = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + OutputFolder = outFolder + } }; + Mock cycloneDXBomParser = new Mock(); NpmProcessor NpmProcessor = new NpmProcessor(cycloneDXBomParser.Object); @@ -89,15 +101,19 @@ public void ParsePackageFile_PackageLockWithoutDuplicateComponents_ReturnsCountZ string[] Includes = { "p*-lock.json" }; string[] Excludes = { "node_modules" }; BomKpiData bomKpiData = new BomKpiData(); - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - BomFolderPath= outFolder, - PackageFilePath = filepath, ProjectType = "NPM", - RemoveDevDependency = true, - Npm = new Config() { Include = Includes, Exclude = Excludes } - - + Npm = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + OutputFolder = outFolder + } }; Mock cycloneDXBomParser = new Mock(); @@ -120,13 +136,19 @@ public void ParseCycloneDXFile_GivenMultipleInputFiles_ReturnsCounts() Mock cycloneDXBomParser = new Mock(); NpmProcessor npmProcessor = new NpmProcessor(cycloneDXBomParser.Object); string[] Includes = { "*_NPM.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - BomFolderPath = outFolder, - PackageFilePath = outFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "NPM", - RemoveDevDependency = true, - Npm = new Config() { Include = Includes } + Npm = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = outFolder + @"\PackageIdentifierUTTestFiles", + OutputFolder = outFolder + } }; //Act @@ -146,16 +168,21 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo Mock cycloneDXBomParser = new Mock(); NpmProcessor npmProcessor = new NpmProcessor(cycloneDXBomParser.Object); string[] Includes = { "CycloneDX2_NPM.cdx.json", "SBOMTemplate_Npm.cdx.json" }; - string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; + string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - BomFolderPath = outFolder, - PackageFilePath = packagefilepath, ProjectType = "NPM", - RemoveDevDependency = true, Npm = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_NpmCATemplate.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + OutputFolder = outFolder, + CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_NpmCATemplate.cdx.json" + } }; //Act @@ -174,16 +201,21 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp Mock cycloneDXBomParser = new Mock(); NpmProcessor npmProcessor = new NpmProcessor(cycloneDXBomParser.Object); string[] Includes = { "CycloneDX2_NPM.cdx.json" }; - string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; + string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - BomFolderPath = outFolder, - PackageFilePath = packagefilepath, ProjectType = "NPM", - RemoveDevDependency = true, Npm = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Npm.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + OutputFolder = outFolder, + CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Npm.cdx.json" + } }; //Act diff --git a/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs b/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs index 536472b8..af33c611 100644 --- a/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs +++ b/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs @@ -8,6 +8,8 @@ using LCT.APICommunications.Model.AQL; using LCT.Common; using LCT.Common.Constants; +using LCT.Common.Interface; +using LCT.Common.Model; using LCT.PackageIdentifier.Interface; using LCT.PackageIdentifier.Model; using LCT.Services.Interface; @@ -83,7 +85,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -120,8 +134,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData2_Succe var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; - + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common_license-1.0.0.tgz", @@ -159,7 +184,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe var components = new List() { component1 }; ComponentIdentification componentIdentification = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo1" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -198,8 +235,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo1" }; - CommonAppSettings appSettings = new(); - appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.tgz", @@ -238,8 +286,20 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully( }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; + AqlResult aqlResult = new() { Name = "animations-common-1.0.0.tgz", diff --git a/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs b/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs index cb9488db..c2ac35ed 100644 --- a/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs @@ -20,6 +20,7 @@ using System.Threading.Tasks; using System.Linq; using LCT.Common.Constants; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -400,10 +401,17 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSuccess() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string outFolder = Path.GetDirectoryName(exePath); string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles\packages.config"; - - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = outFolder + @"\PackageIdentifierUTTestFiles" + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + Nuget = new Config(), + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = outFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -514,15 +522,22 @@ public void Parsecsproj_GivenXMLFile_ReturnsSuccess() string outFolder = Path.GetDirectoryName(exePath); string csprojfilepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Excludes = null; - CommonAppSettings CommonAppSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings commonAppSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = csprojfilepath, - Nuget = new Config() { Exclude = Excludes } + Nuget = new Config() { Exclude= Excludes }, + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = csprojfilepath + } }; int devDependent = 0; //Act - List referenceDetails = NugetProcessor.Parsecsproj(CommonAppSettings); + List referenceDetails = NugetProcessor.Parsecsproj(commonAppSettings); foreach (var item in referenceDetails) { if (item.Private) @@ -545,15 +560,22 @@ public void RemoveExcludedComponents_ReturnsUpdatedBom() string[] Excludes = null; Bom bom = new Bom(); - bom.Components = new List(); - CommonAppSettings CommonAppSettings = new CommonAppSettings() + bom.Components = new List(); + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings commonAppSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = csprojfilepath, - Nuget = new Config() { Exclude = Excludes, ExcludedComponents = new List() } + Nuget = new Config() { Exclude = Excludes }, + SW360 = new SW360() { ExcludeComponents= new List() }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = csprojfilepath + } }; //Act - Bom updatedBom = NugetProcessor.RemoveExcludedComponents(CommonAppSettings, bom); + Bom updatedBom = NugetProcessor.RemoveExcludedComponents(commonAppSettings, bom); //Assert Assert.AreEqual(0, updatedBom.Components.Count, "Zero component exculded"); @@ -572,8 +594,20 @@ public async Task IdentificationOfInternalComponents_Nuget_ReturnsComponentData_ var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo1" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; - + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-1.0.0.nupkg", @@ -610,7 +644,19 @@ public async Task IdentificationOfInternalComponents_Nuget_ReturnsComponentData2 var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -649,7 +695,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe var components = new List() { component1 }; ComponentIdentification componentIdentification = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -689,8 +747,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.nupkg", @@ -729,8 +798,20 @@ public async Task GetJfrogRepoDetailsOfAComponent_Nuget_ReturnsWithData2_Success }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; + AqlResult aqlResult = new() { Name = "animations-common-1.0.0.nupkg", @@ -769,8 +850,19 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_SuccessFully() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.nupkg", @@ -809,8 +901,19 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsFailure() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animation-test-1.0.0.nupkg", @@ -849,8 +952,19 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsSuccess() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common.1.0.0.nupkg", @@ -890,8 +1004,20 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsNotFound_ReturnsFailure() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; + AqlResult aqlResult = new() { Name = "animation-common.1.0.0.nupkg", @@ -928,16 +1054,19 @@ public void ParseProjectAssetFile_GivenAInputFilePath_ReturnsSuccess() string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Includes = { "project.assets.json" }; - Config config = new Config() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - Include = Includes + Nuget = new Config() { Include = Includes }, + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } }; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = packagefilepath, - Nuget = config - }; Mock cycloneDXBomParser = new Mock(); //Act @@ -957,17 +1086,20 @@ public void ParseProjectAssetFile_GivenAInputFilePath_ReturnDevDependentComp() string outFolder = Path.GetDirectoryName(exePath); string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; - string[] Includes = { "project.assets.json" }; - Config config = new Config() + string[] Includes = { "project.assets.json" }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - Include = Includes + Nuget = new Config() { Include= Includes }, + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } }; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = packagefilepath, - Nuget = config - }; Mock cycloneDXBomParser = new Mock(); diff --git a/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs b/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs index b7f8e1fa..2113c22e 100644 --- a/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs @@ -18,6 +18,7 @@ using Moq; using System.Collections.Generic; using System.Threading.Tasks; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -45,13 +46,19 @@ public void ParseCycloneDXFile_GivenAMultipleInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "*_Python.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes }, - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles" + ProjectType="PYTHON", + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency=true}, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; + //Act Bom listofcomponents = pythonProcessor.ParsePackageFile(appSettings); @@ -69,14 +76,19 @@ public void ParseCycloneDXFile_GivenAInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Python.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes } + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; - //Act Bom listofcomponents = pythonProcessor.ParsePackageFile(appSettings); @@ -92,21 +104,20 @@ public void ParseCycloneDXFile_GivenAInputFilePathExcludeOneComponent_ReturnsCou string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Python.cdx.json" }; - Config config = new Config() + List excludeComponents = ["attrs:22.2.0"]; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - Include = Includes, - ExcludedComponents = new List() + ProjectType = "PYTHON", + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true,ExcludeComponents= excludeComponents }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) { - "attrs:22.2.0" + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" } }; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", - ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = config - }; //Act Bom listofcomponents = pythonProcessor.ParsePackageFile(appSettings); @@ -122,15 +133,20 @@ public void ParseCycloneDXFile_GivenMultipleInputFiles_ReturnsCountOfDuplicates( int duplicateComponents = 2; string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); - string[] Includes = { "*_Python.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + string[] Includes = { "*_Python.cdx.json" }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes } + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; - //Act pythonProcessor.ParsePackageFile(appSettings); @@ -147,14 +163,19 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Python.cdx.json", "SBOMTemplate_Python.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_PythonCATemplate.cdx.json" + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles", + CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_PythonCATemplate.cdx.json" + } }; //Act @@ -173,13 +194,18 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp string[] Includes = { "CycloneDX_Python.cdx.json", "SBOMTemplate_Python.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Python.cdx.json" + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Python.cdx.json" + } }; //Act @@ -203,7 +229,19 @@ public async Task IdentificationOfInternalComponents_Python_ReturnsComponentData var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Poetry = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -241,7 +279,19 @@ public async Task IdentificationOfInternalComponents_Python_ReturnsComponentData var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Poetry = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -279,8 +329,19 @@ public async Task GetJfrogRepoDetailsOfAComponentForPython_ReturnsWithData_Succe }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Python = new Config() { JfrogPythonRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Poetry = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "html5lib-1.1.tar.gz", @@ -318,8 +379,19 @@ public async Task GetJfrogRepoDetailsOfAComponentForPython_ReturnsWithData2_Succ }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Python = new Config() { JfrogPythonRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Poetry = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "html5lib-1.1-py2.py3-none-any.whl", @@ -367,15 +439,22 @@ public void ExtractDetailsForPoetryLockfile_GivenAInputFilePath_ReturnsCounts() //Arrange string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); - string[] Includes = { "poetry.lock" }; - CommonAppSettings appSettings = new CommonAppSettings() + string[] Includes = { "poetry.lock" }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles\PythonTestProject", ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes } + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles\PythonTestProject" + } }; + //Act Bom listofcomponents = pythonProcessor.ParsePackageFile(appSettings); diff --git a/src/LCT.PackageIdentifier/ConanProcessor.cs b/src/LCT.PackageIdentifier/ConanProcessor.cs index d0fffb7f..6b54ed2f 100644 --- a/src/LCT.PackageIdentifier/ConanProcessor.cs +++ b/src/LCT.PackageIdentifier/ConanProcessor.cs @@ -118,7 +118,10 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Conan?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Conan?.Artifactory.RemoteRepos ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); diff --git a/src/LCT.PackageIdentifier/DebianProcessor.cs b/src/LCT.PackageIdentifier/DebianProcessor.cs index d7a57f6e..079a7a80 100644 --- a/src/LCT.PackageIdentifier/DebianProcessor.cs +++ b/src/LCT.PackageIdentifier/DebianProcessor.cs @@ -128,7 +128,10 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Debian?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Debian?.Artifactory.RemoteRepos ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); @@ -149,7 +152,7 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Maven?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Maven?.Artifactory.RemoteRepos ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); diff --git a/src/LCT.PackageIdentifier/NpmProcessor.cs b/src/LCT.PackageIdentifier/NpmProcessor.cs index a1605519..f3f3e15d 100644 --- a/src/LCT.PackageIdentifier/NpmProcessor.cs +++ b/src/LCT.PackageIdentifier/NpmProcessor.cs @@ -395,7 +395,10 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Npm?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Npm?.Artifactory.RemoteRepos ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); diff --git a/src/LCT.PackageIdentifier/NugetProcessor.cs b/src/LCT.PackageIdentifier/NugetProcessor.cs index 9bad28db..51454a15 100644 --- a/src/LCT.PackageIdentifier/NugetProcessor.cs +++ b/src/LCT.PackageIdentifier/NugetProcessor.cs @@ -216,7 +216,10 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Nuget?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Nuget?.Artifactory.RemoteRepos ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); @@ -236,7 +239,7 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List> GetJfrogRepoDetailsOfAComponent(List componentsForBOM, CommonAppSettings appSettings, IJFrogService jFrogService, IBomHelper bomhelper) { // get the component list from Jfrog for given repo + internal repo - string[] repoList = appSettings.Poetry?.Artifactory.InternalRepos.Concat(appSettings.Poetry?.Artifactory.DevRepos).Concat(appSettings.Poetry?.Artifactory.RemoteRepos).ToArray(); + string[] repoList = (appSettings.Poetry?.Artifactory.InternalRepos ?? Array.Empty()) + .Concat(appSettings.Poetry?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Poetry?.Artifactory.RemoteRepos ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List();