Skip to content

Commit 8350d64

Browse files
committed
Python: Add concept test definitions
1 parent 601a803 commit 8350d64

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

python/ql/test/experimental/meta/ConceptsTest.qll

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,59 @@ class HttpServerRouteSetupTest extends InlineExpectationsTest {
142142
)
143143
}
144144
}
145+
146+
class FileSystemAccessTest extends InlineExpectationsTest {
147+
FileSystemAccessTest() { this = "FileSystemAccessTest" }
148+
149+
override string getARelevantTag() { result = "getAPathArgument" }
150+
151+
override predicate hasActualResult(Location location, string element, string tag, string value) {
152+
exists(FileSystemAccess a, DataFlow::Node path |
153+
exists(location.getFile().getRelativePath()) and
154+
path = a.getAPathArgument() and
155+
location = a.getLocation() and
156+
element = path.toString() and
157+
value = value_from_expr(path.asExpr()) and
158+
tag = "getAPathArgument"
159+
)
160+
}
161+
}
162+
163+
class PathNormalizationTest extends InlineExpectationsTest {
164+
PathNormalizationTest() { this = "PathNormalizationTest" }
165+
166+
override string getARelevantTag() { result = "pathNormalization" }
167+
168+
override predicate hasActualResult(Location location, string element, string tag, string value) {
169+
exists(Path::PathNormalization n |
170+
exists(location.getFile().getRelativePath()) and
171+
location = n.getLocation() and
172+
element = n.toString() and
173+
value = "" and
174+
tag = "pathNormalization"
175+
)
176+
}
177+
}
178+
179+
class SafeAccessCheckTest extends InlineExpectationsTest {
180+
SafeAccessCheckTest() { this = "SafeAccessCheckTest" }
181+
182+
override string getARelevantTag() { result in ["checks", "branch"] }
183+
184+
override predicate hasActualResult(Location location, string element, string tag, string value) {
185+
exists(Path::SafeAccessCheck c, DataFlow::Node checks, boolean branch |
186+
exists(location.getFile().getRelativePath()) and
187+
c.checks(checks.asCfgNode(), branch) and
188+
location = c.getLocation() and
189+
(
190+
element = checks.toString() and
191+
value = value_from_expr(checks.asExpr()) and
192+
tag = "checks"
193+
or
194+
element = branch.toString() and
195+
value = branch.toString() and
196+
tag = "branch"
197+
)
198+
)
199+
}
200+
}

0 commit comments

Comments
 (0)