Skip to content

Commit 8628ff5

Browse files
authored
Merge pull request github#10999 from RasmusWL/inline-fail-tag
InlineExpectationsTest: Fail if missing `getARelevantTag`
2 parents 95a54f7 + b840e8e commit 8628ff5

File tree

18 files changed

+126
-17
lines changed

18 files changed

+126
-17
lines changed

cpp/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ abstract class InlineExpectationsTest extends string {
137137
final predicate hasFailureMessage(FailureLocatable element, string message) {
138138
exists(ActualResult actualResult |
139139
actualResult.getTest() = this and
140+
actualResult.getTag() = this.getARelevantTag() and
140141
element = actualResult and
141142
(
142143
exists(FalseNegativeExpectation falseNegative |
@@ -150,9 +151,18 @@ abstract class InlineExpectationsTest extends string {
150151
)
151152
)
152153
or
154+
exists(ActualResult actualResult |
155+
actualResult.getTest() = this and
156+
not actualResult.getTag() = this.getARelevantTag() and
157+
element = actualResult and
158+
message =
159+
"Tag mismatch: Actual result with tag '" + actualResult.getTag() +
160+
"' that is not part of getARelevantTag()"
161+
)
162+
or
153163
exists(ValidExpectation expectation |
154164
not exists(ActualResult actualResult | expectation.matchesActualResult(actualResult)) and
155-
expectation.getTag() = getARelevantTag() and
165+
expectation.getTag() = this.getARelevantTag() and
156166
element = expectation and
157167
(
158168
expectation instanceof GoodExpectation and

csharp/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ abstract class InlineExpectationsTest extends string {
137137
final predicate hasFailureMessage(FailureLocatable element, string message) {
138138
exists(ActualResult actualResult |
139139
actualResult.getTest() = this and
140+
actualResult.getTag() = this.getARelevantTag() and
140141
element = actualResult and
141142
(
142143
exists(FalseNegativeExpectation falseNegative |
@@ -150,9 +151,18 @@ abstract class InlineExpectationsTest extends string {
150151
)
151152
)
152153
or
154+
exists(ActualResult actualResult |
155+
actualResult.getTest() = this and
156+
not actualResult.getTag() = this.getARelevantTag() and
157+
element = actualResult and
158+
message =
159+
"Tag mismatch: Actual result with tag '" + actualResult.getTag() +
160+
"' that is not part of getARelevantTag()"
161+
)
162+
or
153163
exists(ValidExpectation expectation |
154164
not exists(ActualResult actualResult | expectation.matchesActualResult(actualResult)) and
155-
expectation.getTag() = getARelevantTag() and
165+
expectation.getTag() = this.getARelevantTag() and
156166
element = expectation and
157167
(
158168
expectation instanceof GoodExpectation and

go/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ abstract class InlineExpectationsTest extends string {
137137
final predicate hasFailureMessage(FailureLocatable element, string message) {
138138
exists(ActualResult actualResult |
139139
actualResult.getTest() = this and
140+
actualResult.getTag() = this.getARelevantTag() and
140141
element = actualResult and
141142
(
142143
exists(FalseNegativeExpectation falseNegative |
@@ -150,9 +151,18 @@ abstract class InlineExpectationsTest extends string {
150151
)
151152
)
152153
or
154+
exists(ActualResult actualResult |
155+
actualResult.getTest() = this and
156+
not actualResult.getTag() = this.getARelevantTag() and
157+
element = actualResult and
158+
message =
159+
"Tag mismatch: Actual result with tag '" + actualResult.getTag() +
160+
"' that is not part of getARelevantTag()"
161+
)
162+
or
153163
exists(ValidExpectation expectation |
154164
not exists(ActualResult actualResult | expectation.matchesActualResult(actualResult)) and
155-
expectation.getTag() = getARelevantTag() and
165+
expectation.getTag() = this.getARelevantTag() and
156166
element = expectation and
157167
(
158168
expectation instanceof GoodExpectation and

java/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ abstract class InlineExpectationsTest extends string {
137137
final predicate hasFailureMessage(FailureLocatable element, string message) {
138138
exists(ActualResult actualResult |
139139
actualResult.getTest() = this and
140+
actualResult.getTag() = this.getARelevantTag() and
140141
element = actualResult and
141142
(
142143
exists(FalseNegativeExpectation falseNegative |
@@ -150,9 +151,18 @@ abstract class InlineExpectationsTest extends string {
150151
)
151152
)
152153
or
154+
exists(ActualResult actualResult |
155+
actualResult.getTest() = this and
156+
not actualResult.getTag() = this.getARelevantTag() and
157+
element = actualResult and
158+
message =
159+
"Tag mismatch: Actual result with tag '" + actualResult.getTag() +
160+
"' that is not part of getARelevantTag()"
161+
)
162+
or
153163
exists(ValidExpectation expectation |
154164
not exists(ActualResult actualResult | expectation.matchesActualResult(actualResult)) and
155-
expectation.getTag() = getARelevantTag() and
165+
expectation.getTag() = this.getARelevantTag() and
156166
element = expectation and
157167
(
158168
expectation instanceof GoodExpectation and

java/ql/test/library-tests/frameworks/JaxWs/JakartaRs1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void Post() { // $ ResourceMethod ResourceMethodOnResourceClass
4141
@Produces("text/plain") // $ ProducesAnnotation=text/plain
4242
@DELETE
4343
double Delete() { // $ ResourceMethod=text/plain ResourceMethodOnResourceClass
44-
return 0.0; // $ XssSink
44+
return 0.0;
4545
}
4646

4747
@Produces(MediaType.TEXT_HTML) // $ ProducesAnnotation=text/html
@@ -77,7 +77,7 @@ boolean Post() { // $ ResourceMethod=text/html ResourceMethodOnResourceClass
7777
@Produces(MediaType.TEXT_PLAIN) // $ ProducesAnnotation=text/plain
7878
@DELETE
7979
double Delete() { // $ ResourceMethod=text/plain ResourceMethodOnResourceClass
80-
return 0.0; // $ XssSink
80+
return 0.0;
8181
}
8282

8383
@Path("")

java/ql/test/library-tests/frameworks/JaxWs/JaxRs.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class JaxRsTest extends InlineExpectationsTest {
1414
"InjectionAnnotation", "ResponseDeclaration", "ResponseBuilderDeclaration",
1515
"ClientDeclaration", "BeanParamConstructor", "MessageBodyReaderDeclaration",
1616
"MessageBodyReaderReadFromCall", "MessageBodyReaderReadCall", "ProducesAnnotation",
17-
"ConsumesAnnotation"
17+
"ConsumesAnnotation", "XssSink"
1818
]
1919
}
2020

java/ql/test/library-tests/frameworks/JaxWs/JaxRs1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void Post() { // $ ResourceMethod ResourceMethodOnResourceClass
4141
@Produces("text/plain") // $ ProducesAnnotation=text/plain
4242
@DELETE
4343
double Delete() { // $ ResourceMethod=text/plain ResourceMethodOnResourceClass
44-
return 0.0; // $ XssSink
44+
return 0.0;
4545
}
4646

4747
@Produces(MediaType.TEXT_HTML) // $ ProducesAnnotation=text/html
@@ -77,7 +77,7 @@ boolean Post() { // $ ResourceMethod=text/html ResourceMethodOnResourceClass
7777
@Produces(MediaType.TEXT_PLAIN) // $ ProducesAnnotation=text/plain
7878
@DELETE
7979
double Delete() { // $ ResourceMethod=text/plain ResourceMethodOnResourceClass
80-
return 0.0; // $ XssSink
80+
return 0.0;
8181
}
8282

8383
@Path("")

python/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ abstract class InlineExpectationsTest extends string {
137137
final predicate hasFailureMessage(FailureLocatable element, string message) {
138138
exists(ActualResult actualResult |
139139
actualResult.getTest() = this and
140+
actualResult.getTag() = this.getARelevantTag() and
140141
element = actualResult and
141142
(
142143
exists(FalseNegativeExpectation falseNegative |
@@ -150,9 +151,18 @@ abstract class InlineExpectationsTest extends string {
150151
)
151152
)
152153
or
154+
exists(ActualResult actualResult |
155+
actualResult.getTest() = this and
156+
not actualResult.getTag() = this.getARelevantTag() and
157+
element = actualResult and
158+
message =
159+
"Tag mismatch: Actual result with tag '" + actualResult.getTag() +
160+
"' that is not part of getARelevantTag()"
161+
)
162+
or
153163
exists(ValidExpectation expectation |
154164
not exists(ActualResult actualResult | expectation.matchesActualResult(actualResult)) and
155-
expectation.getTag() = getARelevantTag() and
165+
expectation.getTag() = this.getARelevantTag() and
156166
element = expectation and
157167
(
158168
expectation instanceof GoodExpectation and
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.py:1:1:1:3 | foo | Tag mismatch: Actual result with tag 'foo' that is not part of getARelevantTag() |
2+
| test.py:4:1:4:3 | foo | Tag mismatch: Actual result with tag 'foo' that is not part of getARelevantTag() |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// test to illustrate what happens if you forget to put in the
2+
// right values for `getARelevantTag`. We want to alert on this,
3+
// so it gets fixed!
4+
import python
5+
import TestUtilities.InlineExpectationsTest
6+
7+
class MissingRelevantTag extends InlineExpectationsTest {
8+
MissingRelevantTag() { this = "MissingRelevantTag" }
9+
10+
override string getARelevantTag() { none() }
11+
12+
override predicate hasActualResult(Location location, string element, string tag, string value) {
13+
exists(Name name | name.getId() = "foo" |
14+
location = name.getLocation() and
15+
element = name.toString() and
16+
value = "val" and
17+
tag = "foo"
18+
)
19+
}
20+
}

0 commit comments

Comments
 (0)