Skip to content

Commit

Permalink
fix: fix root directory for open source scans (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
aldanchenko authored Apr 19, 2022
1 parent 0700ab2 commit 47e4c1c
Show file tree
Hide file tree
Showing 29 changed files with 636 additions and 491 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Snyk Changelog

## [1.1.9]
## [1.1.10]

### Changed
- Snyk Code: add support for Single Tenant setups.

### Fixed
- Scan of solutions in which *.sln file is not in the root directory.

## [1.1.9]

### Fixed
- "Object reference not set to an instance of an object" when launching extension in Visual Studio 2022.

Expand Down
16 changes: 8 additions & 8 deletions Snyk.Code.Library.Tests/SnykCode/AnalysisServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void AnalysisService_FailedStatusProvided_GetAnalysisThrowException()
};

codeClientMock
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()).Result)
.Returns(dummyAnalysisResultDto);
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyAnalysisResultDto);

_ = Assert.ThrowsAsync<AggregateException>(() => analysisService.GetAnalysisAsync(dummyBundleId, scanCodeProgressUpdate));

Expand All @@ -61,8 +61,8 @@ public async Task AnalysisService_WaitingStatusProvided_GetAnalysisSuccessInTwoA
var mockMethodCallsCount = 0;

codeClientMock
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()).Result)
.Returns(dummyAnalysisResultDto)
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyAnalysisResultDto)
.Callback<string, CancellationToken>((str, cancellationToken) =>
{
mockMethodCallsCount++;
Expand Down Expand Up @@ -99,8 +99,8 @@ public async Task AnalysisService_InfiniteWaitingStatusProvided_GetAnalysisRetur
};

codeClientMock
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()).Result)
.Returns(dummyAnalysisResultDto);
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyAnalysisResultDto);

var analysisResult = await analysisService.GetAnalysisAsync(dummyBundleId, this.scanCodeProgressUpdate, requestAttempts: 5);

Expand Down Expand Up @@ -282,8 +282,8 @@ public async Task AnalysisService_TwoFilesWithIssuesProvided_GetAnalysisSuccessA
};

codeClientMock
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()).Result)
.Returns(dummyAnalysisResultDto);
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyAnalysisResultDto);

var analysisResult = await analysisService.GetAnalysisAsync(dummyBundleId, this.scanCodeProgressUpdate);

Expand Down
60 changes: 30 additions & 30 deletions Snyk.Code.Library.Tests/SnykCode/BundleServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public async Task BundleService_TwoFilesProvided_UploadSuccessfullAfterTreeAttem
};

codeClientMock
.Setup(codeClient => codeClient.CheckBundleAsync(bundle.Id, It.IsAny<CancellationToken>()).Result)
.Returns(bundleDto);
.Setup(codeClient => codeClient.CheckBundleAsync(bundle.Id, It.IsAny<CancellationToken>()))
.ReturnsAsync(bundleDto);

string fileContent1 = TestResource.GetFileContent("app1.js");
string fileContent2 = TestResource.GetFileContent("app2.js");
Expand All @@ -56,8 +56,8 @@ public async Task BundleService_TwoFilesProvided_UploadSuccessfullAfterTreeAttem
var mockMethodCallsCount = 1;

codeClientMock
.Setup(codeClient => codeClient.ExtendBundleAsync(bundle.Id, It.IsAny<Dictionary<string, CodeFileDto>>(), It.IsAny<CancellationToken>()).Result)
.Returns(new BundleResponseDto())
.Setup(codeClient => codeClient.ExtendBundleAsync(bundle.Id, It.IsAny<Dictionary<string, CodeFileDto>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new BundleResponseDto())
.Callback<string, IDictionary<string, CodeFileDto>, CancellationToken>((str, codeFilesDict, cancellationToken) =>
{
mockMethodCallsCount++;
Expand Down Expand Up @@ -103,8 +103,8 @@ public async Task BundleService_ActiveBundleProvided_CheckBundleSuccessfullAsync
var dummyBundleDto = new BundleResponseDto { Hash = "dummy id" };

codeClientMock
.Setup(codeClient => codeClient.CheckBundleAsync(dummyBundleDto.Hash, It.IsAny<CancellationToken>()).Result)
.Returns(dummyBundleDto);
.Setup(codeClient => codeClient.CheckBundleAsync(dummyBundleDto.Hash, It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyBundleDto);

var bundleService = new BundleService(codeClientMock.Object);

Expand Down Expand Up @@ -142,8 +142,8 @@ public async Task BundleService_ThreeFilesProvided_UploadedSuccessfullyAsync()
var dummyBundleDto = new BundleResponseDto { Hash = "dummy id" };

codeClientMock
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()).Result)
.Returns(dummyBundleDto);
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyBundleDto);

var bundleService = new BundleService(codeClientMock.Object);

Expand All @@ -159,8 +159,8 @@ public async Task BundleService_ThreeFilesProvided_UploadedSuccessfullyAsync()
fileHashToContentDict.Add(filePath3, (fileHash3, fileContent3));

codeClientMock
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, CodeFileDto>>(), It.IsAny<CancellationToken>()).Result)
.Returns(new BundleResponseDto());
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, CodeFileDto>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new BundleResponseDto());

bool isSuccess = await bundleService.UploadFilesAsync(createdBundle.Id, fileHashToContentDict, (state, progress) => { }, 200);

Expand Down Expand Up @@ -191,8 +191,8 @@ public async Task BundleService_TwoFilesAndRemoveOneFileProvided_ExtendBundleChe
var dummyBundleDto = new BundleResponseDto { Hash = "dummy id" };

codeClientMock
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()).Result)
.Returns(dummyBundleDto);
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyBundleDto);

var firstBundleDto = await bundleService.CreateBundleAsync(filePathToHashDict);

Expand All @@ -215,8 +215,8 @@ public async Task BundleService_TwoFilesAndRemoveOneFileProvided_ExtendBundleChe
};

codeClientMock
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()).Result)
.Returns(resultExtendBundleDto);
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(resultExtendBundleDto);

var uploadedBundle = await bundleService.ExtendBundleAsync(firstBundleDto.Id, extendFilePathToHashDict, filesToRemovePaths, 200);

Expand Down Expand Up @@ -247,8 +247,8 @@ public async Task BundleService_FiveFilesProvided_ExtendBundleChecksPassAsync()
var dummyBundleDto = new BundleResponseDto { Hash = "dummy id" };

codeClientMock
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()).Result)
.Returns(dummyBundleDto);
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyBundleDto);

var firstBundleDto = await bundleService.CreateBundleAsync(filePathToHashDict);

Expand All @@ -273,8 +273,8 @@ public async Task BundleService_FiveFilesProvided_ExtendBundleChecksPassAsync()
};

codeClientMock
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()).Result)
.Returns(resultExtendBundleDto);
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(resultExtendBundleDto);

var extendedBundle = await bundleService.ExtendBundleAsync(firstBundleDto.Id, extendFilePathToHashDict, new List<string>(), 150);

Expand Down Expand Up @@ -305,8 +305,8 @@ public async Task BundleService_FiveFilesProvided_ProcessExtendLargeBundleChecks
var dummyBundleDto = new BundleResponseDto { Hash = "dummy id" };

codeClientMock
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()).Result)
.Returns(dummyBundleDto);
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyBundleDto);

var firstBundleDto = await bundleService.CreateBundleAsync(filePathToHashDict);

Expand All @@ -331,8 +331,8 @@ public async Task BundleService_FiveFilesProvided_ProcessExtendLargeBundleChecks
};

codeClientMock
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()).Result)
.Returns(resultExtendBundleDto);
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(resultExtendBundleDto);

var extendedBundle = await bundleService.ProcessExtendLargeBundleAsync(firstBundleDto.Id, extendFilePathToHashDict, null, 150);

Expand Down Expand Up @@ -366,8 +366,8 @@ public async Task BundleService_FiftyFilesProvided_CreateBundleChecksPassAsync()
var dummyBundleDto = new BundleResponseDto { Hash = "dummy id" };

codeClientMock
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()).Result)
.Returns(dummyBundleDto);
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyBundleDto);

var resultExtendBundleDto = new BundleResponseDto
{
Expand All @@ -376,8 +376,8 @@ public async Task BundleService_FiftyFilesProvided_CreateBundleChecksPassAsync()
};

codeClientMock
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()).Result)
.Returns(resultExtendBundleDto);
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(resultExtendBundleDto);

var bundleDto = await bundleService.CreateBundleAsync(filePathToHashDict, 150);

Expand Down Expand Up @@ -412,8 +412,8 @@ public async Task BundleService_ThreeFilesProvided_ProcessCreateLargeBundleCheck
var dummyBundleDto = new BundleResponseDto { Hash = "dummy id" };

codeClientMock
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()).Result)
.Returns(dummyBundleDto);
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(dummyBundleDto);

var resultExtendBundleDto = new BundleResponseDto
{
Expand All @@ -422,8 +422,8 @@ public async Task BundleService_ThreeFilesProvided_ProcessCreateLargeBundleCheck
};

codeClientMock
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()).Result)
.Returns(resultExtendBundleDto);
.Setup(codeClient => codeClient.ExtendBundleAsync(dummyBundleDto.Hash, It.IsAny<Dictionary<string, string>>(), It.IsAny<List<string>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(resultExtendBundleDto);

var bundleDto = await bundleService.ProcessCreateLargeBundleAsync(filePathToHashDict, 175);

Expand Down
36 changes: 18 additions & 18 deletions Snyk.Code.Library.Tests/SnykCode/CodeCacheServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public void CodeCacheService_CodeCacheExists_RemoveDeletedFiles()
var solutionServiceMock = new Mock<ISolutionService>();

solutionServiceMock
.Setup(solutionService => solutionService.GetPath())
.Returns(this.projectPath);
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
.ReturnsAsync(this.projectPath);

solutionServiceMock
.Setup(solutionService => solutionService.GetFilesAsync().Result)
.Returns(new List<string>());
.Setup(solutionService => solutionService.GetFilesAsync())
.ReturnsAsync(new List<string>());

var fileProvider = new SnykCodeFileProvider(solutionServiceMock.Object);
var codeCacheService = new CodeCacheService(fileProvider);
Expand All @@ -68,8 +68,8 @@ public void CodeCacheService_CodeCacheExists_ValidCache()
var solutionServiceMock = new Mock<ISolutionService>();

solutionServiceMock
.Setup(solutionService => solutionService.GetPath())
.Returns(this.projectPath);
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
.ReturnsAsync(this.projectPath);

var fileProvider = new SnykCodeFileProvider(solutionServiceMock.Object);

Expand All @@ -86,12 +86,12 @@ public void CodeCacheService_CodeCacheExists_InvalidCache()
var solutionServiceMock = new Mock<ISolutionService>();

solutionServiceMock
.Setup(solutionService => solutionService.GetPath())
.Returns(this.projectPath);
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
.ReturnsAsync(this.projectPath);

solutionServiceMock
.Setup(solutionService => solutionService.GetFilesAsync().Result)
.Returns(new List<string>());
.Setup(solutionService => solutionService.GetFilesAsync())
.ReturnsAsync(new List<string>());

var fileProvider = new SnykCodeFileProvider(solutionServiceMock.Object);
var codeCacheService = new CodeCacheService(fileProvider);
Expand All @@ -114,12 +114,12 @@ public void CodeCacheService_UpdateFile_CacheUpdated()
var filtersServiceMock = new Mock<IFiltersService>();

solutionServiceMock
.Setup(solutionService => solutionService.GetPath())
.Returns(this.projectPath);
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
.ReturnsAsync(this.projectPath);

solutionServiceMock
.Setup(solutionService => solutionService.GetFilesAsync().Result)
.Returns(new List<string>());
.Setup(solutionService => solutionService.GetFilesAsync())
.ReturnsAsync(new List<string>());

var fileProvider = new SnykCodeFileProvider(solutionServiceMock.Object);
var codeCacheService = new CodeCacheService(fileProvider);
Expand Down Expand Up @@ -149,12 +149,12 @@ public void CodeCacheService_AddFiles_CacheContainsFiles()
var filtersServiceMock = new Mock<IFiltersService>();

solutionServiceMock
.Setup(solutionService => solutionService.GetPath())
.Returns(this.projectPath);
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
.ReturnsAsync(this.projectPath);

solutionServiceMock
.Setup(solutionService => solutionService.GetFilesAsync().Result)
.Returns(new List<string>());
.Setup(solutionService => solutionService.GetFilesAsync())
.ReturnsAsync(new List<string>());

var fileProvider = new SnykCodeFileProvider(solutionServiceMock.Object);
var codeCacheService = new CodeCacheService(fileProvider);
Expand Down
12 changes: 6 additions & 6 deletions Snyk.Code.Library.Tests/SnykCode/FiltersServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public async Task FiltersService_FiveCodeFilesProvided_FilterFilesCheckPassAsync
};

codeClientMock
.Setup(codeClient => codeClient.GetFiltersAsync().Result)
.Returns(filtersDto);
.Setup(codeClient => codeClient.GetFiltersAsync())
.ReturnsAsync(filtersDto);

var filterService = new FiltersService(codeClientMock.Object);

Expand Down Expand Up @@ -97,8 +97,8 @@ public async Task FiltersService_FiveConfigFilesProvided_FilterFilesCheckPassAsy
var codeClientMock = new Mock<ISnykCodeClient>();

codeClientMock
.Setup(codeClient => codeClient.GetFiltersAsync().Result)
.Returns(filtersDto);
.Setup(codeClient => codeClient.GetFiltersAsync())
.ReturnsAsync(filtersDto);

var filterService = new FiltersService(codeClientMock.Object);

Expand Down Expand Up @@ -141,8 +141,8 @@ public async Task FiltersService_FiveCodeFilesAndFiveConfigFilesProvided_FilterF
var filtersDto = GetFiltersDto();

codeClientMock
.Setup(codeClient => codeClient.GetFiltersAsync().Result)
.Returns(filtersDto);
.Setup(codeClient => codeClient.GetFiltersAsync())
.ReturnsAsync(filtersDto);

var filterService = new FiltersService(codeClientMock.Object);

Expand Down
Loading

0 comments on commit 47e4c1c

Please sign in to comment.