summaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin/src/test/java/com/yahoo
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@oath.com>2018-04-10 15:47:03 +0200
committerTor Brede Vekterli <vekterli@oath.com>2018-04-10 15:47:03 +0200
commitc593ef736afa91df911416ae6070990a2d361998 (patch)
treed5fe4237f79819bfa5548cfdcd4f148017a74599 /vespaclient-container-plugin/src/test/java/com/yahoo
parentbf8586f5c5d4456b159573c22066bf395f043607 (diff)
Ensure selection parameter sub-expression is complete and valid
Also add validation that specified group only contains allowed text characters. This mirrors the check that is done for group names in IDs when documents are originally fed.
Diffstat (limited to 'vespaclient-container-plugin/src/test/java/com/yahoo')
-rw-r--r--vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java
index ed7935b698b..14d8239ba41 100644
--- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java
+++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java
@@ -340,6 +340,12 @@ public class RestApiTest {
}
@Test
+ public void non_text_group_string_character_returns_error() {
+ String output = performV1RestCall(String.format("group/%s", encoded("\u001f")));
+ assertThat(output, containsString("Failed to parse group part of selection URI; contains invalid text code point U001F"));
+ }
+
+ @Test
public void can_specify_numeric_id_without_explicit_selection() {
assertResultingDocumentSelection("number/1234", "id.user==1234");
}
@@ -361,6 +367,20 @@ public class RestApiTest {
"id.group=='bar' and (3 != 4)");
}
+ private void assertDocumentSelectionFailsParsing(String expression) {
+ String output = performV1RestCall(String.format("number/1234?selection=%s", encoded(expression)));
+ assertThat(output, containsString("Failed to parse expression given in 'selection' parameter. Must be a complete and valid sub-expression."));
+ }
+
+ // Make sure that typoing the selection parameter doesn't corrupt the entire selection expression
+ @Test
+ public void explicit_selection_sub_expression_is_validated_for_completeness() {
+ assertDocumentSelectionFailsParsing("1 +");
+ assertDocumentSelectionFailsParsing(") or true");
+ assertDocumentSelectionFailsParsing("((1 + 2)");
+ assertDocumentSelectionFailsParsing("true) or (true");
+ }
+
@Test
public void wanted_document_count_returned_parameter_is_propagated() throws IOException {
Request request = new Request(String.format("http://localhost:%s/document/v1/namespace/document-type/docid/?wantedDocumentCount=321", getFirstListenPort()));