Skip to content

Commit

Permalink
feat: improve snyk source test display
Browse files Browse the repository at this point in the history
Add color and improve how test results are displayed when running 'snyk
source test' for C/C++ projects.
Add spinner test to give more feedback to user as we test dependencies.
Remove type from ScanResult interface.
  • Loading branch information
gitphill committed Sep 8, 2020
1 parent bcd6484 commit 3796530
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -76,7 +76,7 @@
"proxy-from-env": "^1.0.0",
"semver": "^6.0.0",
"snyk-config": "3.1.0",
"snyk-cpp-plugin": "1.4.1",
"snyk-cpp-plugin": "1.4.3",
"snyk-docker-plugin": "3.19.0",
"snyk-go-plugin": "1.16.0",
"snyk-gradle-plugin": "3.6.2",
Expand Down
46 changes: 23 additions & 23 deletions src/lib/ecosystems.ts
Expand Up @@ -6,44 +6,44 @@ import { isCI } from './is-ci';
import { makeRequest } from './request/promise';
import { Options } from './types';
import { TestCommandResult } from '../cli/commands/types';
import * as spinner from '../lib/spinner';

export interface Artifact {
type: string;
data: any;
meta: { [key: string]: any };
}

export interface ScanResult {
type: string;
artifacts: Artifact[];
meta: {
[key: string]: any;
};
}

export interface TestResult {
depGraph: DepGraphData;
affectedPkgs: {
[pkgId: string]: {
pkg: {
name: string;
version: string;
};
issues: {
[issueId: string]: {
issueId: string;
};
};
};
export interface Issue {
pkgName: string;
pkgVersion?: string;
issueId: string;
fixInfo: {
nearestFixedInVersion?: string;
};
issuesData: {
[issueId: string]: {
id: string;
severity: string;
title: string;
};
}

export interface IssuesData {
[issueId: string]: {
id: string;
severity: string;
title: string;
};
}

export interface TestResult {
issues: Issue[];
issuesData: IssuesData;
depGraphData: DepGraphData;
}

export interface EcosystemPlugin {
scan: (options: Options) => Promise<ScanResult[]>;
display: (
Expand Down Expand Up @@ -84,7 +84,6 @@ export async function testEcosystem(
const results = await plugin.scan(options);
scanResultsByPath[path] = results;
}

const [testResults, errors] = await testDependencies(scanResultsByPath);
const stringifiedData = JSON.stringify(testResults, null, 2);
if (options.json) {
Expand All @@ -106,6 +105,7 @@ export async function testDependencies(scans: {
const results: TestResult[] = [];
const errors: string[] = [];
for (const [path, scanResults] of Object.entries(scans)) {
await spinner(`Testing dependencies in ${path}`);
for (const scanResult of scanResults) {
const payload = {
method: 'POST',
Expand All @@ -116,7 +116,6 @@ export async function testDependencies(scans: {
authorization: 'token ' + snyk.api,
},
body: {
type: scanResult.type,
artifacts: scanResult.artifacts,
meta: {},
},
Expand All @@ -132,5 +131,6 @@ export async function testDependencies(scans: {
}
}
}
spinner.clearAll();
return [results, errors];
}
16 changes: 8 additions & 8 deletions test/fixtures/cpp-project/display.txt
@@ -1,15 +1,15 @@
Dependency Fingerprints
-----------------------
Fingerprints
52d1b046047db9ea0c581cafd4c68fe5 add.cpp
aeca71a6e39f99a24ecf4c088eee9cb8 add.h
ad3365b3370ef6b1c3e778f875055f19 main.cpp

Dependencies
------------
Dependencies
add@1.2.3

Issues
------
Tested 1 dependency for known issues, found 1 issue.
Issues
✗ Cross-site Scripting (XSS) [medium]
https://snyk.io/vuln/cpp:add:20161130
in add@1.2.3
fix version 1.2.4

✗ Cross-site Scripting (XSS) [medium severity][https://snyk.io/vuln/cpp:add:20161130] in add@1.2.3
Tested 1 dependency for known issues, found 1 issue.
7 changes: 2 additions & 5 deletions test/fixtures/cpp-project/error.txt
@@ -1,10 +1,7 @@
Dependency Fingerprints
-----------------------
Fingerprints
52d1b046047db9ea0c581cafd4c68fe5 add.cpp
aeca71a6e39f99a24ecf4c088eee9cb8 add.h
ad3365b3370ef6b1c3e778f875055f19 main.cpp


Errors
------
Errors
Could not test dependencies in .
21 changes: 8 additions & 13 deletions test/fixtures/cpp-project/testResults.json
@@ -1,25 +1,20 @@
{
"affectedPkgs": {
"add@1.2.3": {
"pkg": {
"name": "add",
"version": "1.2.3"
},
"issues": {
"cpp:add:20161130": {
"issueId": "cpp:add:20161130"
}
}
"issues": [{
"pkgName": "add",
"pkgVersion": "1.2.3",
"issueId": "cpp:add:20161130",
"fixInfo": {
"nearestFixedInVersion": "1.2.4"
}
},
}],
"issuesData": {
"cpp:add:20161130": {
"id": "cpp:add:20161130",
"severity": "medium",
"title": "Cross-site Scripting (XSS)"
}
},
"depGraph": {
"depGraphData": {
"schemaVersion": "1.2.0",
"pkgManager": {
"name": "cpp"
Expand Down

0 comments on commit 3796530

Please sign in to comment.