Skip to content

Commit 2907db7

Browse files
authored
Merge pull request #1390 from snyk/feat/improve-source-test-display
feat: improve snyk source test display
2 parents dae8ade + 3796530 commit 2907db7

File tree

5 files changed

+42
-50
lines changed

5 files changed

+42
-50
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"proxy-from-env": "^1.0.0",
7777
"semver": "^6.0.0",
7878
"snyk-config": "3.1.0",
79-
"snyk-cpp-plugin": "1.4.1",
79+
"snyk-cpp-plugin": "1.4.3",
8080
"snyk-docker-plugin": "3.19.0",
8181
"snyk-go-plugin": "1.16.0",
8282
"snyk-gradle-plugin": "3.6.2",

src/lib/ecosystems.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,44 @@ import { isCI } from './is-ci';
66
import { makeRequest } from './request/promise';
77
import { Options } from './types';
88
import { TestCommandResult } from '../cli/commands/types';
9+
import * as spinner from '../lib/spinner';
10+
911
export interface Artifact {
1012
type: string;
1113
data: any;
1214
meta: { [key: string]: any };
1315
}
1416

1517
export interface ScanResult {
16-
type: string;
1718
artifacts: Artifact[];
1819
meta: {
1920
[key: string]: any;
2021
};
2122
}
2223

23-
export interface TestResult {
24-
depGraph: DepGraphData;
25-
affectedPkgs: {
26-
[pkgId: string]: {
27-
pkg: {
28-
name: string;
29-
version: string;
30-
};
31-
issues: {
32-
[issueId: string]: {
33-
issueId: string;
34-
};
35-
};
36-
};
24+
export interface Issue {
25+
pkgName: string;
26+
pkgVersion?: string;
27+
issueId: string;
28+
fixInfo: {
29+
nearestFixedInVersion?: string;
3730
};
38-
issuesData: {
39-
[issueId: string]: {
40-
id: string;
41-
severity: string;
42-
title: string;
43-
};
31+
}
32+
33+
export interface IssuesData {
34+
[issueId: string]: {
35+
id: string;
36+
severity: string;
37+
title: string;
4438
};
4539
}
4640

41+
export interface TestResult {
42+
issues: Issue[];
43+
issuesData: IssuesData;
44+
depGraphData: DepGraphData;
45+
}
46+
4747
export interface EcosystemPlugin {
4848
scan: (options: Options) => Promise<ScanResult[]>;
4949
display: (
@@ -84,7 +84,6 @@ export async function testEcosystem(
8484
const results = await plugin.scan(options);
8585
scanResultsByPath[path] = results;
8686
}
87-
8887
const [testResults, errors] = await testDependencies(scanResultsByPath);
8988
const stringifiedData = JSON.stringify(testResults, null, 2);
9089
if (options.json) {
@@ -106,6 +105,7 @@ export async function testDependencies(scans: {
106105
const results: TestResult[] = [];
107106
const errors: string[] = [];
108107
for (const [path, scanResults] of Object.entries(scans)) {
108+
await spinner(`Testing dependencies in ${path}`);
109109
for (const scanResult of scanResults) {
110110
const payload = {
111111
method: 'POST',
@@ -116,7 +116,6 @@ export async function testDependencies(scans: {
116116
authorization: 'token ' + snyk.api,
117117
},
118118
body: {
119-
type: scanResult.type,
120119
artifacts: scanResult.artifacts,
121120
meta: {},
122121
},
@@ -132,5 +131,6 @@ export async function testDependencies(scans: {
132131
}
133132
}
134133
}
134+
spinner.clearAll();
135135
return [results, errors];
136136
}

test/fixtures/cpp-project/display.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
Dependency Fingerprints
2-
-----------------------
1+
Fingerprints
32
52d1b046047db9ea0c581cafd4c68fe5 add.cpp
43
aeca71a6e39f99a24ecf4c088eee9cb8 add.h
54
ad3365b3370ef6b1c3e778f875055f19 main.cpp
65

7-
Dependencies
8-
------------
6+
Dependencies
97
108

11-
Issues
12-
------
13-
Tested 1 dependency for known issues, found 1 issue.
9+
Issues
10+
✗ Cross-site Scripting (XSS) [medium]
11+
https://snyk.io/vuln/cpp:add:20161130
12+
13+
fix version 1.2.4
1414

15-
✗ Cross-site Scripting (XSS) [medium severity][https://snyk.io/vuln/cpp:add:20161130] in [email protected]
15+
Tested 1 dependency for known issues, found 1 issue.

test/fixtures/cpp-project/error.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
Dependency Fingerprints
2-
-----------------------
1+
Fingerprints
32
52d1b046047db9ea0c581cafd4c68fe5 add.cpp
43
aeca71a6e39f99a24ecf4c088eee9cb8 add.h
54
ad3365b3370ef6b1c3e778f875055f19 main.cpp
65

7-
8-
Errors
9-
------
6+
Errors
107
Could not test dependencies in .

test/fixtures/cpp-project/testResults.json

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
{
2-
"affectedPkgs": {
3-
4-
"pkg": {
5-
"name": "add",
6-
"version": "1.2.3"
7-
},
8-
"issues": {
9-
"cpp:add:20161130": {
10-
"issueId": "cpp:add:20161130"
11-
}
12-
}
2+
"issues": [{
3+
"pkgName": "add",
4+
"pkgVersion": "1.2.3",
5+
"issueId": "cpp:add:20161130",
6+
"fixInfo": {
7+
"nearestFixedInVersion": "1.2.4"
138
}
14-
},
9+
}],
1510
"issuesData": {
1611
"cpp:add:20161130": {
1712
"id": "cpp:add:20161130",
1813
"severity": "medium",
1914
"title": "Cross-site Scripting (XSS)"
2015
}
2116
},
22-
"depGraph": {
17+
"depGraphData": {
2318
"schemaVersion": "1.2.0",
2419
"pkgManager": {
2520
"name": "cpp"

0 commit comments

Comments
 (0)