Skip to content

Commit fbaa382

Browse files
committed
Add tests for Pair.of and Triple.of
1 parent eebaab8 commit fbaa382

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ void test() throws Exception {
1919
ImmutablePair<String, String> taintedLeft2 = (ImmutablePair)taintedLeft2_;
2020
Pair<String, String> taintedRight2_ = ImmutablePair.right(taint());
2121
ImmutablePair<String, String> taintedRight2 = (ImmutablePair)taintedRight2_;
22+
Pair<String, String> taintedLeft3 = Pair.of(taint(), "clean-right");
23+
Pair<String, String> taintedRight3 = Pair.of("clean-left", taint());
2224

2325
// Check flow through ImmutablePairs:
2426
sink(taintedLeft.getLeft()); // $hasValueFlow
@@ -45,6 +47,14 @@ void test() throws Exception {
4547
sink(taintedRight2.getValue()); // $hasValueFlow
4648
sink(taintedRight2.left);
4749
sink(taintedRight2.right); // $hasValueFlow
50+
sink(taintedLeft3.getLeft()); // $hasValueFlow
51+
sink(taintedLeft3.getRight());
52+
sink(taintedLeft3.getKey()); // $hasValueFlow
53+
sink(taintedLeft3.getValue());
54+
sink(taintedRight3.getLeft());
55+
sink(taintedRight3.getRight()); // $hasValueFlow
56+
sink(taintedRight3.getKey());
57+
sink(taintedRight3.getValue()); // $hasValueFlow
4858

4959
// Check flow also works via an alias of type Pair:
5060
sink(taintedLeft2_.getLeft()); // $hasValueFlow

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ void test() throws Exception {
5252
sink(taintedRight2.getMiddle());
5353
sink(taintedRight2.getRight()); // $hasValueFlow
5454

55+
// Check flow via Triple.of:
56+
Triple<String, String, String> taintedLeft3 = Triple.of(taint(), "clean-middle", "clean-right");
57+
Triple<String, String, String> taintedMiddle3 = Triple.of("clean-left", taint(), "clean-right");
58+
Triple<String, String, String> taintedRight3 = Triple.of("clean-left", "clean-middle", taint());
59+
60+
sink(taintedLeft3.getLeft()); // $hasValueFlow
61+
sink(taintedLeft3.getMiddle());
62+
sink(taintedLeft3.getRight());
63+
sink(taintedMiddle3.getLeft());
64+
sink(taintedMiddle3.getMiddle()); // $hasValueFlow
65+
sink(taintedMiddle3.getRight());
66+
sink(taintedRight3.getLeft());
67+
sink(taintedRight3.getMiddle());
68+
sink(taintedRight3.getRight()); // $hasValueFlow
69+
5570
MutableTriple<String, String, String> mutableTaintedLeft = MutableTriple.of(taint(), "clean-middle", "clean-right");
5671
MutableTriple<String, String, String> mutableTaintedMiddle = MutableTriple.of("clean-left", taint(), "clean-right");
5772
MutableTriple<String, String, String> mutableTaintedRight = MutableTriple.of("clean-left", "clean-middle", taint());

0 commit comments

Comments
 (0)