You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gu...@apache.org on 2019/03/04 17:32:04 UTC
[lucene-solr] 05/10: SOLR-13152 Add check for values that resolve
to the __CRA__ collection name infix which is reserved
This is an automated email from the ASF dual-hosted git repository.
gus pushed a commit to branch solr-13131
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 6a93ee4bf37e7c9c68747224f44a8b97af955eba
Author: Gus Heck <gu...@apache.org>
AuthorDate: Sun Mar 3 12:23:29 2019 -0500
SOLR-13152 Add check for values that resolve to the __CRA__ collection
name infix which is reserved
---
.../apache/solr/cloud/api/collections/CategoryRoutedAlias.java | 10 +++++++++-
.../processor/CategoryRoutedAliasUpdateProcessorTest.java | 4 +++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java
index 0b0114d..5089eeb 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java
@@ -128,7 +128,7 @@ public class CategoryRoutedAlias implements RoutedAlias {
if (fieldValue == null) {
throw new SolrException(BAD_REQUEST,"Route value is null");
}
-
+
String dataValue = String.valueOf(fieldValue);
String candidateCollectionName = buildCollectionNameFromValue(dataValue);
@@ -138,6 +138,14 @@ public class CategoryRoutedAlias implements RoutedAlias {
return;
}
+ // this check will become very important for future work
+ int infix = candidateCollectionName.indexOf(COLLECTION_INFIX);
+ int valueStart = infix + COLLECTION_INFIX.length();
+ if (candidateCollectionName.substring(valueStart).contains(COLLECTION_INFIX)) {
+ throw new SolrException(BAD_REQUEST, "No portion of the route value may resolve to the 7 character sequence " +
+ "__CRA__");
+ }
+
if (mustMatch != null && !mustMatch.matcher(candidateCollectionName).matches()) {
throw new SolrException(BAD_REQUEST, "Collection name " + candidateCollectionName
+ " does not match " + ROUTER_MUST_MATCH + ": " + mustMatch);
diff --git a/solr/core/src/test/org/apache/solr/update/processor/CategoryRoutedAliasUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/update/processor/CategoryRoutedAliasUpdateProcessorTest.java
index e84912e..813a326 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/CategoryRoutedAliasUpdateProcessorTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/CategoryRoutedAliasUpdateProcessorTest.java
@@ -203,6 +203,8 @@ public class CategoryRoutedAliasUpdateProcessorTest extends RoutedAliasUpdatePro
// make sure we fail if we have no value to route on.
testFailedDocument(newDoc(null), "Route value is null");
+ testFailedDocument(newDoc("foo__CRA__bar"), "7 character sequence __CRA__");
+ testFailedDocument(newDoc("fóóCRAóóbar"), "7 character sequence __CRA__");
}
@@ -464,7 +466,7 @@ public class CategoryRoutedAliasUpdateProcessorTest extends RoutedAliasUpdatePro
// if we have a TolerantUpdateProcessor then we see it there)
final Object errors = resp.getResponseHeader().get("errors"); // Tolerant URP
assertNotNull(errors);
- assertTrue(errors.toString().contains(errorMsg));
+ assertTrue("Expected to find " + errorMsg + " in errors: " + errors.toString(),errors.toString().contains(errorMsg));
} catch (SolrException e) {
assertTrue(e.getMessage().contains(errorMsg));
}