Skip to content

Commit 47e4c1c

Browse files
authored
fix: fix root directory for open source scans (#136)
1 parent 0700ab2 commit 47e4c1c

29 files changed

Lines changed: 636 additions & 491 deletions

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# Snyk Changelog
22

3-
## [1.1.9]
3+
## [1.1.10]
44

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

8+
### Fixed
9+
- Scan of solutions in which *.sln file is not in the root directory.
10+
11+
## [1.1.9]
12+
813
### Fixed
914
- "Object reference not set to an instance of an object" when launching extension in Visual Studio 2022.
1015

Snyk.Code.Library.Tests/SnykCode/AnalysisServiceTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public void AnalysisService_FailedStatusProvided_GetAnalysisThrowException()
3333
};
3434

3535
codeClientMock
36-
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()).Result)
37-
.Returns(dummyAnalysisResultDto);
36+
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()))
37+
.ReturnsAsync(dummyAnalysisResultDto);
3838

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

@@ -61,8 +61,8 @@ public async Task AnalysisService_WaitingStatusProvided_GetAnalysisSuccessInTwoA
6161
var mockMethodCallsCount = 0;
6262

6363
codeClientMock
64-
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()).Result)
65-
.Returns(dummyAnalysisResultDto)
64+
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()))
65+
.ReturnsAsync(dummyAnalysisResultDto)
6666
.Callback<string, CancellationToken>((str, cancellationToken) =>
6767
{
6868
mockMethodCallsCount++;
@@ -99,8 +99,8 @@ public async Task AnalysisService_InfiniteWaitingStatusProvided_GetAnalysisRetur
9999
};
100100

101101
codeClientMock
102-
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()).Result)
103-
.Returns(dummyAnalysisResultDto);
102+
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()))
103+
.ReturnsAsync(dummyAnalysisResultDto);
104104

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

@@ -282,8 +282,8 @@ public async Task AnalysisService_TwoFilesWithIssuesProvided_GetAnalysisSuccessA
282282
};
283283

284284
codeClientMock
285-
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()).Result)
286-
.Returns(dummyAnalysisResultDto);
285+
.Setup(codeClient => codeClient.GetAnalysisAsync(dummyBundleId, It.IsAny<CancellationToken>()))
286+
.ReturnsAsync(dummyAnalysisResultDto);
287287

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

Snyk.Code.Library.Tests/SnykCode/BundleServiceTest.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public async Task BundleService_TwoFilesProvided_UploadSuccessfullAfterTreeAttem
3838
};
3939

4040
codeClientMock
41-
.Setup(codeClient => codeClient.CheckBundleAsync(bundle.Id, It.IsAny<CancellationToken>()).Result)
42-
.Returns(bundleDto);
41+
.Setup(codeClient => codeClient.CheckBundleAsync(bundle.Id, It.IsAny<CancellationToken>()))
42+
.ReturnsAsync(bundleDto);
4343

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

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

105105
codeClientMock
106-
.Setup(codeClient => codeClient.CheckBundleAsync(dummyBundleDto.Hash, It.IsAny<CancellationToken>()).Result)
107-
.Returns(dummyBundleDto);
106+
.Setup(codeClient => codeClient.CheckBundleAsync(dummyBundleDto.Hash, It.IsAny<CancellationToken>()))
107+
.ReturnsAsync(dummyBundleDto);
108108

109109
var bundleService = new BundleService(codeClientMock.Object);
110110

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

144144
codeClientMock
145-
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()).Result)
146-
.Returns(dummyBundleDto);
145+
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()))
146+
.ReturnsAsync(dummyBundleDto);
147147

148148
var bundleService = new BundleService(codeClientMock.Object);
149149

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

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

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

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

193193
codeClientMock
194-
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()).Result)
195-
.Returns(dummyBundleDto);
194+
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()))
195+
.ReturnsAsync(dummyBundleDto);
196196

197197
var firstBundleDto = await bundleService.CreateBundleAsync(filePathToHashDict);
198198

@@ -215,8 +215,8 @@ public async Task BundleService_TwoFilesAndRemoveOneFileProvided_ExtendBundleChe
215215
};
216216

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

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

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

249249
codeClientMock
250-
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()).Result)
251-
.Returns(dummyBundleDto);
250+
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()))
251+
.ReturnsAsync(dummyBundleDto);
252252

253253
var firstBundleDto = await bundleService.CreateBundleAsync(filePathToHashDict);
254254

@@ -273,8 +273,8 @@ public async Task BundleService_FiveFilesProvided_ExtendBundleChecksPassAsync()
273273
};
274274

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

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

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

307307
codeClientMock
308-
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()).Result)
309-
.Returns(dummyBundleDto);
308+
.Setup(codeClient => codeClient.CreateBundleAsync(filePathToHashDict, It.IsAny<CancellationToken>()))
309+
.ReturnsAsync(dummyBundleDto);
310310

311311
var firstBundleDto = await bundleService.CreateBundleAsync(filePathToHashDict);
312312

@@ -331,8 +331,8 @@ public async Task BundleService_FiveFilesProvided_ProcessExtendLargeBundleChecks
331331
};
332332

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

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

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

368368
codeClientMock
369-
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()).Result)
370-
.Returns(dummyBundleDto);
369+
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()))
370+
.ReturnsAsync(dummyBundleDto);
371371

372372
var resultExtendBundleDto = new BundleResponseDto
373373
{
@@ -376,8 +376,8 @@ public async Task BundleService_FiftyFilesProvided_CreateBundleChecksPassAsync()
376376
};
377377

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

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

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

414414
codeClientMock
415-
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()).Result)
416-
.Returns(dummyBundleDto);
415+
.Setup(codeClient => codeClient.CreateBundleAsync(It.IsAny<Dictionary<string, string>>(), It.IsAny<CancellationToken>()))
416+
.ReturnsAsync(dummyBundleDto);
417417

418418
var resultExtendBundleDto = new BundleResponseDto
419419
{
@@ -422,8 +422,8 @@ public async Task BundleService_ThreeFilesProvided_ProcessCreateLargeBundleCheck
422422
};
423423

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

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

Snyk.Code.Library.Tests/SnykCode/CodeCacheServiceTest.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public void CodeCacheService_CodeCacheExists_RemoveDeletedFiles()
4141
var solutionServiceMock = new Mock<ISolutionService>();
4242

4343
solutionServiceMock
44-
.Setup(solutionService => solutionService.GetPath())
45-
.Returns(this.projectPath);
44+
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
45+
.ReturnsAsync(this.projectPath);
4646

4747
solutionServiceMock
48-
.Setup(solutionService => solutionService.GetFilesAsync().Result)
49-
.Returns(new List<string>());
48+
.Setup(solutionService => solutionService.GetFilesAsync())
49+
.ReturnsAsync(new List<string>());
5050

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

7070
solutionServiceMock
71-
.Setup(solutionService => solutionService.GetPath())
72-
.Returns(this.projectPath);
71+
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
72+
.ReturnsAsync(this.projectPath);
7373

7474
var fileProvider = new SnykCodeFileProvider(solutionServiceMock.Object);
7575

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

8888
solutionServiceMock
89-
.Setup(solutionService => solutionService.GetPath())
90-
.Returns(this.projectPath);
89+
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
90+
.ReturnsAsync(this.projectPath);
9191

9292
solutionServiceMock
93-
.Setup(solutionService => solutionService.GetFilesAsync().Result)
94-
.Returns(new List<string>());
93+
.Setup(solutionService => solutionService.GetFilesAsync())
94+
.ReturnsAsync(new List<string>());
9595

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

116116
solutionServiceMock
117-
.Setup(solutionService => solutionService.GetPath())
118-
.Returns(this.projectPath);
117+
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
118+
.ReturnsAsync(this.projectPath);
119119

120120
solutionServiceMock
121-
.Setup(solutionService => solutionService.GetFilesAsync().Result)
122-
.Returns(new List<string>());
121+
.Setup(solutionService => solutionService.GetFilesAsync())
122+
.ReturnsAsync(new List<string>());
123123

124124
var fileProvider = new SnykCodeFileProvider(solutionServiceMock.Object);
125125
var codeCacheService = new CodeCacheService(fileProvider);
@@ -149,12 +149,12 @@ public void CodeCacheService_AddFiles_CacheContainsFiles()
149149
var filtersServiceMock = new Mock<IFiltersService>();
150150

151151
solutionServiceMock
152-
.Setup(solutionService => solutionService.GetPath())
153-
.Returns(this.projectPath);
152+
.Setup(solutionService => solutionService.GetSolutionFolderAsync())
153+
.ReturnsAsync(this.projectPath);
154154

155155
solutionServiceMock
156-
.Setup(solutionService => solutionService.GetFilesAsync().Result)
157-
.Returns(new List<string>());
156+
.Setup(solutionService => solutionService.GetFilesAsync())
157+
.ReturnsAsync(new List<string>());
158158

159159
var fileProvider = new SnykCodeFileProvider(solutionServiceMock.Object);
160160
var codeCacheService = new CodeCacheService(fileProvider);

Snyk.Code.Library.Tests/SnykCode/FiltersServiceTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public async Task FiltersService_FiveCodeFilesProvided_FilterFilesCheckPassAsync
4646
};
4747

4848
codeClientMock
49-
.Setup(codeClient => codeClient.GetFiltersAsync().Result)
50-
.Returns(filtersDto);
49+
.Setup(codeClient => codeClient.GetFiltersAsync())
50+
.ReturnsAsync(filtersDto);
5151

5252
var filterService = new FiltersService(codeClientMock.Object);
5353

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

9999
codeClientMock
100-
.Setup(codeClient => codeClient.GetFiltersAsync().Result)
101-
.Returns(filtersDto);
100+
.Setup(codeClient => codeClient.GetFiltersAsync())
101+
.ReturnsAsync(filtersDto);
102102

103103
var filterService = new FiltersService(codeClientMock.Object);
104104

@@ -141,8 +141,8 @@ public async Task FiltersService_FiveCodeFilesAndFiveConfigFilesProvided_FilterF
141141
var filtersDto = GetFiltersDto();
142142

143143
codeClientMock
144-
.Setup(codeClient => codeClient.GetFiltersAsync().Result)
145-
.Returns(filtersDto);
144+
.Setup(codeClient => codeClient.GetFiltersAsync())
145+
.ReturnsAsync(filtersDto);
146146

147147
var filterService = new FiltersService(codeClientMock.Object);
148148

0 commit comments

Comments
 (0)