From 49c5d4e8439853d0b99425788bf51209e77b88dd Mon Sep 17 00:00:00 2001 From: PeterSchafer <101886095+PeterSchafer@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:20:07 +0100 Subject: [PATCH] feat: Derive Vulnerability Count from LS results [HEAD-942] (#388) * chore: introduce observerable in ProductService * feat: enable LS based Vulnerability Count Service * fix: creating subject * chore: introduce static getOssIssueArgCommand() * chore: adapt vuln count code action provider * chore: remove dependency to old OSSService * fix: linter & cleanup * chore: adapt test to use LS versions of classes * chore: delete now obsolote classes * fix: duplicate diagnostics message * fix: use strict equal * chore: convert severities explicitely * fix: typo --- src/snyk/base/modules/baseSnykModule.ts | 4 +- src/snyk/common/services/productService.ts | 4 +- src/snyk/extension.ts | 16 ++-- ...s => vulnerabilityCodeActionProviderLS.ts} | 36 ++++++-- src/snyk/snykOss/ossResult.ts | 14 ++++ src/snyk/snykOss/services/ossService.ts | 2 +- ...e.ts => ossVulnerabilityCountServiceLS.ts} | 21 +++-- ...der.ts => vulnerabilityCountProviderLS.ts} | 83 +++++++++++++++++-- .../ossVulnerabilityCountService.test.ts | 29 +++---- .../vulnerabilityCountProvider.test.ts | 42 +++++----- 10 files changed, 179 insertions(+), 72 deletions(-) rename src/snyk/snykOss/codeActions/{vulnerabilityCodeActionProvider.ts => vulnerabilityCodeActionProviderLS.ts} (66%) rename src/snyk/snykOss/services/vulnerabilityCount/{ossVulnerabilityCountService.ts => ossVulnerabilityCountServiceLS.ts} (92%) rename src/snyk/snykOss/services/vulnerabilityCount/{vulnerabilityCountProvider.ts => vulnerabilityCountProviderLS.ts} (64%) diff --git a/src/snyk/base/modules/baseSnykModule.ts b/src/snyk/base/modules/baseSnykModule.ts index 4dc05fdbd..5681dafdf 100644 --- a/src/snyk/base/modules/baseSnykModule.ts +++ b/src/snyk/base/modules/baseSnykModule.ts @@ -25,7 +25,7 @@ import { ICodeSettings } from '../../snykCode/codeSettings'; import SnykEditorsWatcher from '../../snykCode/watchers/editorsWatcher'; import { OssServiceLanguageServer } from '../../snykOss/ossServiceLanguageServer'; import { OssService } from '../../snykOss/services/ossService'; -import { OssVulnerabilityCountService } from '../../snykOss/services/vulnerabilityCount/ossVulnerabilityCountService'; +import { OssVulnerabilityCountServiceLS } from '../../snykOss/services/vulnerabilityCount/ossVulnerabilityCountServiceLS'; import { IAuthenticationService } from '../services/authenticationService'; import { ScanModeService } from '../services/scanModeService'; import SnykStatusBarItem, { IStatusBarItem } from '../statusBarItem/statusBarItem'; @@ -50,7 +50,7 @@ export default abstract class BaseSnykModule implements IBaseSnykModule { protected advisorService?: AdvisorProvider; protected commandController: CommandController; protected scanModeService: ScanModeService; - protected ossVulnerabilityCountService: OssVulnerabilityCountService; + protected ossVulnerabilityCountServiceLanguageServer: OssVulnerabilityCountServiceLS; protected advisorScoreDisposable: AdvisorService; protected languageServer: ILanguageServer; diff --git a/src/snyk/common/services/productService.ts b/src/snyk/common/services/productService.ts index 62b6c69b3..efb4f06b1 100644 --- a/src/snyk/common/services/productService.ts +++ b/src/snyk/common/services/productService.ts @@ -1,4 +1,4 @@ -import { Subscription } from 'rxjs'; +import { Subject, Subscription } from 'rxjs'; import { AnalysisStatusProvider } from '../analysis/statusProvider'; import { IConfiguration } from '../configuration/configuration'; import { IWorkspaceTrust } from '../configuration/trustedFolders'; @@ -30,6 +30,7 @@ export interface IProductService extends AnalysisStatusProvider, Disposable { export abstract class ProductService extends AnalysisStatusProvider implements IProductService { private _result: ProductResult; + readonly newResultAvailable$ = new Subject(); // Track running scan count. Assumption: server sends N success/error messages for N scans in progress. private runningScanCount = 0; @@ -168,6 +169,7 @@ export abstract class ProductService extends AnalysisStatusProvider implement this.analysisFinished(); this.runningScanCount = 0; + this.newResultAvailable$.next(); this.refreshTreeView(); } } diff --git a/src/snyk/extension.ts b/src/snyk/extension.ts index 71e42fe4f..8085d6d9d 100644 --- a/src/snyk/extension.ts +++ b/src/snyk/extension.ts @@ -79,8 +79,8 @@ import { OssServiceLanguageServer } from './snykOss/ossServiceLanguageServer'; import { OssDetailPanelProvider } from './snykOss/providers/ossDetailPanelProvider'; import OssIssueTreeProvider from './snykOss/providers/ossVulnerabilityTreeProvider'; import { OssService } from './snykOss/services/ossService'; -import { OssVulnerabilityCountService } from './snykOss/services/vulnerabilityCount/ossVulnerabilityCountService'; -import { ModuleVulnerabilityCountProvider } from './snykOss/services/vulnerabilityCount/vulnerabilityCountProvider'; +import { OssVulnerabilityCountServiceLS } from './snykOss/services/vulnerabilityCount/ossVulnerabilityCountServiceLS'; +import { ModuleVulnerabilityCountProviderLS } from './snykOss/services/vulnerabilityCount/vulnerabilityCountProviderLS'; import { OssVulnerabilityTreeProvider } from './snykOss/views/ossVulnerabilityTreeProvider'; import { OssSuggestionWebviewProvider } from './snykOss/views/suggestion/ossSuggestionWebviewProvider'; import { DailyScanJob } from './snykOss/watchers/dailyScanJob'; @@ -414,24 +414,24 @@ class SnykExtension extends SnykLib implements IExtension { this.initDependencyDownload(); - this.ossVulnerabilityCountService = new OssVulnerabilityCountService( + this.ossVulnerabilityCountServiceLanguageServer = new OssVulnerabilityCountServiceLS( vsCodeWorkspace, vsCodeWindow, vsCodeLanguages, - new ModuleVulnerabilityCountProvider( - this.ossService, + new ModuleVulnerabilityCountProviderLS( + this.ossServiceLanguageServer, languageClientAdapter, new UriAdapter(), new TextDocumentAdapter(), ), - this.ossService, + this.ossServiceLanguageServer, Logger, new EditorDecorator(vsCodeWindow, vsCodeLanguages, new ThemeColorAdapter()), new CodeActionKindAdapter(), this.analytics, configuration, ); - this.ossVulnerabilityCountService.activate(); + this.ossVulnerabilityCountServiceLanguageServer.activate(); this.advisorScoreDisposable = new AdvisorService( vsCodeWindow, @@ -461,7 +461,7 @@ class SnykExtension extends SnykLib implements IExtension { } public async deactivate(): Promise { - this.ossVulnerabilityCountService.dispose(); + this.ossVulnerabilityCountServiceLanguageServer.dispose(); await this.languageServer.stop(); await this.analytics.flush(); await ErrorReporter.flush(); diff --git a/src/snyk/snykOss/codeActions/vulnerabilityCodeActionProvider.ts b/src/snyk/snykOss/codeActions/vulnerabilityCodeActionProviderLS.ts similarity index 66% rename from src/snyk/snykOss/codeActions/vulnerabilityCodeActionProvider.ts rename to src/snyk/snykOss/codeActions/vulnerabilityCodeActionProviderLS.ts index 68b1b3535..1d398a5f5 100644 --- a/src/snyk/snykOss/codeActions/vulnerabilityCodeActionProvider.ts +++ b/src/snyk/snykOss/codeActions/vulnerabilityCodeActionProviderLS.ts @@ -1,3 +1,4 @@ +import marked from 'marked'; import { IAnalytics } from '../../common/analytics/itly'; import { OpenCommandIssueType, OpenIssueCommandArg } from '../../common/commands/types'; import { SNYK_OPEN_ISSUE_COMMAND } from '../../common/constants/commands'; @@ -16,16 +17,15 @@ import { } from '../../common/vscode/types'; import { DIAGNOSTICS_OSS_COLLECTION_NAME } from '../../snykCode/constants/analysis'; import { messages } from '../messages/vulnerabilityCount'; -import { isResultCliError } from '../ossResult'; -import { OssService } from '../services/ossService'; -import { ModuleVulnerabilityCountProvider } from '../services/vulnerabilityCount/vulnerabilityCountProvider'; +import { OssVulnerability, isResultCliError } from '../ossResult'; +import { ModuleVulnerabilityCountProviderLS } from '../services/vulnerabilityCount/vulnerabilityCountProviderLS'; +import { OssIssueCommandArg } from '../views/ossVulnerabilityTreeProvider'; -export class VulnerabilityCodeActionProvider implements CodeActionProvider { +export class VulnerabilityCodeActionProviderLS implements CodeActionProvider { public codeActionKinds: ReadonlyArray = [this.codeActionKindProvider.getQuickFix()]; constructor( - private readonly ossService: OssService, - private readonly vulnerabilityCountProvider: ModuleVulnerabilityCountProvider, + private readonly vulnerabilityCountProvider: ModuleVulnerabilityCountProviderLS, private readonly codeActionKindProvider: ICodeActionKindAdapter, private readonly analytics: IAnalytics, ) {} @@ -40,7 +40,7 @@ export class VulnerabilityCodeActionProvider implements CodeActionProvider { return; } - const ossResult = this.ossService.getResultArray(); + const ossResult = this.vulnerabilityCountProvider.getResultArray(); if (!ossResult) { return; } @@ -65,7 +65,7 @@ export class VulnerabilityCodeActionProvider implements CodeActionProvider { arguments: [ { issueType: OpenCommandIssueType.OssVulnerability, - issue: await this.ossService.getOssIssueCommandArg(vulnerability, fileResult.vulnerabilities), + issue: await this.getOssIssueCommandArg(vulnerability, fileResult.vulnerabilities), } as OpenIssueCommandArg, ], }; @@ -78,4 +78,24 @@ export class VulnerabilityCodeActionProvider implements CodeActionProvider { return [command]; } } + + getOssIssueCommandArg( + vulnerability: OssVulnerability, + allVulnerabilities: OssVulnerability[], + ): Promise { + return new Promise((resolve, reject) => { + const matchingIdVulnerabilities = allVulnerabilities.filter(v => v.id === vulnerability.id); + marked.parse(vulnerability.description, (err, overviewHtml) => { + if (err) { + return reject(err); + } + + return resolve({ + ...vulnerability, + matchingIdVulnerabilities: matchingIdVulnerabilities, + overviewHtml, + }); + }); + }); + } } diff --git a/src/snyk/snykOss/ossResult.ts b/src/snyk/snykOss/ossResult.ts index 625019a49..b469695d8 100644 --- a/src/snyk/snykOss/ossResult.ts +++ b/src/snyk/snykOss/ossResult.ts @@ -1,5 +1,6 @@ import _ from 'lodash'; import { CliError } from '../cli/services/cliService'; +import { IssueSeverity } from '../common/languageServer/types'; export type OssResult = OssFileResult[] | OssFileResult; @@ -56,3 +57,16 @@ export function capitalizeOssSeverity(ossSeverity: OssSeverity): Capitalize this.processActiveEditor()); + this.ossScanFinishedSubscription = this.ossService.newResultAvailable$.subscribe(() => this.processActiveEditor()); [JAVASCRIPT, TYPESCRIPT, PJSON, HTML].forEach(language => { - const provider = new VulnerabilityCodeActionProvider( - this.ossService, + const provider = new VulnerabilityCodeActionProviderLS( this.vulnerabilityCountProvider, this.codeActionKindProvider, this.analytics, @@ -188,7 +187,7 @@ export class OssVulnerabilityCountService implements Disposable { private shouldProcessFile(fileName: string, language: Language): boolean { if ([Language.TypeScript, Language.JavaScript, Language.PJSON].includes(language)) { - const ossResult = this.ossService.getResultArray(); + const ossResult = this.vulnerabilityCountProvider.getResultArray(); if (!ossResult) { return false; } @@ -254,7 +253,7 @@ export class OssVulnerabilityCountService implements Disposable { ], module, ); - message += messages.decoratorMessage(module.count); + return message; } diff --git a/src/snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProvider.ts b/src/snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProviderLS.ts similarity index 64% rename from src/snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProvider.ts rename to src/snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProviderLS.ts index 3c852ae33..0f24e8304 100644 --- a/src/snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProvider.ts +++ b/src/snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProviderLS.ts @@ -1,15 +1,16 @@ +import { CliError } from '../../../cli/services/cliService'; import { Language } from '../../../common/types'; import { ILanguageClientAdapter } from '../../../common/vscode/languageClient'; import { ITextDocumentAdapter } from '../../../common/vscode/textdocument'; import { InlineValueText, LSPTextDocument } from '../../../common/vscode/types'; import { IUriAdapter } from '../../../common/vscode/uri'; -import { OssFileResult, OssResultBody, OssVulnerability, isResultCliError } from '../../ossResult'; -import { OssService } from '../ossService'; +import { OssFileResult, OssResultBody, OssVulnerability, convertSeverity, isResultCliError } from '../../ossResult'; +import { OssServiceLanguageServer } from '../../ossServiceLanguageServer'; import { ImportedModule, ModuleVulnerabilityCount, SeverityCounts } from './importedModule'; -export class ModuleVulnerabilityCountProvider { +export class ModuleVulnerabilityCountProviderLS { constructor( - private readonly ossService: OssService, + private readonly ossService: OssServiceLanguageServer, private readonly lca: ILanguageClientAdapter, private readonly uriAdapter: IUriAdapter, private readonly textDocumentAdapter: ITextDocumentAdapter, @@ -29,8 +30,7 @@ export class ModuleVulnerabilityCountProvider { }; if ([Language.TypeScript, Language.JavaScript, Language.PJSON].includes(language)) { - // TODO use LS when OSS is moved to LS - const ossResult = this.ossService.getResultArray(); + const ossResult = this.getResultArray(); if (!ossResult) { return notCalculated; } @@ -91,7 +91,7 @@ export class ModuleVulnerabilityCountProvider { continue; } - const vulnerabilities = this.ossService.getUniqueVulnerabilities((fileResult as OssResultBody).vulnerabilities); + const vulnerabilities = this.getUniqueVulnerabilities((fileResult as OssResultBody).vulnerabilities); // Sum up all vulnerabilities detected in first-level dependencies by OSS matching the imported module name. // Ideally we want to use the same mechanism as NPM for determining the version used within users code. For now we stick with direct-vulnerability surfacing only. @@ -158,4 +158,73 @@ export class ModuleVulnerabilityCountProvider { return 0; })?.[0]; } + + public getResultArray = (): ReadonlyArray | undefined => { + if (!this.ossService.result) { + return undefined; + } + + const tempResultArray: OssFileResult[] = []; + const resultCache = new Map(); + + for (const [, value] of this.ossService.result) { + // value is Error + if (value instanceof Error) { + tempResultArray.push(new CliError(value)); + } + // value is Issue[] + else { + for (const issue of value) { + // try to access list of vulns for the current file + let res = resultCache.get(issue.filePath); + + // add list of vulns to local cache if not there yet + if (res === undefined) { + res = { + path: issue.filePath, + vulnerabilities: [], + projectName: issue.additionalData.projectName, + displayTargetFile: issue.additionalData.displayTargetFile, + packageManager: issue.additionalData.packageManager, + }; + resultCache.set(issue.filePath, res); + } + + const tempVuln: OssVulnerability = { + id: issue.id, + license: issue.additionalData.license, + identifiers: issue.additionalData.identifiers, + title: issue.title, + description: issue.additionalData.description, + language: issue.additionalData.language, + packageManager: issue.additionalData.packageManager, + packageName: issue.additionalData.packageName, + severity: convertSeverity(issue.severity), + name: issue.additionalData.name, + version: issue.additionalData.version, + exploit: issue.additionalData.exploit, + + CVSSv3: issue.additionalData.CVSSv3, + cvssScore: issue.additionalData.cvssScore, + + fixedIn: issue.additionalData.fixedIn, + from: issue.additionalData.from, + upgradePath: issue.additionalData.upgradePath, + isPatchable: issue.additionalData.isPatchable, + isUpgradable: issue.additionalData.isUpgradable, + }; + res.vulnerabilities.push(tempVuln); + } + } + } + + // copy cached results to final result array + resultCache.forEach(value => tempResultArray.push(value)); + + return tempResultArray; + }; + + public getUniqueVulnerabilities(vulnerabilities: OssVulnerability[]): OssVulnerability[] { + return vulnerabilities.filter((val, i, arr) => arr.findIndex(el => el.id === val.id) === i); + } } diff --git a/src/test/unit/snykOss/services/vulnerabilityCount/ossVulnerabilityCountService.test.ts b/src/test/unit/snykOss/services/vulnerabilityCount/ossVulnerabilityCountService.test.ts index 1e8277bc5..5a444dceb 100644 --- a/src/test/unit/snykOss/services/vulnerabilityCount/ossVulnerabilityCountService.test.ts +++ b/src/test/unit/snykOss/services/vulnerabilityCount/ossVulnerabilityCountService.test.ts @@ -4,34 +4,35 @@ import sinon from 'sinon'; import { IAnalytics } from '../../../../../snyk/common/analytics/itly'; import { IConfiguration } from '../../../../../snyk/common/configuration/configuration'; import { ICodeActionKindAdapter } from '../../../../../snyk/common/vscode/codeAction'; +import { ILanguageClientAdapter } from '../../../../../snyk/common/vscode/languageClient'; import { IVSCodeLanguages } from '../../../../../snyk/common/vscode/languages'; +import { ITextDocumentAdapter } from '../../../../../snyk/common/vscode/textdocument'; import { IThemeColorAdapter } from '../../../../../snyk/common/vscode/theme'; import { TextDocument, TextEditor } from '../../../../../snyk/common/vscode/types'; +import { IUriAdapter } from '../../../../../snyk/common/vscode/uri'; import { IVSCodeWindow } from '../../../../../snyk/common/vscode/window'; import { IVSCodeWorkspace } from '../../../../../snyk/common/vscode/workspace'; import { EditorDecorator } from '../../../../../snyk/snykOss/editor/editorDecorator'; import { OssFileResult } from '../../../../../snyk/snykOss/ossResult'; -import { OssService } from '../../../../../snyk/snykOss/services/ossService'; -import { OssVulnerabilityCountService } from '../../../../../snyk/snykOss/services/vulnerabilityCount/ossVulnerabilityCountService'; -import { ModuleVulnerabilityCountProvider } from '../../../../../snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProvider'; +import { OssServiceLanguageServer } from '../../../../../snyk/snykOss/ossServiceLanguageServer'; +import { OssVulnerabilityCountServiceLS } from '../../../../../snyk/snykOss/services/vulnerabilityCount/ossVulnerabilityCountServiceLS'; +import { ModuleVulnerabilityCountProviderLS } from '../../../../../snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProviderLS'; import { LoggerMock } from '../../../mocks/logger.mock'; -import { ILanguageClientAdapter } from '../../../../../snyk/common/vscode/languageClient'; -import { IUriAdapter } from '../../../../../snyk/common/vscode/uri'; -import { ITextDocumentAdapter } from '../../../../../snyk/common/vscode/textdocument'; suite('OSS VulnerabilityCountService', () => { let workspace: IVSCodeWorkspace; let window: IVSCodeWindow; let languages: IVSCodeLanguages; - let ossVulnerabilityCountService: OssVulnerabilityCountService; - let ossService: OssService; - let vulnerabilityCountProvider: ModuleVulnerabilityCountProvider; + let ossVulnerabilityCountService: OssVulnerabilityCountServiceLS; + let ossService: OssServiceLanguageServer; + let vulnerabilityCountProvider: ModuleVulnerabilityCountProviderLS; setup(() => { const logger = new LoggerMock(); ossService = { scanFinished$: EMPTY, - } as unknown as OssService; + newResultAvailable$: EMPTY, + } as unknown as OssServiceLanguageServer; workspace = {} as IVSCodeWorkspace; window = { createTextEditorDecorationType: sinon.fake(), @@ -41,7 +42,7 @@ suite('OSS VulnerabilityCountService', () => { registerCodeActionsProvider: sinon.fake(), registerHoverProvider: sinon.fake(), } as unknown as IVSCodeLanguages; - vulnerabilityCountProvider = new ModuleVulnerabilityCountProvider( + vulnerabilityCountProvider = new ModuleVulnerabilityCountProviderLS( ossService, {} as ILanguageClientAdapter, {} as IUriAdapter, @@ -55,7 +56,7 @@ suite('OSS VulnerabilityCountService', () => { const analytics = {} as IAnalytics; const configuration = {} as IConfiguration; - ossVulnerabilityCountService = new OssVulnerabilityCountService( + ossVulnerabilityCountService = new OssVulnerabilityCountServiceLS( workspace, window, languages, @@ -125,7 +126,7 @@ suite('OSS VulnerabilityCountService', () => { }); test("Doesn't process if file is supported and OSS scan hasn't run", () => { - ossService.getResultArray = () => undefined; + vulnerabilityCountProvider.getResultArray = () => undefined; const tsDocument = { fileName: 'C:\\git\\project\\test.ts', languageId: 'typescript', @@ -150,7 +151,7 @@ suite('OSS VulnerabilityCountService', () => { languageId: 'typescript', getText: () => 'const x = require("react")', } as TextDocument; - ossService.getResultArray = () => [{} as OssFileResult]; + vulnerabilityCountProvider.getResultArray = () => [{} as OssFileResult]; sinon.stub(vulnerabilityCountProvider, 'isFilePartOfOssTest').returns(true); const processed = ossVulnerabilityCountService.processFile(document); diff --git a/src/test/unit/snykOss/services/vulnerabilityCount/vulnerabilityCountProvider.test.ts b/src/test/unit/snykOss/services/vulnerabilityCount/vulnerabilityCountProvider.test.ts index fb5eb9ca4..79c933516 100644 --- a/src/test/unit/snykOss/services/vulnerabilityCount/vulnerabilityCountProvider.test.ts +++ b/src/test/unit/snykOss/services/vulnerabilityCount/vulnerabilityCountProvider.test.ts @@ -2,17 +2,17 @@ import { deepStrictEqual, strictEqual } from 'assert'; import sinon from 'sinon'; import { CliError } from '../../../../../snyk/cli/services/cliService'; import { Language } from '../../../../../snyk/common/types'; -import { OssResultBody, OssVulnerability } from '../../../../../snyk/snykOss/ossResult'; -import { OssService } from '../../../../../snyk/snykOss/services/ossService'; -import { ImportedModule } from '../../../../../snyk/snykOss/services/vulnerabilityCount/importedModule'; -import { ModuleVulnerabilityCountProvider } from '../../../../../snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProvider'; import { ILanguageClientAdapter } from '../../../../../snyk/common/vscode/languageClient'; -import { IUriAdapter } from '../../../../../snyk/common/vscode/uri'; import { ITextDocumentAdapter } from '../../../../../snyk/common/vscode/textdocument'; +import { IUriAdapter } from '../../../../../snyk/common/vscode/uri'; +import { OssResultBody, OssVulnerability } from '../../../../../snyk/snykOss/ossResult'; +import { OssServiceLanguageServer } from '../../../../../snyk/snykOss/ossServiceLanguageServer'; +import { ImportedModule } from '../../../../../snyk/snykOss/services/vulnerabilityCount/importedModule'; +import { ModuleVulnerabilityCountProviderLS } from '../../../../../snyk/snykOss/services/vulnerabilityCount/vulnerabilityCountProviderLS'; suite('OSS ModuleVulnerabilityCountProvider', () => { - let ossService: OssService; - let vulnerabilityCountProvider: ModuleVulnerabilityCountProvider; + let ossService: OssServiceLanguageServer; + let vulnerabilityCountProvider: ModuleVulnerabilityCountProviderLS; const sampleFilePath = 'C:\\git\\project\\test.js'; const sampleModuleName = 'mongo-express'; @@ -54,8 +54,8 @@ suite('OSS ModuleVulnerabilityCountProvider', () => { ]; setup(() => { - ossService = {} as OssService; - vulnerabilityCountProvider = new ModuleVulnerabilityCountProvider( + ossService = {} as OssServiceLanguageServer; + vulnerabilityCountProvider = new ModuleVulnerabilityCountProviderLS( ossService, {} as ILanguageClientAdapter, {} as IUriAdapter, @@ -68,7 +68,7 @@ suite('OSS ModuleVulnerabilityCountProvider', () => { }); test('Not calculated if JS/TS results are not provided', async () => { - ossService.getResultArray = () => undefined; + vulnerabilityCountProvider.getResultArray = () => undefined; const tsCount = await vulnerabilityCountProvider.getVulnerabilityCount( 'test.ts', @@ -89,8 +89,8 @@ suite('OSS ModuleVulnerabilityCountProvider', () => { }); test('Gets TS/JS imported module vulnerability results correctly', async () => { - ossService.getResultArray = () => sampleOssResults; - ossService.getUniqueVulnerabilities = () => sampleOssResults[0].vulnerabilities; + vulnerabilityCountProvider.getResultArray = () => sampleOssResults; + vulnerabilityCountProvider.getUniqueVulnerabilities = () => sampleOssResults[0].vulnerabilities; const count = await vulnerabilityCountProvider.getVulnerabilityCount( 'test.ts', @@ -116,8 +116,8 @@ suite('OSS ModuleVulnerabilityCountProvider', () => { }); test('Gets package.json dependency vulnerability results correctly', async () => { - ossService.getResultArray = () => sampleOssResults; - ossService.getUniqueVulnerabilities = () => sampleOssResults[0].vulnerabilities; + vulnerabilityCountProvider.getResultArray = () => sampleOssResults; + vulnerabilityCountProvider.getUniqueVulnerabilities = () => sampleOssResults[0].vulnerabilities; const count = await vulnerabilityCountProvider.getVulnerabilityCount( 'test.ts', @@ -145,8 +145,8 @@ suite('OSS ModuleVulnerabilityCountProvider', () => { ], }, ]; - ossService.getResultArray = () => ossResultsWithIndirectVulnerability; - ossService.getUniqueVulnerabilities = () => ossResultsWithIndirectVulnerability[0].vulnerabilities; + vulnerabilityCountProvider.getResultArray = () => ossResultsWithIndirectVulnerability; + vulnerabilityCountProvider.getUniqueVulnerabilities = () => ossResultsWithIndirectVulnerability[0].vulnerabilities; const count = await vulnerabilityCountProvider.getVulnerabilityCount( 'test.ts', @@ -177,8 +177,9 @@ suite('OSS ModuleVulnerabilityCountProvider', () => { ], }, ]; - ossService.getResultArray = () => ossResultsWithMultipleVersionsVulnerability; - ossService.getUniqueVulnerabilities = () => ossResultsWithMultipleVersionsVulnerability[0].vulnerabilities; + vulnerabilityCountProvider.getResultArray = () => ossResultsWithMultipleVersionsVulnerability; + vulnerabilityCountProvider.getUniqueVulnerabilities = () => + ossResultsWithMultipleVersionsVulnerability[0].vulnerabilities; const count = await vulnerabilityCountProvider.getVulnerabilityCount( 'test.ts', @@ -207,8 +208,9 @@ suite('OSS ModuleVulnerabilityCountProvider', () => { ], }, ]; - ossService.getResultArray = () => ossResultsWithMultipleVersionsVulnerability; - ossService.getUniqueVulnerabilities = () => ossResultsWithMultipleVersionsVulnerability[0].vulnerabilities; + vulnerabilityCountProvider.getResultArray = () => ossResultsWithMultipleVersionsVulnerability; + vulnerabilityCountProvider.getUniqueVulnerabilities = () => + ossResultsWithMultipleVersionsVulnerability[0].vulnerabilities; const count = await vulnerabilityCountProvider.getVulnerabilityCount( 'test.ts',