You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by an...@apache.org on 2016/12/22 17:58:44 UTC
[1/3] lucene-solr:branch_5x: Revert "SOLR-8677: Fix assert statement"
Repository: lucene-solr
Updated Branches:
refs/heads/branch_5x 8a13448c0 -> 297b193de
Revert "SOLR-8677: Fix assert statement"
This reverts commit e8acc04c68ac74ca5757285581c42457100c990c.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/7415d100
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/7415d100
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/7415d100
Branch: refs/heads/branch_5x
Commit: 7415d100ef09a9a10b45746ebb794452e288ca3a
Parents: 8a13448
Author: anshum <an...@apache.org>
Authored: Wed Dec 21 12:23:53 2016 -0800
Committer: anshum <an...@apache.org>
Committed: Wed Dec 21 12:23:53 2016 -0800
----------------------------------------------------------------------
.../solr/client/solrj/request/TestCollectionAdminRequest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/7415d100/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
index ce6a6aa..6fef14c 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
@@ -63,7 +63,7 @@ public class TestCollectionAdminRequest extends LuceneTestCase {
fail();
} catch (IllegalArgumentException e) {
final String exceptionMessage = e.getMessage();
- assertTrue(exceptionMessage.contains("Invalid alias"));
+ assertTrue(exceptionMessage.contains("Invalid collection"));
assertTrue(exceptionMessage.contains("invalid$alias@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, and alphanumerics"));
}
[2/3] lucene-solr:branch_5x: Revert "SOLR-8677: Fix broken build"
Posted by an...@apache.org.
Revert "SOLR-8677: Fix broken build"
This reverts commit 55162f2255a1f707603cc81134996cfb2a5968ec.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/69a8aa77
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/69a8aa77
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/69a8aa77
Branch: refs/heads/branch_5x
Commit: 69a8aa77e36216b329dc159c391ad2f0155de740
Parents: 7415d10
Author: anshum <an...@apache.org>
Authored: Wed Dec 21 12:24:09 2016 -0800
Committer: anshum <an...@apache.org>
Committed: Wed Dec 21 12:24:09 2016 -0800
----------------------------------------------------------------------
.../org/apache/solr/client/solrj/request/CoreAdminRequest.java | 4 ++--
.../org/apache/solr/client/solrj/request/TestCoreAdmin.java | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/69a8aa77/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
index c1f986e..2a2d4ae 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
@@ -111,7 +111,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> {
@Override
public void setCoreName(String coreName) {
if (!SolrIdentifierValidator.validateCoreName(coreName)) {
- throw new IllegalArgumentException("Invalid core: " + coreName
+ throw new IllegalArgumentException("Invalid collection: " + coreName
+ ". Core names must consist entirely of periods, underscores, and alphanumerics");
}
this.core = coreName;
@@ -560,7 +560,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> {
public static CoreAdminResponse renameCore(String coreName, String newName, SolrClient client )
throws SolrServerException, IOException {
if (!SolrIdentifierValidator.validateCoreName(newName)) {
- throw new IllegalArgumentException("Invalid core: " + newName
+ throw new IllegalArgumentException("Invalid collection: " + newName
+ ". Core names must consist entirely of periods, underscores, and alphanumerics");
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/69a8aa77/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
index 143d2c3..8275ff1 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
@@ -171,7 +171,7 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid core"));
assertTrue(exceptionMessage.contains("invalid$core@name"));
- assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, and alphanumerics"));
+ assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores and alphanumerics"));
}
}
@@ -182,9 +182,9 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
fail();
} catch (IllegalArgumentException e) {
final String exceptionMessage = e.getMessage();
- assertTrue(e.getMessage(), exceptionMessage.contains("Invalid core"));
+ assertTrue(exceptionMessage.contains("Invalid core"));
assertTrue(exceptionMessage.contains("invalid$core@name"));
- assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, and alphanumerics"));
+ assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores and alphanumerics"));
}
}
[3/3] lucene-solr:branch_5x: Revert "SOLR-8677: Restrict creation of
shards with invalid names"
Posted by an...@apache.org.
Revert "SOLR-8677: Restrict creation of shards with invalid names"
This reverts commit 96c01a2c885871f7d80beddc6e019547639ef71e.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/297b193d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/297b193d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/297b193d
Branch: refs/heads/branch_5x
Commit: 297b193dec2213dd48cc308ae59ddc0c4845d4d0
Parents: 69a8aa7
Author: anshum <an...@apache.org>
Authored: Wed Dec 21 13:30:20 2016 -0800
Committer: anshum <an...@apache.org>
Committed: Wed Dec 21 13:30:20 2016 -0800
----------------------------------------------------------------------
solr/CHANGES.txt | 3 -
.../org/apache/solr/core/CoreContainer.java | 12 +--
.../solr/handler/admin/CollectionsHandler.java | 29 +------
.../solr/util/SolrIdentifierValidator.java | 47 +++++++++++
.../apache/solr/cloud/TestCollectionAPI.java | 71 ++--------------
.../handler/admin/CoreAdminHandlerTest.java | 4 +-
.../solrj/request/CollectionAdminRequest.java | 79 ++----------------
.../client/solrj/request/CoreAdminRequest.java | 33 +-------
.../solrj/util/SolrIdentifierValidator.java | 50 ------------
.../request/TestCollectionAdminRequest.java | 85 --------------------
.../client/solrj/request/TestCoreAdmin.java | 38 +--------
11 files changed, 76 insertions(+), 375 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index ce538c7..4fff68f 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -25,9 +25,6 @@ Bug Fixes
Other Changes
----------------------
-* SOLR-8677: Prevent shards containing invalid characters from being created. Checks added server-side
- and in SolrJ. (Shai Erera, Jason Gerlowski, Anshum Gupta)
-
* SOLR-9819: Upgrade commons-fileupload to 1.3.2, fixing a potential vulnerability CVE-2016-3092 (Anshum Gupta)
======================= 5.5.3 =======================
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/core/src/java/org/apache/solr/core/CoreContainer.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index db8b270..0689b51 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -37,7 +37,6 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
-import org.apache.solr.client.solrj.util.SolrIdentifierValidator;
import org.apache.solr.cloud.Overseer;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.SolrException;
@@ -65,6 +64,7 @@ import org.apache.solr.security.PKIAuthenticationPlugin;
import org.apache.solr.security.SecurityPluginHolder;
import org.apache.solr.update.UpdateShardHandler;
import org.apache.solr.util.DefaultSolrThreadFactory;
+import org.apache.solr.util.SolrIdentifierValidator;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -810,10 +810,7 @@ public class CoreContainer {
SolrCore core = null;
try {
MDCLoggingContext.setCore(core);
- if (!SolrIdentifierValidator.validateCoreName(dcore.getName())) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid core: " + dcore.getName()
- + ". Core names must consist entirely of periods, underscores, and alphanumerics");
- }
+ SolrIdentifierValidator.validateCoreName(dcore.getName());
if (zkSys.getZkController() != null) {
zkSys.getZkController().preRegister(dcore);
}
@@ -1015,10 +1012,7 @@ public class CoreContainer {
}
public void rename(String name, String toName) {
- if(!SolrIdentifierValidator.validateCoreName(toName)) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid core: " + toName
- + ". Core names must consist entirely of periods, underscores, and alphanumerics");
- }
+ SolrIdentifierValidator.validateCoreName(toName);
try (SolrCore core = getCore(name)) {
if (core != null) {
registerCore(toName, core, true);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
index b4a1581..739cd4d 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
@@ -69,7 +69,6 @@ import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest.RequestSyncShard;
import org.apache.solr.client.solrj.response.RequestStatusState;
-import org.apache.solr.client.solrj.util.SolrIdentifierValidator;
import org.apache.solr.cloud.DistributedMap;
import org.apache.solr.cloud.Overseer;
import org.apache.solr.cloud.OverseerCollectionMessageHandler;
@@ -110,6 +109,7 @@ import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.handler.component.ShardHandler;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.util.SolrIdentifierValidator;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
@@ -347,14 +347,7 @@ public class CollectionsHandler extends RequestHandlerBase {
addMapObject(props, SNITCH);
verifyRuleParams(h.coreContainer, props);
final String collectionName = (String) props.get(NAME);
- if (!SolrIdentifierValidator.validateCollectionName(collectionName)) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid collection: " + collectionName
- + ". Collection names must consist entirely of periods, underscores, and alphanumerics");
- }
- final String shardsParam = (String) props.get(SHARDS_PROP);
- if (StringUtils.isNotEmpty(shardsParam)) {
- verifyShardsParam(shardsParam);
- }
+ SolrIdentifierValidator.validateCollectionName(collectionName);
if (SYSTEM_COLL.equals(collectionName)) {
//We must always create a .system collection with only a single shard
props.put(NUM_SLICES, 1);
@@ -426,10 +419,7 @@ public class CollectionsHandler extends RequestHandlerBase {
Map<String, Object> call(SolrQueryRequest req, SolrQueryResponse rsp, CollectionsHandler handler)
throws Exception {
final String aliasName = req.getParams().get(NAME);
- if (!SolrIdentifierValidator.validateCollectionName(aliasName)) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid alias: " + aliasName
- + ". Aliases must consist entirely of periods, underscores, and alphanumerics");
- }
+ SolrIdentifierValidator.validateCollectionName(aliasName);
return req.getParams().required().getAll(null, NAME, "collections");
}
},
@@ -493,11 +483,6 @@ public class CollectionsHandler extends RequestHandlerBase {
COLLECTION_PROP,
SHARD_ID_PROP);
ClusterState clusterState = handler.coreContainer.getZkController().getClusterState();
- final String newShardName = req.getParams().get(SHARD_ID_PROP);
- if (!SolrIdentifierValidator.validateShardName(newShardName)) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid shard: " + newShardName
- + ". Shard names must consist entirely of periods, underscores, and alphanumerics");
- }
if (!ImplicitDocRouter.NAME.equals(((Map) clusterState.getCollection(req.getParams().get(COLLECTION_PROP)).get(DOC_ROUTER)).get(NAME)))
throw new SolrException(ErrorCode.BAD_REQUEST, "shards can be added only to 'implicit' collections");
req.getParams().getAll(map,
@@ -989,14 +974,6 @@ public class CollectionsHandler extends RequestHandlerBase {
}
return props;
}
-
- private static void verifyShardsParam(String shardsParam) {
- for (String shard : shardsParam.split(",")) {
- if (!SolrIdentifierValidator.validateShardName(shard))
- throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid shard: " + shard
- + ". Shard names must consist entirely of periods, underscores, and alphanumerics");;
- }
- }
public static final List<String> MODIFIABLE_COLL_PROPS = ImmutableList.of(
RULE,
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/core/src/java/org/apache/solr/util/SolrIdentifierValidator.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/SolrIdentifierValidator.java b/solr/core/src/java/org/apache/solr/util/SolrIdentifierValidator.java
new file mode 100644
index 0000000..dc8301f
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/util/SolrIdentifierValidator.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.util;
+
+import java.lang.invoke.MethodHandles;
+import java.util.regex.Pattern;
+
+import org.apache.solr.common.SolrException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Ensures that provided identifiers align with Solr's recommendations/requirements for choosing
+ * collection, core, etc identifiers.
+ *
+ * Identifiers are allowed to contain underscores, periods, hyphens, and alphanumeric characters.
+ */
+public class SolrIdentifierValidator {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ final static Pattern identifierPattern = Pattern.compile("^[\\._A-Za-z0-9]*$");
+
+ public static void validateCollectionName(String collectionName) throws SolrException {
+ validateCoreName(collectionName);
+ }
+
+ public static void validateCoreName(String name) throws SolrException {
+ if (name == null || !identifierPattern.matcher(name).matches()) {
+ log.info("Validation failed on the invalid identifier [{}]. Throwing SolrException to indicate a BAD REQUEST.", name);
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+ "Invalid name: '" + name + "' Identifiers must consist entirely of periods, underscores and alphanumerics");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
index 304890c..c3b2a7a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
@@ -44,7 +44,6 @@ import org.apache.solr.common.util.NamedList;
import org.apache.zookeeper.KeeperException;
import org.junit.Test;
-import static org.apache.solr.cloud.OverseerCollectionMessageHandler.ROUTER;
import static org.apache.solr.cloud.OverseerCollectionMessageHandler.SHARD_UNIQUE;
public class TestCollectionAPI extends ReplicaPropertiesBase {
@@ -81,10 +80,8 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
replicaPropTest();
clusterStatusZNodeVersion();
testClusterStateMigration();
- testCollectionCreationCollectionNameValidation();
- testCollectionCreationShardNameValidation();
+ testCollectionCreationNameValidation();
testAliasCreationNameValidation();
- testShardCreationNameValidation();
}
private void clusterStatusWithCollectionAndShard() throws IOException, SolrServerException {
@@ -653,7 +650,7 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
}
}
- private void testCollectionCreationCollectionNameValidation() throws Exception {
+ private void testCollectionCreationNameValidation() throws Exception {
try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CREATE.toString());
@@ -666,32 +663,9 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
fail();
} catch (RemoteSolrException e) {
final String errorMessage = e.getMessage();
- assertTrue(errorMessage.contains("Invalid collection"));
+ assertTrue(errorMessage.contains("Invalid name"));
assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
- assertTrue(errorMessage.contains("Collection names must consist entirely of"));
- }
- }
- }
-
- private void testCollectionCreationShardNameValidation() throws Exception {
- try (CloudSolrClient client = createCloudClient(null)) {
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("action", CollectionParams.CollectionAction.CREATE.toString());
- params.set("name", "valid_collection_name");
- params.set("router.name", "implicit");
- params.set("numShards", "1");
- params.set("shards", "invalid@name#with$weird%characters");
- SolrRequest request = new QueryRequest(params);
- request.setPath("/admin/collections");
-
- try {
- client.request(request);
- fail();
- } catch (RemoteSolrException e) {
- final String errorMessage = e.getMessage();
- assertTrue(errorMessage.contains("Invalid shard"));
- assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
- assertTrue(errorMessage.contains("Shard names must consist entirely of"));
+ assertTrue(errorMessage.contains("Identifiers must consist entirely of"));
}
}
}
@@ -710,42 +684,9 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
fail();
} catch (RemoteSolrException e) {
final String errorMessage = e.getMessage();
- assertTrue(errorMessage.contains("Invalid alias"));
- assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
- assertTrue(errorMessage.contains("Aliases must consist entirely of"));
- }
- }
- }
-
- private void testShardCreationNameValidation() throws Exception {
- try (CloudSolrClient client = createCloudClient(null)) {
- client.connect();
- // Create a collection w/ implicit router
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("action", CollectionParams.CollectionAction.CREATE.toString());
- params.set("name", "valid_collection_name");
- params.set("shards", "a");
- params.set("router.name", "implicit");
- SolrRequest request = new QueryRequest(params);
- request.setPath("/admin/collections");
- client.request(request);
-
- params = new ModifiableSolrParams();
- params.set("action", CollectionParams.CollectionAction.CREATESHARD.toString());
- params.set("collection", "valid_collection_name");
- params.set("shard", "invalid@name#with$weird%characters");
-
- request = new QueryRequest(params);
- request.setPath("/admin/collections");
-
- try {
- client.request(request);
- fail();
- } catch (RemoteSolrException e) {
- final String errorMessage = e.getMessage();
- assertTrue(errorMessage.contains("Invalid shard"));
+ assertTrue(errorMessage.contains("Invalid name"));
assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
- assertTrue(errorMessage.contains("Shard names must consist entirely of"));
+ assertTrue(errorMessage.contains("Identifiers must consist entirely of"));
}
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
index 89f4b2b..2159325 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
@@ -139,7 +139,7 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
resp);
} catch (SolrException se) {
- assertTrue("Expected error message for bad core name.", se.toString().contains("Invalid core"));
+ assertTrue("Expected error message for bad core name.", se.toString().contains("Invalid name"));
}
CoreDescriptor cd = cores.getCoreDescriptor("ugly$core=name");
assertNull("Should NOT have added this core!", cd);
@@ -228,7 +228,7 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
CoreAdminParams.OTHER, "bad$name"),
resp);
} catch (SolrException e) { // why the heck does create return a SolrException (admittedly wrapping an IAE)
- assertTrue("Expected error message for bad core name.", e.getMessage().contains("Invalid core"));
+ assertTrue("Expected error message for bad core name.", e.getMessage().contains("Invalid name"));
}
cd = cores.getCoreDescriptor("bad$name");
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
index 441be5d..e3446f7 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
@@ -16,16 +16,9 @@
*/
package org.apache.solr.client.solrj.request;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
-import org.apache.solr.client.solrj.util.SolrIdentifierValidator;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.ZkStateReader;
@@ -38,6 +31,12 @@ import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ContentStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
/**
* This class is experimental and subject to change.
*
@@ -123,7 +122,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
protected abstract static class CollectionSpecificAdminRequest <T extends CollectionAdminRequest<T>> extends CollectionAdminRequest<T> {
protected String collection = null;
- public T setCollectionName(String collectionName) {
+ public final T setCollectionName(String collectionName) {
this.collection = collectionName;
return getThis();
}
@@ -278,6 +277,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
public Create setConfigName(String config) { this.configName = config; return this; }
public Create setCreateNodeSet(String nodeSet) { this.createNodeSet = nodeSet; return this; }
public Create setRouterName(String routerName) { this.routerName = routerName; return this; }
+ public Create setShards(String shards) { this.shards = shards; return this; }
public Create setRouterField(String routerField) { this.routerField = routerField; return this; }
public Create setNumShards(Integer numShards) {this.numShards = numShards; return this; }
public Create setMaxShardsPerNode(Integer numShards) { this.maxShardsPerNode = numShards; return this; }
@@ -296,41 +296,6 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
public Integer getReplicationFactor() { return replicationFactor; }
public Boolean getAutoAddReplicas() { return autoAddReplicas; }
public Integer getStateFormat() { return stateFormat; }
-
- /**
- * Provide the name of the shards to be created, separated by commas
- *
- * Shard names must consist entirely of periods, underscores, and alphanumerics. Other characters are not allowed.
- *
- * @throws IllegalArgumentException if any of the shard names contain invalid characters.
- */
- public Create setShards(String shards) {
- for (String shard : shards.split(",")) {
- if (!SolrIdentifierValidator.validateShardName(shard)) {
- throw new IllegalArgumentException("Invalid shard: " + shard
- + ". Shard names must consist entirely of periods, underscores, and alphanumerics");
- }
- }
- this.shards = shards;
- return this;
- }
-
- /**
- * Provide the name of the collection to be created.
- *
- * Collection names must consist entirely of periods, underscores and alphanumerics. Other characters are not allowed.
- *
- * @throws IllegalArgumentException if the collection name contains invalid characters.
- */
- @Override
- public Create setCollectionName(String collectionName) throws SolrException {
- if (!SolrIdentifierValidator.validateCollectionName(collectionName)) {
- throw new IllegalArgumentException("Invalid collection: " + collectionName
- + ". Collection names must consist entirely of periods, underscores, and alphanumerics");
- }
- this.collection = collectionName;
- return this;
- }
public Properties getProperties() {
return properties;
@@ -444,23 +409,6 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
public CreateShard() {
action = CollectionAction.CREATESHARD;
}
-
- /**
- * Provide the name of the shard to be created.
- *
- * Shard names must consist entirely of periods, underscores, and alphanumerics. Other characters are not allowed.
- *
- * @throws IllegalArgumentException if the shard name contains invalid characters.
- */
- @Override
- public CreateShard setShardName(String shardName) {
- if (!SolrIdentifierValidator.validateShardName(shardName)) {
- throw new IllegalArgumentException("Invalid shard: " + shardName
- + ". Shard names must consist entirely of periods, underscores, and alphanumerics");
- }
- this.shardName = shardName;
- return this;
- }
@Override
public SolrParams getParams() {
@@ -640,18 +588,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
action = CollectionAction.CREATEALIAS;
}
- /**
- * Provide the name of the alias to be created.
- *
- * Alias names must consist entirely of periods, underscores and alphanumerics. Other characters are not allowed.
- *
- * @throws IllegalArgumentException if the alias name contains invalid characters.
- */
public CreateAlias setAliasName(String aliasName) {
- if (!SolrIdentifierValidator.validateCollectionName(aliasName)) {
- throw new IllegalArgumentException("Invalid alias: " + aliasName
- + ". Aliases must consist entirely of periods, underscores, and alphanumerics");
- }
this.aliasName = aliasName;
return this;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
index 2a2d4ae..188a9ea 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
@@ -20,7 +20,6 @@ import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
-import org.apache.solr.client.solrj.util.SolrIdentifierValidator;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CoreAdminParams;
@@ -101,22 +100,6 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> {
public Boolean getIsTransient() { return isTransient; }
public String getCollectionConfigName() { return collectionConfigName;}
- /**
- * Provide the name of the core to be created.
- *
- * Core names must consist entirely of periods, underscores and alphanumerics. Other characters are not allowed.
- *
- * @throws IllegalArgumentException if the core name contains invalid characters.
- */
- @Override
- public void setCoreName(String coreName) {
- if (!SolrIdentifierValidator.validateCoreName(coreName)) {
- throw new IllegalArgumentException("Invalid collection: " + coreName
- + ". Core names must consist entirely of periods, underscores, and alphanumerics");
- }
- this.core = coreName;
- }
-
@Override
public SolrParams getParams() {
if( action == null ) {
@@ -467,7 +450,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> {
super( METHOD.GET, path );
}
- public void setCoreName( String coreName )
+ public final void setCoreName( String coreName )
{
this.core = coreName;
}
@@ -552,18 +535,8 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> {
return req.process(client);
}
- /**
- * Rename an existing core.
- *
- * @throws IllegalArgumentException if the new core name contains invalid characters.
- */
- public static CoreAdminResponse renameCore(String coreName, String newName, SolrClient client )
- throws SolrServerException, IOException {
- if (!SolrIdentifierValidator.validateCoreName(newName)) {
- throw new IllegalArgumentException("Invalid collection: " + newName
- + ". Core names must consist entirely of periods, underscores, and alphanumerics");
- }
-
+ public static CoreAdminResponse renameCore(String coreName, String newName, SolrClient client ) throws SolrServerException, IOException
+ {
CoreAdminRequest req = new CoreAdminRequest();
req.setCoreName(coreName);
req.setOtherCoreName(newName);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/solrj/src/java/org/apache/solr/client/solrj/util/SolrIdentifierValidator.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/util/SolrIdentifierValidator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/util/SolrIdentifierValidator.java
deleted file mode 100644
index 4750b29..0000000
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/util/SolrIdentifierValidator.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.client.solrj.util;
-
-import java.util.regex.Pattern;
-
-/**
- * Ensures that provided identifiers align with Solr's recommendations/requirements for choosing
- * collection, core, etc identifiers.
- *
- * Identifiers are allowed to contain underscores, periods, hyphens, and alphanumeric characters.
- */
-public class SolrIdentifierValidator {
- final static Pattern identifierPattern = Pattern.compile("^(?!\\\\-)[\\\\._A-Za-z0-9\\\\-]+$");
-
- public static boolean validateShardName(String shardName) {
- return validateIdentifier(shardName);
- }
-
- public static boolean validateCollectionName(String collectionName) {
- return validateIdentifier(collectionName);
- }
-
- public static boolean validateCoreName(String name) {
- return validateIdentifier(name);
- }
-
- private static boolean validateIdentifier(String identifier) {
- if (identifier == null || ! identifierPattern.matcher(identifier).matches()) {
- return false;
- }
- return true;
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
deleted file mode 100644
index 6fef14c..0000000
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.client.solrj.request;
-
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest.Create;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest.CreateAlias;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest.CreateShard;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link CollectionAdminRequest}.
- */
-public class TestCollectionAdminRequest extends LuceneTestCase {
-
- @Test
- public void testInvalidCollectionNameRejectedWhenCreatingCollection() {
- final Create createRequest = new Create();
- try {
- createRequest.setCollectionName("invalid$collection@name");
- fail();
- } catch (IllegalArgumentException e) {
- final String exceptionMessage = e.getMessage();
- assertTrue(exceptionMessage.contains("Invalid collection"));
- assertTrue(exceptionMessage.contains("invalid$collection@name"));
- assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, and alphanumerics"));
- }
- }
-
- @Test
- public void testInvalidShardNamesRejectedWhenCreatingCollection() {
- final Create createRequest = new Create();
- try {
- createRequest.setShards("invalid$shard@name");
- fail();
- } catch (IllegalArgumentException e) {
- final String exceptionMessage = e.getMessage();
- assertTrue(exceptionMessage.contains("Invalid shard"));
- assertTrue(exceptionMessage.contains("invalid$shard@name"));
- assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, and alphanumerics"));
- }
- }
-
- @Test
- public void testInvalidAliasNameRejectedWhenCreatingAlias() {
- final CreateAlias createAliasRequest = new CreateAlias();
- try {
- createAliasRequest.setAliasName("invalid$alias@name");
- fail();
- } catch (IllegalArgumentException e) {
- final String exceptionMessage = e.getMessage();
- assertTrue(exceptionMessage.contains("Invalid collection"));
- assertTrue(exceptionMessage.contains("invalid$alias@name"));
- assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, and alphanumerics"));
- }
- }
-
- @Test
- public void testInvalidShardNameRejectedWhenCreatingShard() {
- final CreateShard createShardRequest = new CreateShard();
- try {
- createShardRequest.setShardName("invalid$shard@name");
- fail();
- } catch (IllegalArgumentException e) {
- final String exceptionMessage = e.getMessage();
- assertTrue(exceptionMessage.contains("Invalid shard"));
- assertTrue(exceptionMessage.contains("invalid$shard@name"));
- assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, and alphanumerics"));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b193d/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
index 8275ff1..4e46373 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
@@ -16,19 +16,17 @@
*/
package org.apache.solr.client.solrj.request;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.core.Is.is;
-
import java.io.File;
import java.lang.invoke.MethodHandles;
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrIgnoredThreadsFilter;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.embedded.AbstractEmbeddedSolrServerTestCase;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
-import org.apache.solr.client.solrj.request.CoreAdminRequest.Create;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.ModifiableSolrParams;
@@ -43,8 +41,8 @@ import org.junit.rules.TestRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.core.Is.is;
@ThreadLeakFilters(defaultFilters = true, filters = {SolrIgnoredThreadsFilter.class})
public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
@@ -160,34 +158,6 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
assertTrue(gotExp);
}
- @Test
- public void testInvalidCoreNamesAreRejectedWhenCreatingCore() {
- final Create createRequest = new Create();
-
- try {
- createRequest.setCoreName("invalid$core@name");
- fail();
- } catch (IllegalArgumentException e) {
- final String exceptionMessage = e.getMessage();
- assertTrue(exceptionMessage.contains("Invalid core"));
- assertTrue(exceptionMessage.contains("invalid$core@name"));
- assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores and alphanumerics"));
- }
- }
-
- @Test
- public void testInvalidCoreNamesAreRejectedWhenRenamingExistingCore() throws Exception {
- try {
- CoreAdminRequest.renameCore("validExistingCoreName", "invalid$core@name", null);
- fail();
- } catch (IllegalArgumentException e) {
- final String exceptionMessage = e.getMessage();
- assertTrue(exceptionMessage.contains("Invalid core"));
- assertTrue(exceptionMessage.contains("invalid$core@name"));
- assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores and alphanumerics"));
- }
- }
-
@BeforeClass
public static void before() {
// wtf?