Skip to content

Commit b7353f0

Browse files
Marcono1234smowton
authored andcommitted
Java: Simplify tests using InlineExpectationsTest
1 parent 84554af commit b7353f0

File tree

10 files changed

+475
-475
lines changed

10 files changed

+475
-475
lines changed

java/ql/test/library-tests/dataflow/fluent-methods/Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ public static void sink(String s) {}
4242
public static void test1() {
4343
Test t = new Test();
4444
t.fluentNoop().fluentSet(source()).fluentNoop();
45-
sink(t.get()); // $hasTaintFlow=y
45+
sink(t.get()); // $hasTaintFlow
4646
}
4747

4848
public static void test2() {
4949
Test t = new Test();
5050
Test.identity(t).fluentNoop().fluentSet(source()).fluentNoop();
51-
sink(t.get()); // $hasTaintFlow=y
51+
sink(t.get()); // $hasTaintFlow
5252
}
5353

5454
public static void test3() {
5555
Test t = new Test();
5656
t.indirectlyFluentNoop().fluentSet(source()).fluentNoop();
57-
sink(t.get()); // $hasTaintFlow=y
57+
sink(t.get()); // $hasTaintFlow
5858
}
5959

6060
public static void testModel1() {

java/ql/test/library-tests/dataflow/fluent-methods/flow.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class HasFlowTest extends InlineExpectationsTest {
3535
exists(DataFlow::Node src, DataFlow::Node sink, Conf conf | conf.hasFlow(src, sink) |
3636
sink.getLocation() = location and
3737
element = sink.toString() and
38-
value = "y"
38+
value = ""
3939
)
4040
}
4141
}

java/ql/test/library-tests/frameworks/apache-commons-lang3/StrBuilderTest.java

Lines changed: 73 additions & 73 deletions
Large diffs are not rendered by default.

java/ql/test/library-tests/frameworks/apache-commons-lang3/StrBuilderTextTest.java

Lines changed: 73 additions & 73 deletions
Large diffs are not rendered by default.

java/ql/test/library-tests/frameworks/apache-commons-lang3/Test.java

Lines changed: 178 additions & 178 deletions
Large diffs are not rendered by default.

java/ql/test/library-tests/frameworks/apache-commons-lang3/TextStringBuilderTest.java

Lines changed: 74 additions & 74 deletions
Large diffs are not rendered by default.

java/ql/test/library-tests/frameworks/apache-commons-lang3/flow.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class HasFlowTest extends InlineExpectationsTest {
2424
exists(DataFlow::Node src, DataFlow::Node sink, Conf conf | conf.hasFlow(src, sink) |
2525
sink.getLocation() = location and
2626
element = sink.toString() and
27-
value = "y"
27+
value = ""
2828
)
2929
}
3030
}

java/ql/test/library-tests/frameworks/apache-http/A.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,54 @@ static void sink(Object o) { }
1212

1313
class Test1 implements HttpRequestHandler {
1414
public void handle(HttpRequest req, HttpResponse res, HttpContext ctx) throws IOException {
15-
A.sink(req.getRequestLine()); //$hasTaintFlow=y
16-
A.sink(req.getRequestLine().getUri()); //$hasTaintFlow=y
17-
A.sink(req.getRequestLine().getMethod()); //$hasTaintFlow=y
18-
A.sink(req.getAllHeaders()); //$hasTaintFlow=y
15+
A.sink(req.getRequestLine()); //$hasTaintFlow
16+
A.sink(req.getRequestLine().getUri()); //$hasTaintFlow
17+
A.sink(req.getRequestLine().getMethod()); //$hasTaintFlow
18+
A.sink(req.getAllHeaders()); //$hasTaintFlow
1919
HeaderIterator it = req.headerIterator();
20-
A.sink(it.next()); //$hasTaintFlow=y
21-
A.sink(it.nextHeader()); //$hasTaintFlow=y
20+
A.sink(it.next()); //$hasTaintFlow
21+
A.sink(it.nextHeader()); //$hasTaintFlow
2222
Header h = req.getHeaders("abc")[3];
23-
A.sink(h.getName()); //$hasTaintFlow=y
24-
A.sink(h.getValue()); //$hasTaintFlow=y
23+
A.sink(h.getName()); //$hasTaintFlow
24+
A.sink(h.getValue()); //$hasTaintFlow
2525
HeaderElement el = h.getElements()[0];
26-
A.sink(el.getName()); //$hasTaintFlow=y
27-
A.sink(el.getValue()); //$hasTaintFlow=y
28-
A.sink(el.getParameters()); //$hasTaintFlow=y
29-
A.sink(el.getParameterByName("abc").getValue()); //$hasTaintFlow=y
30-
A.sink(el.getParameter(0).getName()); //$hasTaintFlow=y
26+
A.sink(el.getName()); //$hasTaintFlow
27+
A.sink(el.getValue()); //$hasTaintFlow
28+
A.sink(el.getParameters()); //$hasTaintFlow
29+
A.sink(el.getParameterByName("abc").getValue()); //$hasTaintFlow
30+
A.sink(el.getParameter(0).getName()); //$hasTaintFlow
3131
HttpEntity ent = ((HttpEntityEnclosingRequest)req).getEntity();
32-
A.sink(ent.getContent()); //$hasTaintFlow=y
33-
A.sink(ent.getContentEncoding()); //$hasTaintFlow=y
34-
A.sink(ent.getContentType()); //$hasTaintFlow=y
35-
A.sink(EntityUtils.toString(ent)); //$hasTaintFlow=y
36-
A.sink(EntityUtils.toByteArray(ent)); //$hasTaintFlow=y
37-
A.sink(EntityUtils.getContentCharSet(ent)); //$hasTaintFlow=y
38-
A.sink(EntityUtils.getContentMimeType(ent)); //$hasTaintFlow=y
39-
res.setEntity(new StringEntity("<a href='" + req.getRequestLine().getUri() + "'>a</a>")); //$hasTaintFlow=y
40-
EntityUtils.updateEntity(res, new ByteArrayEntity(EntityUtils.toByteArray(ent))); //$hasTaintFlow=y
41-
res.setHeader("Location", req.getRequestLine().getUri()); //$hasTaintFlow=y
42-
res.setHeader(new BasicHeader("Location", req.getRequestLine().getUri())); //$hasTaintFlow=y
32+
A.sink(ent.getContent()); //$hasTaintFlow
33+
A.sink(ent.getContentEncoding()); //$hasTaintFlow
34+
A.sink(ent.getContentType()); //$hasTaintFlow
35+
A.sink(EntityUtils.toString(ent)); //$hasTaintFlow
36+
A.sink(EntityUtils.toByteArray(ent)); //$hasTaintFlow
37+
A.sink(EntityUtils.getContentCharSet(ent)); //$hasTaintFlow
38+
A.sink(EntityUtils.getContentMimeType(ent)); //$hasTaintFlow
39+
res.setEntity(new StringEntity("<a href='" + req.getRequestLine().getUri() + "'>a</a>")); //$hasTaintFlow
40+
EntityUtils.updateEntity(res, new ByteArrayEntity(EntityUtils.toByteArray(ent))); //$hasTaintFlow
41+
res.setHeader("Location", req.getRequestLine().getUri()); //$hasTaintFlow
42+
res.setHeader(new BasicHeader("Location", req.getRequestLine().getUri())); //$hasTaintFlow
4343
}
4444
}
4545

4646
void test2() {
4747
ByteArrayBuffer bbuf = new ByteArrayBuffer(42);
4848
bbuf.append((byte[]) taint(), 0, 3);
49-
sink(bbuf.buffer()); //$hasTaintFlow=y
50-
sink(bbuf.toByteArray()); //$hasTaintFlow=y
49+
sink(bbuf.buffer()); //$hasTaintFlow
50+
sink(bbuf.toByteArray()); //$hasTaintFlow
5151

5252
CharArrayBuffer cbuf = new CharArrayBuffer(42);
5353
cbuf.append(bbuf.toByteArray(), 0, 3);
54-
sink(cbuf.toCharArray()); //$hasTaintFlow=y
55-
sink(cbuf.toString()); //$hasTaintFlow=y
56-
sink(cbuf.subSequence(0, 3)); //$hasTaintFlow=y
57-
sink(cbuf.substring(0, 3)); //$hasTaintFlow=y
58-
sink(cbuf.substringTrimmed(0, 3)); //$hasTaintFlow=y
54+
sink(cbuf.toCharArray()); //$hasTaintFlow
55+
sink(cbuf.toString()); //$hasTaintFlow
56+
sink(cbuf.subSequence(0, 3)); //$hasTaintFlow
57+
sink(cbuf.substring(0, 3)); //$hasTaintFlow
58+
sink(cbuf.substringTrimmed(0, 3)); //$hasTaintFlow
5959

60-
sink(Args.notNull(taint(), "x")); //$hasTaintFlow=y
61-
sink(Args.notEmpty((String) taint(), "x")); //$hasTaintFlow=y
62-
sink(Args.notBlank((String) taint(), "x")); //$hasTaintFlow=y
60+
sink(Args.notNull(taint(), "x")); //$hasTaintFlow
61+
sink(Args.notEmpty((String) taint(), "x")); //$hasTaintFlow
62+
sink(Args.notBlank((String) taint(), "x")); //$hasTaintFlow
6363
sink(Args.notNull("x", (String) taint())); // Good
6464
}
6565
}

java/ql/test/library-tests/frameworks/apache-http/B.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,63 @@ static void sink(Object o) { }
1414

1515
class Test1 implements HttpRequestHandler {
1616
public void handle(ClassicHttpRequest req, ClassicHttpResponse res, HttpContext ctx) throws IOException, ParseException {
17-
B.sink(req.getAuthority().getHostName()); //$hasTaintFlow=y
18-
B.sink(req.getAuthority().toString()); //$hasTaintFlow=y
19-
B.sink(req.getMethod()); //$hasTaintFlow=y
20-
B.sink(req.getPath()); //$hasTaintFlow=y
17+
B.sink(req.getAuthority().getHostName()); //$hasTaintFlow
18+
B.sink(req.getAuthority().toString()); //$hasTaintFlow
19+
B.sink(req.getMethod()); //$hasTaintFlow
20+
B.sink(req.getPath()); //$hasTaintFlow
2121
B.sink(req.getScheme());
22-
B.sink(req.getRequestUri()); //$hasTaintFlow=y
22+
B.sink(req.getRequestUri()); //$hasTaintFlow
2323
RequestLine line = new RequestLine(req);
24-
B.sink(line.getUri()); //$hasTaintFlow=y
25-
B.sink(line.getMethod()); //$hasTaintFlow=y
26-
B.sink(req.getHeaders()); //$hasTaintFlow=y
27-
B.sink(req.headerIterator()); //$hasTaintFlow=y
24+
B.sink(line.getUri()); //$hasTaintFlow
25+
B.sink(line.getMethod()); //$hasTaintFlow
26+
B.sink(req.getHeaders()); //$hasTaintFlow
27+
B.sink(req.headerIterator()); //$hasTaintFlow
2828
Header h = req.getHeaders("abc")[3];
29-
B.sink(h.getName()); //$hasTaintFlow=y
30-
B.sink(h.getValue()); //$hasTaintFlow=y
31-
B.sink(req.getFirstHeader("abc")); //$hasTaintFlow=y
32-
B.sink(req.getLastHeader("abc")); //$hasTaintFlow=y
29+
B.sink(h.getName()); //$hasTaintFlow
30+
B.sink(h.getValue()); //$hasTaintFlow
31+
B.sink(req.getFirstHeader("abc")); //$hasTaintFlow
32+
B.sink(req.getLastHeader("abc")); //$hasTaintFlow
3333
HttpEntity ent = req.getEntity();
34-
B.sink(ent.getContent()); //$hasTaintFlow=y
35-
B.sink(ent.getContentEncoding()); //$hasTaintFlow=y
36-
B.sink(ent.getContentType()); //$hasTaintFlow=y
37-
B.sink(ent.getTrailerNames()); //$hasTaintFlow=y
38-
B.sink(ent.getTrailers().get()); //$hasTaintFlow=y
39-
B.sink(EntityUtils.toString(ent)); //$hasTaintFlow=y
40-
B.sink(EntityUtils.toByteArray(ent)); //$hasTaintFlow=y
41-
B.sink(EntityUtils.parse(ent)); //$hasTaintFlow=y
42-
res.setEntity(new StringEntity("<a href='" + req.getRequestUri() + "'>a</a>")); //$hasTaintFlow=y
43-
res.setEntity(new ByteArrayEntity(EntityUtils.toByteArray(ent), ContentType.TEXT_HTML)); //$hasTaintFlow=y
44-
res.setEntity(HttpEntities.create("<a href='" + req.getRequestUri() + "'>a</a>")); //$hasTaintFlow=y
45-
res.setHeader("Location", req.getRequestUri()); //$hasTaintFlow=y
46-
res.setHeader(new BasicHeader("Location", req.getRequestUri())); //$hasTaintFlow=y
34+
B.sink(ent.getContent()); //$hasTaintFlow
35+
B.sink(ent.getContentEncoding()); //$hasTaintFlow
36+
B.sink(ent.getContentType()); //$hasTaintFlow
37+
B.sink(ent.getTrailerNames()); //$hasTaintFlow
38+
B.sink(ent.getTrailers().get()); //$hasTaintFlow
39+
B.sink(EntityUtils.toString(ent)); //$hasTaintFlow
40+
B.sink(EntityUtils.toByteArray(ent)); //$hasTaintFlow
41+
B.sink(EntityUtils.parse(ent)); //$hasTaintFlow
42+
res.setEntity(new StringEntity("<a href='" + req.getRequestUri() + "'>a</a>")); //$hasTaintFlow
43+
res.setEntity(new ByteArrayEntity(EntityUtils.toByteArray(ent), ContentType.TEXT_HTML)); //$hasTaintFlow
44+
res.setEntity(HttpEntities.create("<a href='" + req.getRequestUri() + "'>a</a>")); //$hasTaintFlow
45+
res.setHeader("Location", req.getRequestUri()); //$hasTaintFlow
46+
res.setHeader(new BasicHeader("Location", req.getRequestUri())); //$hasTaintFlow
4747
}
4848
}
4949

5050
void test2() {
5151
ByteArrayBuffer bbuf = new ByteArrayBuffer(42);
5252
bbuf.append((byte[]) taint(), 0, 3);
53-
sink(bbuf.array()); //$hasTaintFlow=y
54-
sink(bbuf.toByteArray()); //$hasTaintFlow=y
53+
sink(bbuf.array()); //$hasTaintFlow
54+
sink(bbuf.toByteArray()); //$hasTaintFlow
5555
sink(bbuf.toString());
5656

5757
CharArrayBuffer cbuf = new CharArrayBuffer(42);
5858
cbuf.append(bbuf.toByteArray(), 0, 3);
59-
sink(cbuf.toCharArray()); //$hasTaintFlow=y
60-
sink(cbuf.toString()); //$hasTaintFlow=y
61-
sink(cbuf.subSequence(0, 3)); //$hasTaintFlow=y
62-
sink(cbuf.substring(0, 3)); //$hasTaintFlow=y
63-
sink(cbuf.substringTrimmed(0, 3)); //$hasTaintFlow=y
59+
sink(cbuf.toCharArray()); //$hasTaintFlow
60+
sink(cbuf.toString()); //$hasTaintFlow
61+
sink(cbuf.subSequence(0, 3)); //$hasTaintFlow
62+
sink(cbuf.substring(0, 3)); //$hasTaintFlow
63+
sink(cbuf.substringTrimmed(0, 3)); //$hasTaintFlow
6464

65-
sink(Args.notNull(taint(), "x")); //$hasTaintFlow=y
66-
sink(Args.notEmpty((String) taint(), "x")); //$hasTaintFlow=y
67-
sink(Args.notBlank((String) taint(), "x")); //$hasTaintFlow=y
65+
sink(Args.notNull(taint(), "x")); //$hasTaintFlow
66+
sink(Args.notEmpty((String) taint(), "x")); //$hasTaintFlow
67+
sink(Args.notBlank((String) taint(), "x")); //$hasTaintFlow
6868
sink(Args.notNull("x", (String) taint()));
6969
}
7070

7171
class Test3 implements HttpServerRequestHandler {
7272
public void handle(ClassicHttpRequest req, HttpServerRequestHandler.ResponseTrigger restr, HttpContext ctx) throws HttpException, IOException {
73-
B.sink(req.getEntity()); //$hasTaintFlow=y
73+
B.sink(req.getEntity()); //$hasTaintFlow
7474
}
7575
}
7676
}

java/ql/test/library-tests/frameworks/apache-http/flow.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class HasFlowTest extends InlineExpectationsTest {
3333
exists(DataFlow::Node src, DataFlow::Node sink, Conf conf | conf.hasFlow(src, sink) |
3434
sink.getLocation() = location and
3535
element = sink.toString() and
36-
value = "y"
36+
value = ""
3737
)
3838
}
3939
}

0 commit comments

Comments
 (0)