Skip to content

Commit

Permalink
Merge pull request #3329 from snyk/feat/support-for-unmanaged-snyk-to…
Browse files Browse the repository at this point in the history
…-html

feat: support for unmanaged snyk-to-html
  • Loading branch information
David Agrest authored Jun 21, 2022
2 parents ea3eb80 + 83b4f6a commit 0804baa
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/lib/ecosystems/resolve-test-facts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}`);
Expand Down Expand Up @@ -45,12 +47,33 @@ export async function resolveAndTestFacts(
policy,
);

const issuesMap: Map<string, Issue> = 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;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/package-managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export type SupportedPackageManagers =
| 'composer'
| 'cocoapods'
| 'poetry'
| 'hex';
| 'hex'
| 'Unmanaged (C/C++)';

export enum SUPPORTED_MANIFEST_FILES {
GEMFILE = 'Gemfile',
Expand Down Expand Up @@ -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[] = [
Expand Down
8 changes: 8 additions & 0 deletions src/lib/polling/polling-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ export async function pollingTestWithTokenUntilDone(
depGraphData,
depsFilePaths,
fileSignaturesDetails,
vulnerabilities,
path,
dependencyCount,
packageManager,
} = response.result;
return {
issues,
issuesData,
depGraphData,
depsFilePaths,
fileSignaturesDetails,
vulnerabilities,
path,
dependencyCount,
packageManager,
};
}

Expand Down
8 changes: 7 additions & 1 deletion src/lib/snyk-test/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export interface IssueData {
legalInstructions?: string;
reachability?: REACHABILITY;
packageManager?: SupportedProjectTypes;
from?: string[];
name?: string;
}

export type CallPath = string[];
Expand Down Expand Up @@ -235,7 +237,7 @@ interface TestDepGraphResult {
remediation?: RemediationChanges;
}

interface Issue {
export interface Issue {
pkgName: string;
pkgVersion?: string;
issueId: string;
Expand All @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions test/jest/unit/lib/ecosystems/resolve-test-facts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -138,6 +142,10 @@ describe('resolve and test facts', () => {
issues: [],
depGraphData,
fileSignaturesDetails: {},
vulnerabilities: [],
path: 'path',
dependencyCount: 0,
packageManager: 'Unmanaged (C/C++)',
},
]);
expect(errors).toEqual([]);
Expand Down

0 comments on commit 0804baa

Please sign in to comment.