Skip to content

Commit c4d8189

Browse files
committed
[test] Tests to guard against spurious namespace declarations in REST API results
Closes eXist-db/exist#5845
1 parent 781456c commit c4d8189

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

exist-core/src/test/java/org/exist/http/RESTServiceTest.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,86 @@ public void queryPostXQueryError() throws IOException {
701701
}
702702
}
703703

704+
/**
705+
* See: <a href="https://github.com/eXist-db/exist/issues/5845">[BUG] Spurious namespace declarations in REST API results</a>
706+
*/
707+
@Test
708+
public void queryPostWithEnclosedExpressionResponseNamespaces() throws IOException {
709+
String query =
710+
"<query xmlns=\"http://exist.sourceforge.net/NS/exist\" wrap=\"no\" typed=\"no\">\n" +
711+
" <text>&lt;doc&gt;{3+4}&lt;/doc&gt;</text>\n" +
712+
"</query>";
713+
714+
HttpURLConnection connect = preparePost(query, getResourceUri());
715+
try {
716+
connect.connect();
717+
final int r = connect.getResponseCode();
718+
assertEquals("Server returned response code " + r, HttpStatus.OK_200, r);
719+
720+
final String data = readResponse(connect.getInputStream());
721+
assertEquals("<doc>7</doc>", data.trim());
722+
} finally {
723+
connect.disconnect();
724+
}
725+
726+
query =
727+
"<query xmlns=\"http://exist.sourceforge.net/NS/exist\" wrap=\"no\" typed=\"yes\">\n" +
728+
" <text>&lt;doc&gt;{3+4}&lt;/doc&gt;</text>\n" +
729+
"</query>";
730+
731+
connect = preparePost(query, getResourceUri());
732+
try {
733+
connect.connect();
734+
final int r = connect.getResponseCode();
735+
assertEquals("Server returned response code " + r, HttpStatus.OK_200, r);
736+
737+
final String data = readResponse(connect.getInputStream());
738+
assertEquals("<doc>7</doc>", data.trim());
739+
} finally {
740+
connect.disconnect();
741+
}
742+
}
743+
744+
/**
745+
* See: <a href="https://github.com/eXist-db/exist/issues/5845">[BUG] Spurious namespace declarations in REST API results</a>
746+
*/
747+
@Test
748+
public void queryPostWithoutEnclosedExpressionResponseNamespaces() throws IOException {
749+
String query =
750+
"<query xmlns=\"http://exist.sourceforge.net/NS/exist\" wrap=\"no\" typed=\"no\">\n" +
751+
" <text>&lt;doc&gt;7&lt;/doc&gt;</text>\n" +
752+
"</query>";
753+
754+
HttpURLConnection connect = preparePost(query, getResourceUri());
755+
try {
756+
connect.connect();
757+
final int r = connect.getResponseCode();
758+
assertEquals("Server returned response code " + r, HttpStatus.OK_200, r);
759+
760+
final String data = readResponse(connect.getInputStream());
761+
assertEquals("<doc>7</doc>", data.trim());
762+
} finally {
763+
connect.disconnect();
764+
}
765+
766+
query =
767+
"<query xmlns=\"http://exist.sourceforge.net/NS/exist\" wrap=\"no\" typed=\"yes\">\n" +
768+
" <text>&lt;doc&gt;7&lt;/doc&gt;</text>\n" +
769+
"</query>";
770+
771+
connect = preparePost(query, getResourceUri());
772+
try {
773+
connect.connect();
774+
final int r = connect.getResponseCode();
775+
assertEquals("Server returned response code " + r, HttpStatus.OK_200, r);
776+
777+
final String data = readResponse(connect.getInputStream());
778+
assertEquals("<doc>7</doc>", data.trim());
779+
} finally {
780+
connect.disconnect();
781+
}
782+
}
783+
704784
@Test
705785
public void queryGet() throws IOException {
706786
final String uri = getCollectionUri()

0 commit comments

Comments
 (0)