-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from snyk/feat/add-reachable-vulnerabilities
feat: support reachable vulns for gradle
- Loading branch information
Showing
5 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"options": { | ||
"directed": true, | ||
"multigraph": false, | ||
"compound": false | ||
}, | ||
"nodes": [ | ||
{ | ||
"v": "com.ibm.wala.FakeRootClass:fakeRootMethod", | ||
"value": { | ||
"className": "com.ibm.wala.FakeRootClass", | ||
"functionName": "fakeRootMethod" | ||
} | ||
}, | ||
{ | ||
"v": "ch.qos.logback.classic.net.SocketNode:run", | ||
"value": { | ||
"className": "ch.qos.logback.classic.net.SocketNode", | ||
"functionName": "run" | ||
} | ||
} | ||
], | ||
"edges": [ | ||
{ | ||
"v": "com.ibm.wala.FakeRootClass:fakeRootMethod", | ||
"w": "com.ibm.wala.FakeRootClass:fakeWorldClinit" | ||
}, | ||
{ | ||
"v": "ch.qos.logback.classic.net.SocketNode", | ||
"w": "com.ibm.wala.FakeRootClass:fakeWorldClinit" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
*/ | ||
|
||
plugins { | ||
id 'java' | ||
id 'maven-publish' | ||
id 'application' | ||
} | ||
|
||
apply plugin : "java" | ||
ext { | ||
javaMainClass = "Unzipper" | ||
} | ||
|
||
application { | ||
mainClassName = javaMainClass | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
maven { | ||
url = uri('https://repo.maven.apache.org/maven2') | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'commons-collections:commons-collections:3.2.1' | ||
implementation 'org.nd4j:nd4j-common:1.0.0-beta2' | ||
} | ||
|
||
group = 'org.example' | ||
version = '1.0-SNAPSHOT' | ||
sourceCompatibility = '1.8' | ||
|
||
publishing { | ||
publications { | ||
maven(MavenPublication) { | ||
from(components.java) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ import { fixtureDir } from '../common'; | |
import { test } from 'tap'; | ||
import { inspect } from '../../lib'; | ||
import * as subProcess from '../../lib/sub-process'; | ||
import * as fs from 'fs'; | ||
import * as sinon from 'sinon'; | ||
import * as javaCallGraphBuilder from '@snyk/java-call-graph-builder'; | ||
import { CallGraph } from '@snyk/cli-interface/legacy/common'; | ||
|
||
const rootNoWrapper = fixtureDir('no wrapper'); | ||
const GRADLE_VERSION = process.env.GRADLE_VERSION; | ||
|
@@ -21,6 +25,40 @@ test('run inspect()', async (t) => { | |
); | ||
}); | ||
|
||
test('run inspect() with reachableVulns', async (t) => { | ||
const gradleCallGraph = JSON.parse( | ||
fs.readFileSync( | ||
path.join(fixtureDir('call-graphs'), 'simple.json'), | ||
'utf-8', | ||
), | ||
); | ||
const javaCallGraphBuilderStub = sinon | ||
.stub(javaCallGraphBuilder, 'getCallGraphGradle') | ||
.resolves(gradleCallGraph as CallGraph); | ||
const result = await inspect('.', path.join(rootNoWrapper, 'build.gradle'), { | ||
reachableVulns: true, | ||
}); | ||
const pkgs = result.dependencyGraph.getDepPkgs(); | ||
const nodeIds: string[] = []; | ||
Object.keys(pkgs).forEach((id) => { | ||
nodeIds.push(`${pkgs[id].name}@${pkgs[id].version}`); | ||
}); | ||
|
||
t.ok( | ||
nodeIds.indexOf('com.android.tools:[email protected]') !== -1, | ||
'correct version found', | ||
); | ||
t.ok(javaCallGraphBuilderStub.calledOnce, 'called to the call graph builder'); | ||
t.ok( | ||
javaCallGraphBuilderStub.calledWith(path.join('.', rootNoWrapper)), | ||
'call graph builder was called with the correct path', | ||
); | ||
t.same(gradleCallGraph, result.callGraph, 'returns expected callgraph'); | ||
t.teardown(() => { | ||
javaCallGraphBuilderStub.restore(); | ||
}); | ||
}); | ||
|
||
test('multi-config: both compile and runtime deps picked up by default', async (t) => { | ||
const result = await inspect( | ||
'.', | ||
|