Fixup JaxRs.ql to cope with stubbed MediaType file

In a real-world situation this type would be defined in an imported jar, but since here it is defined in a stub the getADeclaredContentType routine can see it is defined as an empty string in the stubbed implementation. Filter these out so the test more closely resembles the real situation.
This commit is contained in:
Chris Smowton
2021-06-28 19:20:16 +01:00
parent 8eaffaff35
commit 768a8e78dd

View File

@@ -24,8 +24,16 @@ class JaxRsTest extends InlineExpectationsTest {
resourceMethod.getLocation() = location and
element = resourceMethod.toString() and
if exists(resourceMethod.getProducesAnnotation())
then value = resourceMethod.getProducesAnnotation().getADeclaredContentType()
else value = ""
then
value = resourceMethod.getProducesAnnotation().getADeclaredContentType() and
value != ""
else
// Filter out empty strings that stem from using stubs.
// If we built the test against the real JAR then the field
// access against e.g. MediaType.APPLICATION_JSON wouldn't
// be a CompileTimeConstantExpr at all, whereas in the stubs
// it is and is defined empty.
value = ""
)
or
tag = "RootResourceClass" and
@@ -135,7 +143,13 @@ class JaxRsTest extends InlineExpectationsTest {
exists(JaxRSProducesAnnotation producesAnnotation |
producesAnnotation.getLocation() = location and
element = producesAnnotation.toString() and
value = producesAnnotation.getADeclaredContentType()
value = producesAnnotation.getADeclaredContentType() and
value != ""
// Filter out empty strings that stem from using stubs.
// If we built the test against the real JAR then the field
// access against e.g. MediaType.APPLICATION_JSON wouldn't
// be a CompileTimeConstantExpr at all, whereas in the stubs
// it is and is defined empty.
)
or
tag = "ConsumesAnnotation" and