-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter fixable #94
Open
caroalmirola
wants to merge
3
commits into
snyk:main
Choose a base branch
from
caroalmirola:filter-fixable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Filter fixable #94
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,6 @@ buildNumber.properties | |
**/out/ | ||
**/.idea_modules/ | ||
*.iml | ||
|
||
|
||
src/it/.DS_Store |
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,47 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.snyk.example</groupId> | ||
<artifactId>non-fixable-issues-module</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>non fixable issues module</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>commons-httpclient</groupId> | ||
<artifactId>commons-httpclient</artifactId> | ||
<version>2.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.snyk</groupId> | ||
<artifactId>snyk-maven-plugin</artifactId> | ||
<version>${snyk.maven.plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>test</phase> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<apiToken>${env.SNYK_API_TOKEN}</apiToken> | ||
<endpoint>${env.SNYK_API_ENDPOINT}</endpoint> | ||
<failOnSeverity>low</failOnSeverity> | ||
<onlyFailFixable>true</onlyFailFixable> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,14 @@ | ||
/* | ||
* verifying that the non-fixable-issues-module integration test runs as expected | ||
*/ | ||
|
||
import java.io.*; | ||
import org.codehaus.plexus.util.*; | ||
|
||
String log = FileUtils.fileRead( new File( basedir, "build.log" ) ); | ||
|
||
if(!log.contains("/SNYK-JAVA-COMMONSHTTPCLIENT-31660")) { | ||
throw new Exception("Missing Vulnerability 'SNYK-JAVA-COMMONSHTTPCLIENT-31660' "); | ||
} | ||
|
||
return true; |
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 |
---|---|---|
|
@@ -79,6 +79,9 @@ public class SnykTest extends AbstractMojo { | |
@Parameter | ||
private boolean failOnAuthError = false; | ||
|
||
@Parameter | ||
private boolean onlyFailFixable = false; | ||
|
||
@Parameter(property = "snyk.skip") | ||
private boolean skip; | ||
|
||
|
@@ -262,15 +265,17 @@ private void processVulns(JSONObject responseJson) throws MojoFailureException { | |
HashSet<String> vulnIdSet = new HashSet<String>(); | ||
|
||
JSONArray vulns = (JSONArray)responseJson.get("vulnerabilities"); | ||
int highestSeverity = SEVERITY_LOW; | ||
int highestSeverity = Integer.MIN_VALUE; | ||
|
||
Iterator<JSONObject> iterator = vulns.iterator(); | ||
while (iterator.hasNext()) { | ||
JSONObject vuln = iterator.next(); | ||
vulnIdSet.add((String)vuln.get("id")); | ||
Integer severityInt = severityMap.get(vuln.get("severity")); | ||
if(severityInt != null && severityInt > highestSeverity) { | ||
highestSeverity = severityInt; | ||
if (!onlyFailFixable || (onlyFailFixable && isIssueFixable(vuln))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This statement can be simplified. Atm second |
||
if (severityInt != null && severityInt > highestSeverity) { | ||
highestSeverity = severityInt; | ||
} | ||
} | ||
printVuln(vuln); | ||
} | ||
|
@@ -292,6 +297,17 @@ private void processVulns(JSONObject responseJson) throws MojoFailureException { | |
} | ||
} | ||
|
||
private boolean isIssueFixable(JSONObject vuln) { | ||
boolean upgradable = | ||
(vuln.get("isUpgradable") != null && (boolean) vuln.get("isUpgradable")); | ||
boolean fixable = false; | ||
if (vuln.get("fixedIn") != null) { | ||
JSONArray fixedIn = (JSONArray) vuln.get("fixedIn"); | ||
fixable = (!fixedIn.isEmpty()); | ||
} | ||
return upgradable || fixable; | ||
} | ||
|
||
Comment on lines
+300
to
+310
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An issue is fixable if it can be eliminated with an upgrade ("isUpgradable") or patch ("isPatchable"). |
||
/** | ||
* print a single vuln to the build log | ||
* @param vuln a JSON object containing a single vuln | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caroalmirola, let's keep parameter naming consistent (failOnSeverity, failOnAuthError).
How about
failOnFixableOnly
.