From 83b4f6ae240750ddad824c8d9427db8601b4cd4d Mon Sep 17 00:00:00 2001 From: David Agrest Date: Sun, 19 Jun 2022 12:50:22 +0300 Subject: [PATCH] feat: support for unmanaged snyk-to-html --- src/lib/ecosystems/resolve-test-facts.ts | 23 +++++++++++++++++++ src/lib/package-managers.ts | 4 +++- src/lib/polling/polling-test.ts | 8 +++++++ src/lib/snyk-test/legacy.ts | 8 ++++++- .../lib/ecosystems/resolve-test-facts.spec.ts | 8 +++++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/lib/ecosystems/resolve-test-facts.ts b/src/lib/ecosystems/resolve-test-facts.ts index 0a13633725..c4b4610d9c 100644 --- a/src/lib/ecosystems/resolve-test-facts.ts +++ b/src/lib/ecosystems/resolve-test-facts.ts @@ -8,6 +8,7 @@ import { import { extractAndApplyPluginAnalytics } from './plugin-analytics'; import { findAndLoadPolicy } from '../policy'; import { filterIgnoredIssues } from './policy'; +import { IssueData, Issue } from '../snyk-test/legacy'; export async function resolveAndTestFacts( ecosystem: Ecosystem, @@ -18,6 +19,7 @@ export async function resolveAndTestFacts( ): Promise<[TestResult[], string[]]> { const results: any[] = []; const errors: string[] = []; + const packageManager = 'Unmanaged (C/C++)'; for (const [path, scanResults] of Object.entries(scans)) { await spinner(`Resolving and Testing fileSignatures in ${path}`); @@ -45,12 +47,33 @@ export async function resolveAndTestFacts( policy, ); + const issuesMap: Map = new Map(); + response.issues.forEach((i) => { + issuesMap[i.issueId] = i; + }); + + const vulnerabilities: IssueData[] = []; + for (const issuesDataKey in response.issuesData) { + const issueData = response.issuesData[issuesDataKey]; + const pkgCoordinate = `${issuesMap[issuesDataKey].pkgName}@${issuesMap[issuesDataKey].pkgVersion}`; + issueData.from = [pkgCoordinate]; + issueData.name = pkgCoordinate; + issueData.packageManager = packageManager; + vulnerabilities.push(issueData); + } + + const dependencyCount = response.issues.length; + results.push({ issues, issuesData, depGraphData: response?.depGraphData, depsFilePaths: response?.depsFilePaths, fileSignaturesDetails: response?.fileSignaturesDetails, + vulnerabilities, + path, + dependencyCount, + packageManager, }); } catch (error) { const hasStatusCodeError = error.code >= 400 && error.code <= 500; diff --git a/src/lib/package-managers.ts b/src/lib/package-managers.ts index 65e36b7575..69cd2cf0f3 100644 --- a/src/lib/package-managers.ts +++ b/src/lib/package-managers.ts @@ -14,7 +14,8 @@ export type SupportedPackageManagers = | 'composer' | 'cocoapods' | 'poetry' - | 'hex'; + | 'hex' + | 'Unmanaged (C/C++)'; export enum SUPPORTED_MANIFEST_FILES { GEMFILE = 'Gemfile', @@ -67,6 +68,7 @@ export const SUPPORTED_PACKAGE_MANAGER_NAME: { cocoapods: 'CocoaPods', poetry: 'Poetry', hex: 'Hex', + 'Unmanaged (C/C++)': 'Unmanaged (C/C++)', }; export const GRAPH_SUPPORTED_PACKAGE_MANAGERS: SupportedPackageManagers[] = [ diff --git a/src/lib/polling/polling-test.ts b/src/lib/polling/polling-test.ts index be592971a2..cd7efe4db6 100644 --- a/src/lib/polling/polling-test.ts +++ b/src/lib/polling/polling-test.ts @@ -63,6 +63,10 @@ export async function pollingTestWithTokenUntilDone( depGraphData, depsFilePaths, fileSignaturesDetails, + vulnerabilities, + path, + dependencyCount, + packageManager, } = response.result; return { issues, @@ -70,6 +74,10 @@ export async function pollingTestWithTokenUntilDone( depGraphData, depsFilePaths, fileSignaturesDetails, + vulnerabilities, + path, + dependencyCount, + packageManager, }; } diff --git a/src/lib/snyk-test/legacy.ts b/src/lib/snyk-test/legacy.ts index ce1e439b0d..41914274b6 100644 --- a/src/lib/snyk-test/legacy.ts +++ b/src/lib/snyk-test/legacy.ts @@ -92,6 +92,8 @@ export interface IssueData { legalInstructions?: string; reachability?: REACHABILITY; packageManager?: SupportedProjectTypes; + from?: string[]; + name?: string; } export type CallPath = string[]; @@ -235,7 +237,7 @@ interface TestDepGraphResult { remediation?: RemediationChanges; } -interface Issue { +export interface Issue { pkgName: string; pkgVersion?: string; issueId: string; @@ -256,6 +258,10 @@ export interface TestDependenciesResult { depsFilePaths?: DepsFilePaths; depGraphData: depGraphLib.DepGraphData; fileSignaturesDetails: FileSignaturesDetails; + vulnerabilities: IssueData[]; + path: string; + dependencyCount: number; + packageManager: SupportedProjectTypes; } export interface TestDepGraphMeta { diff --git a/test/jest/unit/lib/ecosystems/resolve-test-facts.spec.ts b/test/jest/unit/lib/ecosystems/resolve-test-facts.spec.ts index 14ff84859a..d66e2c72ac 100644 --- a/test/jest/unit/lib/ecosystems/resolve-test-facts.spec.ts +++ b/test/jest/unit/lib/ecosystems/resolve-test-facts.spec.ts @@ -108,6 +108,10 @@ describe('resolve and test facts', () => { issues: [], depGraphData, fileSignaturesDetails: {}, + vulnerabilities: [], + path: 'path', + dependencyCount: 0, + packageManager: 'Unmanaged (C/C++)', }); const extractAndApplyPluginAnalyticsSpy = jest.spyOn( @@ -138,6 +142,10 @@ describe('resolve and test facts', () => { issues: [], depGraphData, fileSignaturesDetails: {}, + vulnerabilities: [], + path: 'path', + dependencyCount: 0, + packageManager: 'Unmanaged (C/C++)', }, ]); expect(errors).toEqual([]);