Skip to content
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

Add YoctoScannerParser #1084

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package edu.hm.hafner.analysis.parser;

import org.json.JSONArray;
import org.json.JSONObject;

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;

import static j2html.TagCreator.*;

/**
* Parser for Yocto Scanner CLI (scannercli) tool.
*
* @author Juri Duval
*/
public class YoctoScannerParser extends JsonIssueParser {
private static final String VALUE_NOT_SET = "-";
private static final long serialVersionUID = 1L;
private static final Double INVALID_SCORE = -1.0;

@Override
protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) {
JSONArray packages = jsonReport.optJSONArray("package");
if (packages != null) {
parseResources(report, packages, issueBuilder);
}
}

private void parseResources(final Report report, final JSONArray packages, final IssueBuilder issueBuilder) {
for (int i = 0; i < packages.length(); i++) {
final Object item = packages.get(i);
if (item instanceof JSONObject) {

Check warning on line 34 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 34 is only partially covered, one branch is missing
final JSONObject resourceWrapper = (JSONObject) item;
if (!resourceWrapper.isNull("issue")) {

Check warning on line 36 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 36 is only partially covered, one branch is missing
parseVulnerabilities(report, issueBuilder, resourceWrapper);
}
}
}
}

private void parseVulnerabilities(final Report report, final IssueBuilder issueBuilder,
final JSONObject resourceWrapper) {
final JSONArray vulnerabilities = resourceWrapper.getJSONArray("issue");
for (Object vulnerability : vulnerabilities) {
if (vulnerability instanceof JSONObject) {

Check warning on line 47 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 47 is only partially covered, one branch is missing
final JSONObject obj = (JSONObject) vulnerability;
final String status = obj.getString("status");
if (status.equals("Unpatched")) {

Check warning on line 50 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Java Compiler

checkstyle:check

NORMAL: (coding) EqualsAvoidNull: String literal expressions should be on the left side of an equals comparison.

Check warning on line 50 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / CheckStyle

EqualsAvoidNullCheck

NORMAL: String literal expressions should be on the left side of an equals comparison.
Raw output
<p>Since Checkstyle 5.0</p><p> Checks that any combination of String literals is on the left side of an equals() comparison. Also checks for String literals assigned to some field (such as <code>someString.equals(anotherString = "text")</code>). </p><p> Rationale: Calling the <code>equals()</code> method on String literals will avoid a potential NullPointerException. Also, it is pretty common to see null checks right before equals comparisons, which is not necessary in the example below. </p><p> For example, this code: </p><pre><code> String nullString = null; nullString.equals("My_Sweet_String"); </code></pre><p>should be refactored to:</p><pre><code> String nullString = null; "My_Sweet_String".equals(nullString); </code></pre>
report.add(convertToIssue(resourceWrapper, obj, issueBuilder));
}
}
}
}

private Issue convertToIssue(final JSONObject resource, final JSONObject vulnerability,
final IssueBuilder issueBuilder) {
final String packageName = resource.getString("name");
return issueBuilder
.setPackageName(packageName)
.setSeverity(mapSeverity(vulnerability))
.setMessage(vulnerability.optString("id", "UNKNOWN"))
.setDescription(formatDescription(packageName, resource, vulnerability))
.buildAndClean();
}

private Severity mapSeverity(final JSONObject vulnerability) {

Check warning on line 68 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / PMD

CyclomaticComplexity

NORMAL: The method 'mapSeverity(JSONObject)' has a cyclomatic complexity of 12.
Raw output
The complexity of methods directly affects maintenance costs and readability. Concentrating too much decisional logic in a single method makes its behaviour hard to read and change. Cyclomatic complexity assesses the complexity of a method by counting the number of decision points in a method, plus one for the method entry. Decision points are places where the control flow jumps to another place in the program. As such, they include all control flow statements, such as `if`, `while`, `for`, and `case`. For more details on the calculation, see the documentation {% jdoc java::lang.java.metrics.JavaMetrics#CYCLO %}. Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote high complexity, and 11+ is very high complexity. By default, this rule reports methods with a complexity >= 10. Additionally, classes with many methods of moderate complexity get reported as well once the total of their methods' complexities reaches 80, even if none of the methods was directly reported. Reported methods should be broken down into several smaller methods. Reported classes should probably be broken down into subcomponents. <pre> <code> class Foo { void baseCyclo() { // Cyclo = 1 highCyclo(); } void highCyclo() { // Cyclo = 10: reported! int x = 0, y = 2; boolean a = false, b = true; if (a &amp;&amp; (y == 1 ? b : true)) { // +3 if (y == x) { // +1 while (true) { // +1 if (x++ &lt; 20) { // +1 break; // +1 } } } else if (y == t &amp;&amp; !d) { // +2 x = a ? y : x; // +1 } else { x = 2; } } } } </code> </pre> <a href="https://docs.pmd-code.org/pmd-doc-7.3.0/pmd_rules_java_design.html#cyclomaticcomplexity"> See PMD documentation. </a>

Check warning on line 68 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / PMD

NPathComplexity

NORMAL: The method 'mapSeverity(JSONObject)' has an NPath complexity of 864, current threshold is 200.
Raw output
The NPath complexity of a method is the number of acyclic execution paths through that method. While cyclomatic complexity counts the number of decision points in a method, NPath counts the number of full paths from the beginning to the end of the block of the method. That metric grows exponentially, as it multiplies the complexity of statements in the same block. For more details on the calculation, see the documentation {% jdoc java::lang.java.metrics.JavaMetrics#NPATH %}. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity and increase readability. <pre> <code> public class Foo { public static void bar() { // Ncss = 252: reported! boolean a, b = true; try { // 2 * 2 + 2 = 6 if (true) { // 2 List buz = new ArrayList(); } for(int i = 0; i &lt; 19; i++) { // * 2 List buz = new ArrayList(); } } catch(Exception e) { if (true) { // 2 e.printStackTrace(); } } while (j++ &lt; 20) { // * 2 List buz = new ArrayList(); } switch(j) { // * 7 case 1: case 2: break; case 3: j = 5; break; case 4: if (b &amp;&amp; a) { bar(); } break; default: break; } do { // * 3 List buz = new ArrayList(); } while (a &amp;&amp; j++ &lt; 30); } } </code> </pre> <a href="https://docs.pmd-code.org/pmd-doc-7.3.0/pmd_rules_java_design.html#npathcomplexity"> See PMD documentation. </a>
Double score_v2 = INVALID_SCORE;

Check warning on line 69 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Java Compiler

checkstyle:check

NORMAL: (naming) LocalVariableName: Name 'score_v2' must match pattern '^[a-z][a-zA-Z0-9]*$'.

Check warning on line 69 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / CheckStyle

LocalVariableNameCheck

NORMAL: Name 'score_v2' must match pattern '^[a-z][a-zA-Z0-9]*$'.
Raw output
<p> Checks that local, non-<code>final</code> variable names conform to a format specified by the format property. A catch parameter is considered to be a local variable. </p>
Double score_v3 = INVALID_SCORE;

Check warning on line 70 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Java Compiler

checkstyle:check

NORMAL: (naming) LocalVariableName: Name 'score_v3' must match pattern '^[a-z][a-zA-Z0-9]*$'.

Check warning on line 70 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / CheckStyle

LocalVariableNameCheck

NORMAL: Name 'score_v3' must match pattern '^[a-z][a-zA-Z0-9]*$'.
Raw output
<p> Checks that local, non-<code>final</code> variable names conform to a format specified by the format property. A catch parameter is considered to be a local variable. </p>
Double score = INVALID_SCORE;

if (vulnerability.has("scorev2")) {

Check warning on line 73 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 73 is only partially covered, one branch is missing
score_v2 = vulnerability.getDouble("scorev2");
}

if (vulnerability.has("scorev3")) {

Check warning on line 77 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 77 is only partially covered, one branch is missing
score_v3 = vulnerability.getDouble("scorev3");
}

if (score_v3 == 0.0) {

Check warning on line 81 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / PMD

AvoidLiteralsInIfCondition

NORMAL: Avoid using literals in if statements.
Raw output
Avoid using hard-coded literals in conditional statements. By declaring them as static variables or private members with descriptive names maintainability is enhanced. By default, the literals "-1" and "0" are ignored. More exceptions can be defined with the property "ignoreMagicNumbers". The rule doesn't consider deeper expressions by default, but this can be enabled via the property `ignoreExpressions`. With this property set to false, if-conditions like `i == 1 + 5` are reported as well. Note that in that case, the property ignoreMagicNumbers is not taken into account, if there are multiple literals involved in such an expression. <pre> <code> private static final int MAX_NUMBER_OF_REQUESTS = 10; public void checkRequests() { if (i == 10) { // magic number, buried in a method doSomething(); } if (i == MAX_NUMBER_OF_REQUESTS) { // preferred approach doSomething(); } if (aString.indexOf(&#x27;.&#x27;) != -1) {} // magic number -1, by default ignored if (aString.indexOf(&#x27;.&#x27;) &gt;= 0) { } // alternative approach if (aDouble &gt; 0.0) {} // magic number 0.0 if (aDouble &gt;= Double.MIN_VALUE) {} // preferred approach // with rule property &quot;ignoreExpressions&quot; set to &quot;false&quot; if (i == pos + 5) {} // violation: magic number 5 within an (additive) expression if (i == pos + SUFFIX_LENGTH) {} // preferred approach if (i == 5 &amp;&amp; &quot;none&quot;.equals(aString)) {} // 2 violations: magic number 5 and literal &quot;none&quot; } </code> </pre> <a href="https://docs.pmd-code.org/pmd-doc-7.3.0/pmd_rules_java_errorprone.html#avoidliteralsinifcondition"> See PMD documentation. </a>
if (score_v2 != 0.0) {

Check warning on line 82 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 82 is only partially covered, one branch is missing

Check warning on line 82 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / PMD

AvoidLiteralsInIfCondition

NORMAL: Avoid using literals in if statements.
Raw output
Avoid using hard-coded literals in conditional statements. By declaring them as static variables or private members with descriptive names maintainability is enhanced. By default, the literals "-1" and "0" are ignored. More exceptions can be defined with the property "ignoreMagicNumbers". The rule doesn't consider deeper expressions by default, but this can be enabled via the property `ignoreExpressions`. With this property set to false, if-conditions like `i == 1 + 5` are reported as well. Note that in that case, the property ignoreMagicNumbers is not taken into account, if there are multiple literals involved in such an expression. <pre> <code> private static final int MAX_NUMBER_OF_REQUESTS = 10; public void checkRequests() { if (i == 10) { // magic number, buried in a method doSomething(); } if (i == MAX_NUMBER_OF_REQUESTS) { // preferred approach doSomething(); } if (aString.indexOf(&#x27;.&#x27;) != -1) {} // magic number -1, by default ignored if (aString.indexOf(&#x27;.&#x27;) &gt;= 0) { } // alternative approach if (aDouble &gt; 0.0) {} // magic number 0.0 if (aDouble &gt;= Double.MIN_VALUE) {} // preferred approach // with rule property &quot;ignoreExpressions&quot; set to &quot;false&quot; if (i == pos + 5) {} // violation: magic number 5 within an (additive) expression if (i == pos + SUFFIX_LENGTH) {} // preferred approach if (i == 5 &amp;&amp; &quot;none&quot;.equals(aString)) {} // 2 violations: magic number 5 and literal &quot;none&quot; } </code> </pre> <a href="https://docs.pmd-code.org/pmd-doc-7.3.0/pmd_rules_java_errorprone.html#avoidliteralsinifcondition"> See PMD documentation. </a>
score = score_v2;
}
} else {

Check warning on line 85 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Java Compiler

checkstyle:check

NORMAL: (blocks) RightCurly: '}' at column 9 should be alone on a line.

Check warning on line 85 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / CheckStyle

RightCurlyCheck

NORMAL: '}' at column 9 should be alone on a line.
Raw output
<p>Since Checkstyle 3.0</p><p> Checks the placement of right curly braces (<code>'}'</code>) for if-else, try-catch-finally blocks, while-loops, for-loops, method definitions, class definitions, constructor definitions, instance and static initialization blocks. The policy to verify is specified using the property <code> option</code>. For right curly brace of expression blocks please follow issue <a href="https://github.com/checkstyle/checkstyle/issues/5945">#5945</a>. </p>
score = score_v3;
}

if (score < 0) {

Check warning on line 89 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 89 is only partially covered, one branch is missing
return Severity.ERROR;

Check warning on line 90 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 90 is not covered by tests
}

if (score == 0.0) {

Check warning on line 93 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 93 is only partially covered, one branch is missing

Check warning on line 93 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / PMD

AvoidLiteralsInIfCondition

NORMAL: Avoid using literals in if statements.
Raw output
Avoid using hard-coded literals in conditional statements. By declaring them as static variables or private members with descriptive names maintainability is enhanced. By default, the literals "-1" and "0" are ignored. More exceptions can be defined with the property "ignoreMagicNumbers". The rule doesn't consider deeper expressions by default, but this can be enabled via the property `ignoreExpressions`. With this property set to false, if-conditions like `i == 1 + 5` are reported as well. Note that in that case, the property ignoreMagicNumbers is not taken into account, if there are multiple literals involved in such an expression. <pre> <code> private static final int MAX_NUMBER_OF_REQUESTS = 10; public void checkRequests() { if (i == 10) { // magic number, buried in a method doSomething(); } if (i == MAX_NUMBER_OF_REQUESTS) { // preferred approach doSomething(); } if (aString.indexOf(&#x27;.&#x27;) != -1) {} // magic number -1, by default ignored if (aString.indexOf(&#x27;.&#x27;) &gt;= 0) { } // alternative approach if (aDouble &gt; 0.0) {} // magic number 0.0 if (aDouble &gt;= Double.MIN_VALUE) {} // preferred approach // with rule property &quot;ignoreExpressions&quot; set to &quot;false&quot; if (i == pos + 5) {} // violation: magic number 5 within an (additive) expression if (i == pos + SUFFIX_LENGTH) {} // preferred approach if (i == 5 &amp;&amp; &quot;none&quot;.equals(aString)) {} // 2 violations: magic number 5 and literal &quot;none&quot; } </code> </pre> <a href="https://docs.pmd-code.org/pmd-doc-7.3.0/pmd_rules_java_errorprone.html#avoidliteralsinifcondition"> See PMD documentation. </a>
return Severity.WARNING_LOW;

Check warning on line 94 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 94 is not covered by tests
}

if (score < 4.0) {

Check warning on line 97 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / PMD

AvoidLiteralsInIfCondition

NORMAL: Avoid using literals in if statements.
Raw output
Avoid using hard-coded literals in conditional statements. By declaring them as static variables or private members with descriptive names maintainability is enhanced. By default, the literals "-1" and "0" are ignored. More exceptions can be defined with the property "ignoreMagicNumbers". The rule doesn't consider deeper expressions by default, but this can be enabled via the property `ignoreExpressions`. With this property set to false, if-conditions like `i == 1 + 5` are reported as well. Note that in that case, the property ignoreMagicNumbers is not taken into account, if there are multiple literals involved in such an expression. <pre> <code> private static final int MAX_NUMBER_OF_REQUESTS = 10; public void checkRequests() { if (i == 10) { // magic number, buried in a method doSomething(); } if (i == MAX_NUMBER_OF_REQUESTS) { // preferred approach doSomething(); } if (aString.indexOf(&#x27;.&#x27;) != -1) {} // magic number -1, by default ignored if (aString.indexOf(&#x27;.&#x27;) &gt;= 0) { } // alternative approach if (aDouble &gt; 0.0) {} // magic number 0.0 if (aDouble &gt;= Double.MIN_VALUE) {} // preferred approach // with rule property &quot;ignoreExpressions&quot; set to &quot;false&quot; if (i == pos + 5) {} // violation: magic number 5 within an (additive) expression if (i == pos + SUFFIX_LENGTH) {} // preferred approach if (i == 5 &amp;&amp; &quot;none&quot;.equals(aString)) {} // 2 violations: magic number 5 and literal &quot;none&quot; } </code> </pre> <a href="https://docs.pmd-code.org/pmd-doc-7.3.0/pmd_rules_java_errorprone.html#avoidliteralsinifcondition"> See PMD documentation. </a>
return Severity.WARNING_LOW;
}

if (score >= 4.0 && score < 7.0) {

Check warning on line 101 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 101 is only partially covered, one branch is missing
return Severity.WARNING_NORMAL;
}

if (score >= 7 && score <= 10)

Check warning on line 105 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 105 is only partially covered, 2 branches are missing

Check warning on line 105 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Java Compiler

checkstyle:check

NORMAL: (blocks) NeedBraces: 'if' construct must use '{}'s.

Check warning on line 105 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / CheckStyle

NeedBracesCheck

NORMAL: 'if' construct must use '{}'s.
Raw output
<p>Since Checkstyle 3.0</p><p> Checks for braces around code blocks. </p>
return Severity.WARNING_HIGH;

Check warning on line 106 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / PMD

ControlStatementBraces

NORMAL: This statement should have braces.
Raw output
Enforce a policy for braces on control statements. It is recommended to use braces on 'if ... else' statements and loop statements, even if they are optional. This usually makes the code clearer, and helps prepare the future when you need to add another statement. That said, this rule lets you control which statements are required to have braces via properties. From 6.2.0 on, this rule supersedes WhileLoopMustUseBraces, ForLoopMustUseBraces, IfStmtMustUseBraces, and IfElseStmtMustUseBraces. <pre> <code> while (true) // not recommended x++; while (true) { // preferred approach x++; } </code> </pre> <a href="https://docs.pmd-code.org/pmd-doc-7.3.0/pmd_rules_java_codestyle.html#controlstatementbraces"> See PMD documentation. </a>

return Severity.ERROR;

Check warning on line 108 in src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 108 is not covered by tests
}

private String formatDescription(final String packageName, final JSONObject resource, final JSONObject vulnerability) {
final String version = resource.optString("version", VALUE_NOT_SET);
final String layer = resource.optString("layer", "UNKOWN");
final String vector = vulnerability.optString("vector", "UNKOWN");
final String link = vulnerability.optString("link", "UNKOWN");
final String description = vulnerability.optString("summary", "");

return join(div(b("Package: "), text(packageName)),
div(b("Version: "), text(version)),
div(b("Link: "), text(link)),
div(b("Yocto Layer: "), text(layer)),
div(b("Vector: "), text(vector)),
p(text(description))).render();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public class ParserRegistry {
new VeraCodePipelineScannerDescriptor(),
new XlcDescriptor(),
new YamlLintDescriptor(),
new YoctoScannerDescriptor(),
new XmlLintDescriptor(),
new YuiCompressorDescriptor(),
new ZptLintDescriptor()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package edu.hm.hafner.analysis.registry;

import edu.hm.hafner.analysis.IssueParser;
import edu.hm.hafner.analysis.parser.YoctoScannerParser;

import static j2html.TagCreator.*;

/**
* A descriptor for Yocto Scanner.
*
* @author Juri Duval
*/
class YoctoScannerDescriptor extends ParserDescriptor {
private static final String ID = "Yocto cli";
private static final String NAME = "Yocto Scanner";

YoctoScannerDescriptor() {
super(ID, NAME);
}

@Override
public IssueParser createParser(final Option... options) {
return new YoctoScannerParser();
}

@Override
public String getHelp() {
return join(text("Use commandline"),
code("bitbake <your product image>"),
text(", add INHERIT += \"cve-check\" in your local.conf"),
a("Yocto Scanner").withHref("https://docs.yoctoproject.org/dev/dev-manual/vulnerabilities.html"),
text("for usage details.")).render();

Check warning on line 32 in src/main/java/edu/hm/hafner/analysis/registry/YoctoScannerDescriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 28-32 are not covered by tests
}

@Override
public String getUrl() {
return "https://docs.yoctoproject.org/dev/dev-manual/vulnerabilities.html";
}

@Override
public String getIconUrl() {
return "https://www.yoctoproject.org/wp-content/uploads/sites/32/2023/09/YoctoProject_Logo_RGB_White_small.svg";

Check warning on line 42 in src/main/java/edu/hm/hafner/analysis/registry/YoctoScannerDescriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 42 is not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package edu.hm.hafner.analysis.parser;

import org.junit.jupiter.api.Test;

import edu.hm.hafner.analysis.IssueParser;
import edu.hm.hafner.analysis.ParsingException;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.assertions.SoftAssertions;
import edu.hm.hafner.analysis.registry.AbstractParserTest;

import static edu.hm.hafner.analysis.assertions.Assertions.*;

/**
* Tests the class {@link YoctoScannerParser}.
*/
class YoctoScannerParserTest extends AbstractParserTest {

Check warning on line 17 in src/test/java/edu/hm/hafner/analysis/parser/YoctoScannerParserTest.java

View check run for this annotation

ci.jenkins.io / Java Compiler

checkstyle:check

NORMAL: (regexp) RegexpMultiline: No empty lines after opening curly braces allowed

Check warning on line 17 in src/test/java/edu/hm/hafner/analysis/parser/YoctoScannerParserTest.java

View check run for this annotation

ci.jenkins.io / CheckStyle

RegexpMultilineCheck

NORMAL: No empty lines after opening curly braces allowed
Raw output
<p>Since Checkstyle 5.0</p><p> A check for detecting that matches across multiple lines. Works with any file type. </p><p> Rationale: This check can be used to when the regular expression can be span multiple lines. </p>

YoctoScannerParserTest() {
super("yocto_scanner_result.json");
}

@Override
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
softly.assertThat(report).hasSize(25);

softly.assertThat(report.get(0))
.hasSeverity(Severity.WARNING_LOW)
.hasPackageName("acl")
.hasMessage("CVE-2009-4411");
softly.assertThat(report.get(3))
.hasSeverity(Severity.WARNING_NORMAL)
.hasPackageName("automake-native")
.hasMessage("CVE-2012-3386");
}

@Test
void shouldHandleEmptyResultsJenkins67296() {
Report report = parse("issue67296.json");

assertThat(report).isEmpty();
}

@Test
void brokenInput() {
assertThatThrownBy(() -> parse("eclipse.txt")).isInstanceOf(ParsingException.class);
}

@Override
protected IssueParser createParser() {
return new YoctoScannerParser();
}
}
Loading
Loading