Java: Add query for CSV framework coverage.

This commit is contained in:
Anders Schack-Mulligen
2021-03-10 12:03:44 +01:00
parent ed250d5017
commit 4941d9b7bf
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
/**
* @name Framework coverage
* @description The number of API endpoints covered by CSV models sorted by
* package and source-, sink-, and summary-kind.
* @kind metric
* @id java/meta/framework-coverage
*/
import java
import semmle.code.java.dataflow.ExternalFlow
from string package, string kind, string part, int n
where modelCoverage(package, kind, part, n)
select package, kind, part, n

View File

@@ -204,6 +204,29 @@ private predicate summaryModel(
)
}
/**
* Holds if CSV framework coverage of `package` is `n` api endpoints of the
* kind `(kind, part)`.
*/
predicate modelCoverage(string package, string kind, string part, int n) {
part = "source" and
n =
strictcount(string type, boolean subtypes, string name, string signature, string ext,
string output | sourceModel(package, type, subtypes, name, signature, ext, output, kind))
or
part = "sink" and
n =
strictcount(string type, boolean subtypes, string name, string signature, string ext,
string input | sinkModel(package, type, subtypes, name, signature, ext, input, kind))
or
part = "summary" and
n =
strictcount(string type, boolean subtypes, string name, string signature, string ext,
string input, string output |
summaryModel(package, type, subtypes, name, signature, ext, input, output, kind)
)
}
/** Provides a query predicate to check the CSV data for validation errors. */
module CsvValidation {
/** Holds if some row in a CSV-based flow model appears to contain typos. */