This is an automated email from the ASF dual-hosted git repository.
rvesse pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new 533d0b109a Fixed flaky tests due to HashMap
new cb37a56577 Merge pull request #2096 from wang3820/fix-flaky
533d0b109a is described below
commit 533d0b109a08aa2a318d432165d9503430d679a9
Author: Tong Wang <[email protected]>
AuthorDate: Wed Nov 29 10:27:27 2023 -0600
Fixed flaky tests due to HashMap
Check both injection orders as first and second element could be returned
in nondeterministic order
Change param back to HashMap
Added missing update
---
.../jena/query/TestParameterizedSparqlString.java | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git
a/jena-arq/src/test/java/org/apache/jena/query/TestParameterizedSparqlString.java
b/jena-arq/src/test/java/org/apache/jena/query/TestParameterizedSparqlString.java
index 058c76aa09..0e954dee8d 100644
---
a/jena-arq/src/test/java/org/apache/jena/query/TestParameterizedSparqlString.java
+++
b/jena-arq/src/test/java/org/apache/jena/query/TestParameterizedSparqlString.java
@@ -1511,6 +1511,16 @@ public class TestParameterizedSparqlString {
pss.setLiteral(first, "?" + second);
pss.setLiteral(second, " . } ; DROP ALL ; INSERT DATA { <s> <p> ");
+ pss.asUpdate();
+ // Due to the unpredictability of the order of parameters in
this.params,
+ // which is a HashMap, here the reverse order is checked to make sure
+ // an ARQException is thrown
+ pss.setLiteral("var", "a");
+ pss.setLiteral("var2", "b");
+
+ pss.setLiteral(second, "?" + first);
+ pss.setLiteral(first, " . } ; DROP ALL ; INSERT DATA { <s> <p> ");
+
pss.asUpdate();
Assert.fail("Attempt to do SPARQL injection should result in an
exception");
}
@@ -1584,6 +1594,16 @@ public class TestParameterizedSparqlString {
pss.setLiteral(first, " ?" + second + " ");
pss.setLiteral(second, " . } ; DROP ALL ; INSERT DATA { <s> <p> ");
+ pss.asUpdate();
+ // Due to the unpredictability of the order of parameters in
this.params,
+ // which is a HashMap, here the reverse order is checked to make sure
+ // an ARQException is thrown
+ pss.setLiteral("var", "a");
+ pss.setLiteral("var2", "b");
+
+ pss.setLiteral(second, " ?" + first + " ");
+ pss.setLiteral(first, " . } ; DROP ALL ; INSERT DATA { <s> <p> ");
+
pss.asUpdate();
Assert.fail("Attempt to do SPARQL injection should result in an
exception");
}