Skip to content

Commit

Permalink
#68 - move sarif readers to separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
darkspirit510 committed Apr 18, 2024
1 parent 5148873 commit 6cc7407
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
import org.owasp.benchmarkutils.score.BenchmarkScore;
import org.owasp.benchmarkutils.score.ResultFile;
import org.owasp.benchmarkutils.score.TestSuiteResults;
import org.owasp.benchmarkutils.score.parsers.sarif.CodeQLReader;
import org.owasp.benchmarkutils.score.parsers.sarif.ContrastScanReader;
import org.owasp.benchmarkutils.score.parsers.sarif.DatadogSastReader;
import org.owasp.benchmarkutils.score.parsers.sarif.PrecautionReader;
import org.owasp.benchmarkutils.score.parsers.sarif.SemgrepSarifReader;
import org.owasp.benchmarkutils.score.parsers.sarif.SnykReader;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @author Nicolas Couraud
* @created 2021
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import org.owasp.benchmarkutils.score.CweNumber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Sascha Knoop
* @created 2022
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import org.json.JSONObject;
import org.owasp.benchmarkutils.score.CweNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Julien Delange
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import org.owasp.benchmarkutils.score.ResultFile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Eric Brown
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

public class PrecautionReader extends SarifReader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Sascha Knoop
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import static java.lang.Integer.parseInt;

Expand All @@ -34,6 +34,7 @@
import org.owasp.benchmarkutils.score.ResultFile;
import org.owasp.benchmarkutils.score.TestCaseResult;
import org.owasp.benchmarkutils.score.TestSuiteResults;
import org.owasp.benchmarkutils.score.parsers.Reader;

public abstract class SarifReader extends Reader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Sascha Knoop
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

public class SemgrepSarifReader extends SarifReader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Raj Barath
* @created 2023
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

public class SnykReader extends SarifReader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void assertReaderIsInReaderAllReadersList() {
"Reader " + thisReaderName + " must be added to Reader.allReaders() list");
}

void assertOnlyMatcherClassIs(ResultFile resultFile, Class<? extends Reader> c) {
protected void assertOnlyMatcherClassIs(ResultFile resultFile, Class<? extends Reader> c) {
List<Class<?>> readers =
Reader.allReaders().stream()
.filter(r -> r.canRead(resultFile))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Nicolas Couraud
* @created 2023
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -26,9 +26,7 @@
import org.owasp.benchmarkutils.score.ResultFile;
import org.owasp.benchmarkutils.score.TestHelper;
import org.owasp.benchmarkutils.score.TestSuiteResults;

import java.io.File;
import java.io.IOException;
import org.owasp.benchmarkutils.score.parsers.ReaderTestBase;

public class CodeQLReaderTest extends ReaderTestBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Sascha Knoop
* @created 2022
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -27,6 +27,7 @@
import org.owasp.benchmarkutils.score.ResultFile;
import org.owasp.benchmarkutils.score.TestHelper;
import org.owasp.benchmarkutils.score.TestSuiteResults;
import org.owasp.benchmarkutils.score.parsers.ReaderTestBase;

public class ContrastScanReaderTest extends ReaderTestBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Julien Delange
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -24,6 +24,7 @@
import org.owasp.benchmarkutils.score.ResultFile;
import org.owasp.benchmarkutils.score.TestHelper;
import org.owasp.benchmarkutils.score.TestSuiteResults;
import org.owasp.benchmarkutils.score.parsers.ReaderTestBase;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Eric Brown
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -27,6 +27,8 @@
import org.owasp.benchmarkutils.score.ResultFile;
import org.owasp.benchmarkutils.score.TestHelper;
import org.owasp.benchmarkutils.score.TestSuiteResults;
import org.owasp.benchmarkutils.score.parsers.ReaderTestBase;
import org.owasp.benchmarkutils.score.parsers.sarif.PrecautionReader;

class PrecautionReaderTest extends ReaderTestBase {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* OWASP Benchmark Project
*
* <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project For
* details, please see <a
* href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
*
* <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, version 2.
*
* <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* @author Sascha Knoop
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers.sarif;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.owasp.benchmarkutils.score.parsers.sarif.SarifReader;

public class SarifReaderTest {

@ParameterizedTest(name = "{index} - extracts cwe number from input {0}")
@ValueSource(
strings = {
"CWE-326",
"CWE-326: Inadequate Encryption Strength",
"external/cwe/cwe-326",
"CWE:326"
})
void extractsCweNumberFromInput(String input) {
assertEquals(326, SarifReader.extractCwe(input));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Sascha Knoop
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -27,6 +27,7 @@
import org.owasp.benchmarkutils.score.ResultFile;
import org.owasp.benchmarkutils.score.TestHelper;
import org.owasp.benchmarkutils.score.TestSuiteResults;
import org.owasp.benchmarkutils.score.parsers.ReaderTestBase;

class SemgrepSarifReaderTest extends ReaderTestBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Raj Barath
* @created 2023
*/
package org.owasp.benchmarkutils.score.parsers;
package org.owasp.benchmarkutils.score.parsers.sarif;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -27,6 +27,7 @@
import org.owasp.benchmarkutils.score.ResultFile;
import org.owasp.benchmarkutils.score.TestHelper;
import org.owasp.benchmarkutils.score.TestSuiteResults;
import org.owasp.benchmarkutils.score.parsers.ReaderTestBase;

class SnykReaderTest extends ReaderTestBase {

Expand Down

0 comments on commit 6cc7407

Please sign in to comment.