-
Notifications
You must be signed in to change notification settings - Fork 114
Accept custom individual component file paths #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...oft.ComponentDetection.Orchestrator.Tests/Services/DefaultGraphTranslationServiceTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services; | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using FluentAssertions; | ||
| using Microsoft.ComponentDetection.Common.DependencyGraph; | ||
| using Microsoft.ComponentDetection.Contracts; | ||
| using Microsoft.ComponentDetection.Contracts.BcdeModels; | ||
| using Microsoft.ComponentDetection.Contracts.TypedComponent; | ||
| using Microsoft.ComponentDetection.Orchestrator.ArgumentSets; | ||
| using Microsoft.ComponentDetection.Orchestrator.Services; | ||
| using Microsoft.ComponentDetection.Orchestrator.Services.GraphTranslation; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using Moq; | ||
|
|
||
| [TestClass] | ||
| [TestCategory("Governance/All")] | ||
| [TestCategory("Governance/ComponentDetection")] | ||
| public class DefaultGraphTranslationServiceTests | ||
| { | ||
| private readonly DefaultGraphTranslationService serviceUnderTest; | ||
| private readonly ContainerDetails sampleContainerDetails; | ||
| private readonly ComponentRecorder componentRecorder; | ||
| private readonly Mock<IComponentDetector> componentDetectorMock; | ||
| private readonly DirectoryInfo sourceDirectory; | ||
|
|
||
| public DefaultGraphTranslationServiceTests() | ||
| { | ||
| this.serviceUnderTest = new DefaultGraphTranslationService(new Mock<ILogger<DefaultGraphTranslationService>>().Object); | ||
| this.componentRecorder = new ComponentRecorder(new Mock<ILogger>().Object); | ||
|
|
||
| this.sampleContainerDetails = new ContainerDetails { Id = 1 }; | ||
| this.componentDetectorMock = new Mock<IComponentDetector>(); | ||
| this.componentDetectorMock.SetupGet(x => x.Id).Returns("Detector1"); | ||
| this.componentDetectorMock.SetupGet(x => x.Version).Returns(1); | ||
| this.sourceDirectory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); | ||
| this.sourceDirectory.Create(); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateScanResultFromResult_WithCustomLocations() | ||
| { | ||
| var detectedFilePath = "/some/file/path"; | ||
| var npmCustomPath = "/custom/path.js"; | ||
| var nugetCustomPath = "/custom/path2.csproj"; | ||
| var relatedFilePath = "/generic/relevant/path"; | ||
|
|
||
| var singleFileComponentRecorder = this.componentRecorder.CreateSingleFileComponentRecorder(Path.Join(this.sourceDirectory.FullName, detectedFilePath)); | ||
| var processingResult = new DetectorProcessingResult | ||
| { | ||
| ResultCode = ProcessingResultCode.Success, | ||
| ContainersDetailsMap = new Dictionary<int, ContainerDetails> | ||
| { | ||
| { | ||
| this.sampleContainerDetails.Id, this.sampleContainerDetails | ||
| }, | ||
| }, | ||
| ComponentRecorders = new[] { (this.componentDetectorMock.Object, this.componentRecorder) }, | ||
| }; | ||
|
|
||
| var expectedNpmComponent = new NpmComponent("npm-component", "1.2.3"); | ||
| var expectedNugetComponent = new NuGetComponent("nugetComponent", "4.5.6"); | ||
| var detectedNpmComponent = new DetectedComponent(expectedNpmComponent); | ||
| var detectedNugetComponent = new DetectedComponent(expectedNugetComponent); | ||
|
|
||
| // Any Related File will be reported for ALL components found in this graph | ||
| singleFileComponentRecorder.AddAdditionalRelatedFile(Path.Join(this.sourceDirectory.FullName, relatedFilePath)); | ||
|
|
||
| // Registering components in same manifest with different custom paths | ||
| detectedNpmComponent.AddComponentFilePath(Path.Join(this.sourceDirectory.FullName, npmCustomPath)); | ||
grvillic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| detectedNugetComponent.AddComponentFilePath(Path.Join(this.sourceDirectory.FullName, nugetCustomPath)); | ||
|
|
||
| singleFileComponentRecorder.RegisterUsage(detectedNpmComponent, isDevelopmentDependency: false); | ||
| singleFileComponentRecorder.RegisterUsage(detectedNugetComponent, isDevelopmentDependency: true); | ||
|
|
||
| var args = new BcdeArguments | ||
| { | ||
| SourceDirectory = this.sourceDirectory, | ||
| }; | ||
|
|
||
| var result = this.serviceUnderTest.GenerateScanResultFromProcessingResult(processingResult, args); | ||
| result.Should().NotBeNull(); | ||
| result.ComponentsFound.Should().HaveCount(2); | ||
| result.ResultCode.Should().Be(ProcessingResultCode.Success); | ||
|
|
||
| var resultNpmComponent = result.ComponentsFound.Single(c => c.Component.Type == ComponentType.Npm); | ||
| var resultNugetComponent = result.ComponentsFound.Single(c => c.Component.Type == ComponentType.NuGet); | ||
|
|
||
| resultNpmComponent.LocationsFoundAt.Should().BeEquivalentTo(new[] { npmCustomPath, detectedFilePath, relatedFilePath }); | ||
| resultNugetComponent.LocationsFoundAt.Should().BeEquivalentTo(new[] { nugetCustomPath, detectedFilePath, relatedFilePath }); | ||
|
|
||
| var actualNpmComponent = resultNpmComponent.Component as NpmComponent; | ||
| var actualNugetComponent = resultNugetComponent.Component as NuGetComponent; | ||
|
|
||
| actualNpmComponent.Should().BeEquivalentTo(expectedNpmComponent); | ||
| actualNugetComponent.Should().BeEquivalentTo(expectedNugetComponent); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.