From 5986a0c5a1aad83c07050d6aeb420bb1cefba39f Mon Sep 17 00:00:00 2001 From: Barath Raj Date: Thu, 11 Jul 2024 00:39:24 +0530 Subject: [PATCH] Refactor. logic for vaild test case result check --- .../score/parsers/GitLabSastReader.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/org/owasp/benchmarkutils/score/parsers/GitLabSastReader.java b/plugin/src/main/java/org/owasp/benchmarkutils/score/parsers/GitLabSastReader.java index 40076b8..c34e08e 100644 --- a/plugin/src/main/java/org/owasp/benchmarkutils/score/parsers/GitLabSastReader.java +++ b/plugin/src/main/java/org/owasp/benchmarkutils/score/parsers/GitLabSastReader.java @@ -19,7 +19,10 @@ import org.json.JSONArray; import org.json.JSONObject; -import org.owasp.benchmarkutils.score.*; +import org.owasp.benchmarkutils.score.CweNumber; +import org.owasp.benchmarkutils.score.ResultFile; +import org.owasp.benchmarkutils.score.TestCaseResult; +import org.owasp.benchmarkutils.score.TestSuiteResults; public class GitLabSastReader extends Reader { @Override @@ -53,10 +56,9 @@ public TestSuiteResults parse(ResultFile resultFile) throws Exception { private TestCaseResult parseGitLabSastFindings(JSONObject vulnerability) { try { - String className = vulnerability.getJSONObject("location").getString("file"); - className = (className.substring(className.lastIndexOf('/') + 1)).split("\\.")[0]; + int testNumber = testNumber(vulnerability.getJSONObject("location").getString("file")); - if (className.startsWith(BenchmarkScore.TESTCASENAME)) { + if (testNumber > -1) { TestCaseResult tcr = new TestCaseResult(); JSONArray identifiers = vulnerability.getJSONArray("identifiers"); @@ -73,7 +75,7 @@ private TestCaseResult parseGitLabSastFindings(JSONObject vulnerability) { tcr.setCategory(category); tcr.setEvidence(evidence); tcr.setConfidence(0); - tcr.setNumber(testNumber(className)); + tcr.setNumber(testNumber); return tcr; }