Skip to content

Commit eaef1c1

Browse files
author
Sauyon Lee
committed
Add generated tests
1 parent 16931e5 commit eaef1c1

File tree

8 files changed

+822
-0
lines changed

8 files changed

+822
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package generatedtest;
2+
3+
import java.util.concurrent.Callable;
4+
import org.springframework.cache.Cache;
5+
6+
// Test case generated by GenerateFlowTestCase.ql
7+
public class Test {
8+
9+
Object getMapKey(Object container) { return null; }
10+
Object getMapValue(Object container) { return null; }
11+
Object newWithMapKey(Object element) { return null; }
12+
Object newWithMapValue(Object element) { return null; }
13+
Object source() { return null; }
14+
void sink(Object o) { }
15+
16+
public void test() {
17+
18+
{
19+
// "org.springframework.cache;Cache$ValueRetrievalException;false;ValueRetrievalException;;;Argument[0];MapKey of Argument[-1];value"
20+
Cache.ValueRetrievalException out = null;
21+
Object in = source();
22+
out = new ValueRetrievalException(in, null, null);
23+
sink(getMapKey(out)); // $hasValueFlow
24+
}
25+
{
26+
// "org.springframework.cache;Cache$ValueRetrievalException;false;getKey;;;MapKey of Argument[-1];ReturnValue;value"
27+
Object out = null;
28+
Cache.ValueRetrievalException in = (Cache.ValueRetrievalException)newWithMapKey(source());
29+
out = in.getKey();
30+
sink(out); // $hasValueFlow
31+
}
32+
{
33+
// "org.springframework.cache;Cache$ValueWrapper;true;get;;;MapValue of Argument[-1];ReturnValue;value"
34+
Object out = null;
35+
Cache.ValueWrapper in = (Cache.ValueWrapper)newWithMapValue(source());
36+
out = in.get();
37+
sink(out); // $hasValueFlow
38+
}
39+
{
40+
// "org.springframework.cache;Cache;true;get;(Object);;MapValue of Argument[-1];MapValue of ReturnValue;value"
41+
Cache.ValueWrapper out = null;
42+
Cache in = (Cache)newWithMapValue(source());
43+
out = in.get(null);
44+
sink(getMapValue(out)); // $hasValueFlow
45+
}
46+
{
47+
// "org.springframework.cache;Cache;true;get;(Object,Callable);;MapValue of Argument[-1];ReturnValue;value"
48+
Object out = null;
49+
Cache in = (Cache)newWithMapValue(source());
50+
out = in.get(null, (Callable)null);
51+
sink(out); // $hasValueFlow
52+
}
53+
{
54+
// "org.springframework.cache;Cache;true;get;(Object,Class);;MapValue of Argument[-1];ReturnValue;value"
55+
Object out = null;
56+
Cache in = (Cache)newWithMapValue(source());
57+
out = in.get(null, (Class)null);
58+
sink(out); // $hasValueFlow
59+
}
60+
{
61+
// "org.springframework.cache;Cache;true;getNativeCache;;;MapKey of Argument[-1];MapKey of ReturnValue;value"
62+
Object out = null;
63+
Cache in = (Cache)newWithMapKey(source());
64+
out = in.getNativeCache();
65+
sink(getMapKey(out)); // $hasValueFlow
66+
}
67+
{
68+
// "org.springframework.cache;Cache;true;getNativeCache;;;MapValue of Argument[-1];MapValue of ReturnValue;value"
69+
Object out = null;
70+
Cache in = (Cache)newWithMapValue(source());
71+
out = in.getNativeCache();
72+
sink(getMapValue(out)); // $hasValueFlow
73+
}
74+
{
75+
// "org.springframework.cache;Cache;true;put;;;Argument[0];MapKey of Argument[-1];value"
76+
Cache out = null;
77+
Object in = source();
78+
out.put(in, null);
79+
sink(getMapKey(out)); // $hasValueFlow
80+
}
81+
{
82+
// "org.springframework.cache;Cache;true;put;;;Argument[1];MapValue of Argument[-1];value"
83+
Cache out = null;
84+
Object in = source();
85+
out.put(null, in);
86+
sink(getMapValue(out)); // $hasValueFlow
87+
}
88+
{
89+
// "org.springframework.cache;Cache;true;putIfAbsent;;;Argument[0];MapKey of Argument[-1];value"
90+
Cache out = null;
91+
Object in = source();
92+
out.putIfAbsent(in, null);
93+
sink(getMapKey(out)); // $hasValueFlow
94+
}
95+
{
96+
// "org.springframework.cache;Cache;true;putIfAbsent;;;Argument[1];MapValue of Argument[-1];value"
97+
Cache out = null;
98+
Object in = source();
99+
out.putIfAbsent(null, in);
100+
sink(getMapValue(out)); // $hasValueFlow
101+
}
102+
{
103+
// "org.springframework.cache;Cache;true;putIfAbsent;;;MapValue of Argument[-1];MapValue of ReturnValue;value"
104+
Cache.ValueWrapper out = null;
105+
Cache in = (Cache)newWithMapValue(source());
106+
out = in.putIfAbsent(null, null);
107+
sink(getMapValue(out)); // $hasValueFlow
108+
}
109+
110+
}
111+
112+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/springframework-5.3.8

java/ql/test/library-tests/frameworks/spring/cache/test.expected

Whitespace-only changes.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import java
2+
import semmle.code.java.dataflow.DataFlow
3+
import semmle.code.java.dataflow.ExternalFlow
4+
import semmle.code.java.dataflow.TaintTracking
5+
import TestUtilities.InlineExpectationsTest
6+
7+
class SummaryModelTest extends SummaryModelCsv {
8+
override predicate row(string row) {
9+
row =
10+
[
11+
//"package;type;overrides;name;signature;ext;inputspec;outputspec;kind",
12+
"generatedtest;Test;false;getMapKey;;;MapKey of Argument[0];ReturnValue;value",
13+
"generatedtest;Test;false;newWithMapKey;;;Argument[0];MapKey of ReturnValue;value",
14+
"generatedtest;Test;false;getMapValue;;;MapValue of Argument[0];ReturnValue;value",
15+
"generatedtest;Test;false;newWithMapValue;;;Argument[0];MapValue of ReturnValue;value"
16+
]
17+
}
18+
}
19+
20+
class ValueFlowConf extends DataFlow::Configuration {
21+
ValueFlowConf() { this = "qltest:valueFlowConf" }
22+
23+
override predicate isSource(DataFlow::Node n) {
24+
n.asExpr().(MethodAccess).getMethod().hasName("source")
25+
}
26+
27+
override predicate isSink(DataFlow::Node n) {
28+
n.asExpr().(Argument).getCall().getCallee().hasName("sink")
29+
}
30+
}
31+
32+
class TaintFlowConf extends TaintTracking::Configuration {
33+
TaintFlowConf() { this = "qltest:taintFlowConf" }
34+
35+
override predicate isSource(DataFlow::Node n) {
36+
n.asExpr().(MethodAccess).getMethod().hasName("source")
37+
}
38+
39+
override predicate isSink(DataFlow::Node n) {
40+
n.asExpr().(Argument).getCall().getCallee().hasName("sink")
41+
}
42+
}
43+
44+
class HasFlowTest extends InlineExpectationsTest {
45+
HasFlowTest() { this = "HasFlowTest" }
46+
47+
override string getARelevantTag() { result = ["hasValueFlow", "hasTaintFlow"] }
48+
49+
override predicate hasActualResult(Location location, string element, string tag, string value) {
50+
tag = "hasValueFlow" and
51+
exists(DataFlow::Node src, DataFlow::Node sink, ValueFlowConf conf | conf.hasFlow(src, sink) |
52+
sink.getLocation() = location and
53+
element = sink.toString() and
54+
value = ""
55+
)
56+
or
57+
tag = "hasTaintFlow" and
58+
exists(DataFlow::Node src, DataFlow::Node sink, TaintFlowConf conf |
59+
conf.hasFlow(src, sink) and not any(ValueFlowConf c).hasFlow(src, sink)
60+
|
61+
sink.getLocation() = location and
62+
element = sink.toString() and
63+
value = ""
64+
)
65+
}
66+
}

0 commit comments

Comments
 (0)