@@ -9,21 +9,29 @@ private import semmle.code.java.dataflow.internal.DataFlowPrivate
99private import semmle.code.java.dataflow.TaintTracking
1010
1111/**
12- * An external API from either the Java Standard Library or a 3rd party library.
12+ * A test library.
1313 */
14- class ExternalApi extends Callable {
15- ExternalApi ( ) { not this .fromSource ( ) }
16-
17- /** Holds if this API is not worth supporting */
18- predicate isUninteresting ( ) { this .isTestLibrary ( ) or this .isParameterlessConstructor ( ) }
19-
20- /** Holds if this API is is a constructor without parameters */
21- predicate isParameterlessConstructor ( ) {
22- this instanceof Constructor and this .getNumberOfParameters ( ) = 0
14+ private class TestLibrary extends RefType {
15+ TestLibrary ( ) {
16+ this .getPackage ( )
17+ .getName ( )
18+ .matches ( [
19+ "org.junit%" , "junit.%" , "org.mockito%" , "org.assertj%" ,
20+ "com.github.tomakehurst.wiremock%" , "org.hamcrest%" , "org.springframework.test.%" ,
21+ "org.springframework.mock.%" , "org.springframework.boot.test.%" , "reactor.test%" ,
22+ "org.xmlunit%" , "org.testcontainers.%" , "org.opentest4j%" , "org.mockserver%" ,
23+ "org.powermock%" , "org.skyscreamer.jsonassert%" , "org.rnorth.visibleassertions" ,
24+ "org.openqa.selenium%" , "com.gargoylesoftware.htmlunit%" ,
25+ "org.jboss.arquillian.testng%" , "org.testng%"
26+ ] )
2327 }
28+ }
2429
25- /** Holds if this API is part of a common testing library or framework */
26- private predicate isTestLibrary ( ) { this .getDeclaringType ( ) instanceof TestLibrary }
30+ /**
31+ * An external API from either the Standard Library or a 3rd party library.
32+ */
33+ class ExternalApi extends Callable {
34+ ExternalApi ( ) { not this .fromSource ( ) }
2735
2836 /**
2937 * Gets information about the external API in the form expected by the CSV modeling framework.
@@ -34,17 +42,17 @@ class ExternalApi extends Callable {
3442 "#" + this .getName ( ) + paramsString ( this )
3543 }
3644
45+ private string containerAsJar ( Container container ) {
46+ if container instanceof JarFile then result = container .getBaseName ( ) else result = "rt.jar"
47+ }
48+
3749 /**
3850 * Gets the jar file containing this API. Normalizes the Java Runtime to "rt.jar" despite the presence of modules.
3951 */
4052 string jarContainer ( ) {
4153 result = this .containerAsJar ( this .getCompilationUnit ( ) .getParentContainer * ( ) )
4254 }
4355
44- private string containerAsJar ( Container container ) {
45- if container instanceof JarFile then result = container .getBaseName ( ) else result = "rt.jar"
46- }
47-
4856 /** Gets a node that is an input to a call to this API. */
4957 private DataFlow:: Node getAnInput ( ) {
5058 exists ( Call call | call .getCallee ( ) .getSourceDeclaration ( ) = this |
@@ -67,6 +75,17 @@ class ExternalApi extends Callable {
6775 TaintTracking:: localAdditionalTaintStep ( this .getAnInput ( ) , _)
6876 }
6977
78+ /** Holds if this API is is a constructor without parameters */
79+ private predicate isParameterlessConstructor ( ) {
80+ this instanceof Constructor and this .getNumberOfParameters ( ) = 0
81+ }
82+
83+ /** Holds if this API is part of a common testing library or framework */
84+ private predicate isTestLibrary ( ) { this .getDeclaringType ( ) instanceof TestLibrary }
85+
86+ /** Holds if this API is not worth supporting */
87+ predicate isUninteresting ( ) { this .isTestLibrary ( ) or this .isParameterlessConstructor ( ) }
88+
7089 /** Holds if this API is a known source. */
7190 predicate isSource ( ) {
7291 this .getAnOutput ( ) instanceof RemoteFlowSource or sourceNode ( this .getAnOutput ( ) , _)
@@ -78,22 +97,3 @@ class ExternalApi extends Callable {
7897 /** Holds if this API is supported by existing CodeQL libraries, that is, it is either a recognized source or sink or has a flow summary. */
7998 predicate isSupported ( ) { this .hasSummary ( ) or this .isSource ( ) or this .isSink ( ) }
8099}
81-
82- /** DEPRECATED: Alias for ExternalApi */
83- deprecated class ExternalAPI = ExternalApi ;
84-
85- private class TestLibrary extends RefType {
86- TestLibrary ( ) {
87- this .getPackage ( )
88- .getName ( )
89- .matches ( [
90- "org.junit%" , "junit.%" , "org.mockito%" , "org.assertj%" ,
91- "com.github.tomakehurst.wiremock%" , "org.hamcrest%" , "org.springframework.test.%" ,
92- "org.springframework.mock.%" , "org.springframework.boot.test.%" , "reactor.test%" ,
93- "org.xmlunit%" , "org.testcontainers.%" , "org.opentest4j%" , "org.mockserver%" ,
94- "org.powermock%" , "org.skyscreamer.jsonassert%" , "org.rnorth.visibleassertions" ,
95- "org.openqa.selenium%" , "com.gargoylesoftware.htmlunit%" ,
96- "org.jboss.arquillian.testng%" , "org.testng%"
97- ] )
98- }
99- }
0 commit comments