Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit be9e972

Browse files
author
Max Schaefer
committed
Introduce class TestFile and use it.
1 parent 43309b9 commit be9e972

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

ql/src/Security/CWE-295/DisabledCertificateCheck.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,5 @@ where
115115
becomesPartOf*(base, init)
116116
) and
117117
// exclude results in test code
118-
exists(File fl | fl = w.getFile() | not fl = any(TestCase tc).getFile())
118+
exists(File fl | fl = w.getFile() | not fl instanceof TestFile)
119119
select w, "InsecureSkipVerify should not be used in production code."

ql/src/filters/ClassifyFiles.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ string generatorCommentRegex() {
2121

2222
predicate classify(File f, string category) {
2323
// tests
24-
f = any(TestCase tc).getFile() and
24+
f instanceof TestFile and
2525
category = "test"
2626
or
2727
// vendored code

ql/src/semmle/go/frameworks/Testing.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,31 @@ module TestCase {
4040
}
4141
}
4242
}
43+
44+
/**
45+
* A file that contains test cases or is otherwise used for testing.
46+
*
47+
* Extend this class to refine existing models of testing frameworks. If you want to model new
48+
* frameworks, extend `TestFile::Range` instead.
49+
*/
50+
class TestFile extends File {
51+
TestFile::Range self;
52+
53+
TestFile() { this = self }
54+
}
55+
56+
/** Provides classes for working with test files. */
57+
module TestFile {
58+
/**
59+
* A file that contains test cases or is otherwise used for testing.
60+
*
61+
* Extend this class to model new testing frameworks. If you want to refine existing models,
62+
* extend `TestFile` instead.
63+
*/
64+
abstract class Range extends File { }
65+
66+
/** A file containing at least one test case. */
67+
private class FileContainingTestCases extends Range {
68+
FileContainingTestCases() { this = any(TestCase tc).getFile() }
69+
}
70+
}

0 commit comments

Comments
 (0)