Skip to content

Commit 22c3a28

Browse files
committed
Ruby: fixup type-tracking hash flow test
Fixup! type-tracking hash flow test result
1 parent 4bb3687 commit 22c3a28

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

ruby/ql/test/TestUtilities/InlineFlowTest.qll

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,7 @@ import codeql.ruby.AST
3737
import codeql.ruby.DataFlow
3838
import codeql.ruby.TaintTracking
3939
import TestUtilities.InlineExpectationsTest
40-
41-
predicate defaultSource(DataFlow::Node src) {
42-
src.asExpr().getExpr().(MethodCall).getMethodName() = ["source", "taint"]
43-
}
44-
45-
predicate defaultSink(DataFlow::Node sink) {
46-
exists(MethodCall mc | mc.getMethodName() = "sink" | sink.asExpr().getExpr() = mc.getAnArgument())
47-
}
40+
import TestUtilities.InlineFlowTestUtil
4841

4942
class DefaultValueFlowConf extends DataFlow::Configuration {
5043
DefaultValueFlowConf() { this = "qltest:defaultValueFlowConf" }
@@ -66,11 +59,6 @@ class DefaultTaintFlowConf extends TaintTracking::Configuration {
6659
override int fieldFlowBranchLimit() { result = 1000 }
6760
}
6861

69-
string getSourceArgString(DataFlow::Node src) {
70-
defaultSource(src) and
71-
src.asExpr().getExpr().(MethodCall).getAnArgument().getConstantValue().toString() = result
72-
}
73-
7462
class InlineFlowTest extends InlineExpectationsTest {
7563
InlineFlowTest() { this = "HasFlowTest" }
7664

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Defines the default source and sink recognition for `InlineFlowTest.qll`.
3+
*
4+
* We reuse these predicates in some type-tracking tests that don't wish to bring in the
5+
* test configuration from `InlineFlowTest`.
6+
*/
7+
8+
import codeql.ruby.AST
9+
import codeql.ruby.DataFlow
10+
11+
predicate defaultSource(DataFlow::Node src) {
12+
src.asExpr().getExpr().(MethodCall).getMethodName() = ["source", "taint"]
13+
}
14+
15+
predicate defaultSink(DataFlow::Node sink) {
16+
exists(MethodCall mc | mc.getMethodName() = "sink" | sink.asExpr().getExpr() = mc.getAnArgument())
17+
}
18+
19+
string getSourceArgString(DataFlow::Node src) {
20+
defaultSource(src) and
21+
src.asExpr().getExpr().(MethodCall).getAnArgument().getConstantValue().toString() = result
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1+
| hash_flow.rb:65:21:65:40 | # $ hasValueFlow=3.3 | Missing result:hasValueFlow=3.3 |
2+
| hash_flow.rb:66:21:66:49 | # $ SPURIOUS hasValueFlow=3.3 | Missing result:hasValueFlow=3.3 |
13
| hash_flow.rb:114:10:114:17 | ...[...] | Unexpected result: hasValueFlow=7.2 |
24
| hash_flow.rb:117:10:117:17 | ...[...] | Unexpected result: hasValueFlow=7.1 |
35
| hash_flow.rb:117:10:117:17 | ...[...] | Unexpected result: hasValueFlow=7.2 |
46
| hash_flow.rb:119:10:119:17 | ...[...] | Unexpected result: hasValueFlow=7.1 |
7+
| hash_flow.rb:152:16:152:36 | # $ hasValueFlow=10.1 | Missing result:hasValueFlow=10.1 |
58
| hash_flow.rb:163:10:163:17 | ...[...] | Unexpected result: hasValueFlow=9.1 |
69
| hash_flow.rb:187:10:187:17 | ...[...] | Unexpected result: hasValueFlow=12.1 |
10+
| hash_flow.rb:201:17:201:37 | # $ hasValueFlow=13.1 | Missing result:hasValueFlow=13.1 |
11+
| hash_flow.rb:219:27:219:47 | # $ hasValueFlow=14.2 | Missing result:hasValueFlow=14.2 |
712
| hash_flow.rb:291:10:291:14 | ...[...] | Unexpected result: hasValueFlow=19.1 |
813
| hash_flow.rb:294:10:294:14 | ...[...] | Unexpected result: hasValueFlow=19.3 |
14+
| hash_flow.rb:351:18:351:38 | # $ hasValueFlow=22.1 | Missing result:hasValueFlow=22.1 |
15+
| hash_flow.rb:396:18:396:38 | # $ hasValueFlow=25.1 | Missing result:hasValueFlow=25.1 |
16+
| hash_flow.rb:453:22:453:42 | # $ hasValueFlow=27.3 | Missing result:hasValueFlow=27.3 |
17+
| hash_flow.rb:455:22:455:42 | # $ hasValueFlow=27.4 | Missing result:hasValueFlow=27.4 |
18+
| hash_flow.rb:467:16:467:36 | # $ hasValueFlow=28.1 | Missing result:hasValueFlow=28.1 |
19+
| hash_flow.rb:482:16:482:36 | # $ hasValueFlow=29.1 | Missing result:hasValueFlow=29.1 |
20+
| hash_flow.rb:497:16:497:36 | # $ hasValueFlow=30.1 | Missing result:hasValueFlow=30.1 |
21+
| hash_flow.rb:513:22:513:42 | # $ hasValueFlow=31.1 | Missing result:hasValueFlow=31.1 |
922
| hash_flow.rb:515:10:515:20 | ( ... ) | Unexpected result: hasValueFlow=31.3 |
23+
| hash_flow.rb:515:22:515:42 | # $ hasValueFlow=31.2 | Missing result:hasValueFlow=31.2 |
24+
| hash_flow.rb:529:18:529:38 | # $ hasValueFlow=32.1 | Missing result:hasValueFlow=32.1 |
25+
| hash_flow.rb:559:17:559:57 | # $ hasValueFlow=34.1 $ hasValueFlow=34.2 | Missing result:hasValueFlow=34.1 |
26+
| hash_flow.rb:559:17:559:57 | # $ hasValueFlow=34.1 $ hasValueFlow=34.2 | Missing result:hasValueFlow=34.2 |
27+
| hash_flow.rb:571:18:571:38 | # $ hasValueFlow=35.1 | Missing result:hasValueFlow=35.1 |
28+
| hash_flow.rb:576:18:576:38 | # $ hasValueFlow=35.1 | Missing result:hasValueFlow=35.1 |
29+
| hash_flow.rb:578:18:578:38 | # $ hasValueFlow=35.2 | Missing result:hasValueFlow=35.2 |
30+
| hash_flow.rb:591:20:591:60 | # $ hasValueFlow=36.1 $ hasValueFlow=36.2 | Missing result:hasValueFlow=36.1 |
31+
| hash_flow.rb:591:20:591:60 | # $ hasValueFlow=36.1 $ hasValueFlow=36.2 | Missing result:hasValueFlow=36.2 |
1032
| hash_flow.rb:668:14:668:18 | value | Unexpected result: hasValueFlow=41.3 |
1133
| hash_flow.rb:671:10:671:19 | ( ... ) | Unexpected result: hasValueFlow=41.1 |
34+
| hash_flow.rb:702:22:702:42 | # $ hasValueFlow=42.3 | Missing result:hasValueFlow=42.3 |
35+
| hash_flow.rb:704:22:704:42 | # $ hasValueFlow=42.4 | Missing result:hasValueFlow=42.4 |

ruby/ql/test/library-tests/dataflow/hash-flow/type-tracking-hash-flow.ql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import ruby
22
import TestUtilities.InlineExpectationsTest
3-
import TestUtilities.InlineFlowTest // we are matching annotations defined by this library
3+
import TestUtilities.InlineFlowTestUtil
44
private import codeql.ruby.typetracking.TypeTracker
5-
import codeql.ruby.ast.Constant
65

76
private DataFlow::LocalSourceNode track(TypeTracker t, DataFlow::CallNode source) {
87
t.start() and
@@ -16,8 +15,8 @@ DataFlow::LocalSourceNode track(DataFlow::CallNode source) {
1615
result = track(TypeTracker::end(), source)
1716
}
1817

19-
class HasFlowTest extends InlineExpectationsTest {
20-
HasFlowTest() { this = "HasFlowTest" }
18+
class TypeTrackingFlowTest extends InlineExpectationsTest {
19+
TypeTrackingFlowTest() { this = "TypeTrackingFlowTest" }
2120

2221
override string getARelevantTag() { result = "hasValueFlow" }
2322

0 commit comments

Comments
 (0)