mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Ruby: Rewrite inline expectation tests to use parameterized module
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -2,17 +2,15 @@ import codeql.ruby.AST
|
||||
import codeql.ruby.Concepts
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
|
||||
class CryptographicOperationTest extends InlineExpectationsTest {
|
||||
CryptographicOperationTest() { this = "CryptographicOperationTest" }
|
||||
|
||||
override string getARelevantTag() {
|
||||
module CryptographicOperationTest implements TestSig {
|
||||
string getARelevantTag() {
|
||||
result in [
|
||||
"CryptographicOperation", "CryptographicOperationInput", "CryptographicOperationAlgorithm",
|
||||
"CryptographicOperationBlockMode"
|
||||
]
|
||||
}
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(Cryptography::CryptographicOperation cryptoOperation |
|
||||
location = cryptoOperation.getLocation() and
|
||||
(
|
||||
@@ -31,3 +29,5 @@ class CryptographicOperationTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<CryptographicOperationTest>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -17,10 +17,8 @@ class CustomEntryPointUse extends API::EntryPoint {
|
||||
}
|
||||
}
|
||||
|
||||
class ApiUseTest extends InlineExpectationsTest {
|
||||
ApiUseTest() { this = "ApiUseTest" }
|
||||
|
||||
override string getARelevantTag() { result = ["use", "def", "call"] }
|
||||
module ApiUseTest implements TestSig {
|
||||
string getARelevantTag() { result = ["use", "def", "call"] }
|
||||
|
||||
private predicate relevantNode(API::Node a, DataFlow::Node n, Location l, string tag) {
|
||||
l = n.getLocation() and
|
||||
@@ -36,13 +34,13 @@ class ApiUseTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
tag = "use" and // def tags are always optional
|
||||
exists(DataFlow::Node n | this.relevantNode(_, n, location, tag) |
|
||||
exists(DataFlow::Node n | relevantNode(_, n, location, tag) |
|
||||
// Only report the longest path on this line:
|
||||
value =
|
||||
max(API::Node a2, Location l2, DataFlow::Node n2 |
|
||||
this.relevantNode(a2, n2, l2, tag) and
|
||||
relevantNode(a2, n2, l2, tag) and
|
||||
l2.getFile() = location.getFile() and
|
||||
l2.getEndLine() = location.getEndLine()
|
||||
|
|
||||
@@ -56,14 +54,16 @@ class ApiUseTest extends InlineExpectationsTest {
|
||||
|
||||
// We also permit optional annotations for any other path on the line.
|
||||
// This is used to test subclass paths, which typically have a shorter canonical path.
|
||||
override predicate hasOptionalResult(Location location, string element, string tag, string value) {
|
||||
exists(API::Node a, DataFlow::Node n | this.relevantNode(a, n, location, tag) |
|
||||
predicate hasOptionalResult(Location location, string element, string tag, string value) {
|
||||
exists(API::Node a, DataFlow::Node n | relevantNode(a, n, location, tag) |
|
||||
element = n.toString() and
|
||||
value = getAPath(a, _)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<ApiUseTest>
|
||||
|
||||
private int size(AstNode n) { not n instanceof StmtSequence and result = count(n.getAChild*()) }
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
WARNING: Type BarrierGuard has been deprecated and may be removed in future (barrier-guards.ql:10,3-15)
|
||||
failures
|
||||
testFailures
|
||||
oldStyleBarrierGuards
|
||||
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:4:5:4:7 | foo | barrier-guards.rb:3:4:3:6 | foo | true |
|
||||
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:4:5:4:7 | foo | barrier-guards.rb:3:11:3:15 | "foo" | true |
|
||||
|
||||
@@ -24,12 +24,10 @@ query predicate controls(CfgNode condition, BasicBlock bb, SuccessorTypes::Condi
|
||||
)
|
||||
}
|
||||
|
||||
class BarrierGuardTest extends InlineExpectationsTest {
|
||||
BarrierGuardTest() { this = "BarrierGuardTest" }
|
||||
module BarrierGuardTest implements TestSig {
|
||||
string getARelevantTag() { result = "guarded" }
|
||||
|
||||
override string getARelevantTag() { result = "guarded" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
tag = "guarded" and
|
||||
exists(DataFlow::Node n |
|
||||
newStyleBarrierGuards(n) and
|
||||
@@ -39,3 +37,5 @@ class BarrierGuardTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<BarrierGuardTest>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
failures
|
||||
testFailures
|
||||
| improper_memoization.rb:100:1:104:3 | m14 | Unexpected result: result=BAD |
|
||||
#select
|
||||
| improper_memoization.rb:50:1:55:3 | m7 | improper_memoization.rb:50:8:50:10 | arg | improper_memoization.rb:51:3:53:5 | ... \|\|= ... |
|
||||
|
||||
@@ -2,12 +2,10 @@ import codeql.ruby.AST
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
import codeql.ruby.security.ImproperMemoizationQuery
|
||||
|
||||
class ImproperMemoizationTest extends InlineExpectationsTest {
|
||||
ImproperMemoizationTest() { this = "ImproperMemoizationTest" }
|
||||
module ImproperMemoizationTest implements TestSig {
|
||||
string getARelevantTag() { result = "result" }
|
||||
|
||||
override string getARelevantTag() { result = "result" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
tag = "result" and
|
||||
value = "BAD" and
|
||||
exists(Expr e |
|
||||
@@ -18,6 +16,8 @@ class ImproperMemoizationTest extends InlineExpectationsTest {
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<ImproperMemoizationTest>
|
||||
|
||||
from Method m, Parameter p, AssignLogicalOrExpr s
|
||||
where isImproperMemoizationMethod(m, p, s)
|
||||
select m, p, s
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -8,17 +8,17 @@ import codeql.ruby.DataFlow
|
||||
import codeql.ruby.security.IncompleteMultiCharacterSanitizationQuery as Query
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
|
||||
class Test extends InlineExpectationsTest {
|
||||
Test() { this = "IncompleteMultiCharacterSanitizationTest" }
|
||||
module Test implements TestSig {
|
||||
string getARelevantTag() { result = "hasResult" }
|
||||
|
||||
override string getARelevantTag() { result = "hasResult" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
tag = "hasResult" and
|
||||
hasResult(location, element, value)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<Test>
|
||||
|
||||
predicate hasResult(Location location, string element, string value) {
|
||||
exists(DataFlow::Node replace, string kind |
|
||||
replace.getLocation() = location and
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
failures
|
||||
testFailures
|
||||
#select
|
||||
| Gemfile:2:8:2:28 | "http://rubygems.org" | Dependency source URL uses the unencrypted protocol HTTP. Use HTTPS instead. |
|
||||
| Gemfile:3:8:3:27 | "ftp://rubygems.org" | Dependency source URL uses the unencrypted protocol FTP. Use FTPS or SFTP instead. |
|
||||
|
||||
@@ -2,12 +2,10 @@ import codeql.ruby.AST
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
import codeql.ruby.security.InsecureDependencyQuery
|
||||
|
||||
class InsecureDependencyTest extends InlineExpectationsTest {
|
||||
InsecureDependencyTest() { this = "InsecureDependencyTest" }
|
||||
module InsecureDependencyTest implements TestSig {
|
||||
string getARelevantTag() { result = "result" }
|
||||
|
||||
override string getARelevantTag() { result = "result" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
tag = "result" and
|
||||
value = "BAD" and
|
||||
exists(Expr e |
|
||||
@@ -18,6 +16,8 @@ class InsecureDependencyTest extends InlineExpectationsTest {
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<InsecureDependencyTest>
|
||||
|
||||
from Expr url, string msg
|
||||
where insecureDependencyUrl(url, msg)
|
||||
select url, msg
|
||||
|
||||
Reference in New Issue
Block a user