Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C3C56200CBD for ; Wed, 31 May 2017 19:01:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C2115160BCB; Wed, 31 May 2017 17:01:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B4BD6160BE6 for ; Wed, 31 May 2017 19:01:07 +0200 (CEST) Received: (qmail 30615 invoked by uid 500); 31 May 2017 17:01:06 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 30358 invoked by uid 99); 31 May 2017 17:01:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 May 2017 17:01:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 93657E03B3; Wed, 31 May 2017 17:01:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.apache.org Date: Wed, 31 May 2017 17:01:15 -0000 Message-Id: <9d22e8852ada4beda761ddb14eec5a32@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [10/32] geode git commit: GEODE-2950: Adding validation checks on create lucene index parameter names archived-at: Wed, 31 May 2017 17:01:08 -0000 GEODE-2950: Adding validation checks on create lucene index parameter names This closes #532 Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/c793f74c Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/c793f74c Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/c793f74c Branch: refs/heads/feature/GEODE-1279 Commit: c793f74c07c3488ba188ed927144be688bd50b19 Parents: 0dae918 Author: David Anuta Authored: Wed May 24 16:21:33 2017 -0700 Committer: nabarun Committed: Thu May 25 11:20:56 2017 -0700 ---------------------------------------------------------------------- .../lucene/internal/LuceneServiceImpl.java | 15 ++++++++---- .../functions/LuceneCreateIndexFunction.java | 6 +++-- .../cli/LuceneIndexCommandsDUnitTest.java | 25 ++++++++++++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/c793f74c/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java ---------------------------------------------------------------------- diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java index 3859804..c0d6266 100644 --- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java +++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java @@ -128,7 +128,7 @@ public class LuceneServiceImpl implements InternalLuceneService { return getUniqueIndexName(indexName, regionPath) + regionSuffix; } - public static void validateRegionName(String name) { + public static void validateCreateIndexCommandParams(String name, boolean isRegionPath) { if (name == null) { throw new IllegalArgumentException( LocalizedStrings.LocalRegion_NAME_CANNOT_BE_NULL.toLocalizedString()); @@ -140,15 +140,22 @@ public class LuceneServiceImpl implements InternalLuceneService { if (name.startsWith("__")) { throw new IllegalArgumentException( - "Region names may not begin with a double-underscore: " + name); + "Parameter names may not begin with a double-underscore: " + name); + } + + final Pattern NAME_PATTERN; + if (isRegionPath) { + NAME_PATTERN = Pattern.compile("[aA-zZ0-9-_./]+"); + } else { + NAME_PATTERN = Pattern.compile("[aA-zZ0-9-_.]+"); } - final Pattern NAME_PATTERN = Pattern.compile("[aA-zZ0-9-_./]+"); // Ensure the region only contains valid characters Matcher matcher = NAME_PATTERN.matcher(name); if (!matcher.matches()) { throw new IllegalArgumentException( - "Region names may only be alphanumeric and may contain hyphens or underscores: " + name); + "Parameter names may only be alphanumeric, though they can contain hyphens or underscores: " + + name); } } http://git-wip-us.apache.org/repos/asf/geode/blob/c793f74c/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java ---------------------------------------------------------------------- diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java index 422b1ef..26ac0e2 100644 --- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java +++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java @@ -15,7 +15,7 @@ package org.apache.geode.cache.lucene.internal.cli.functions; -import static org.apache.geode.cache.lucene.internal.LuceneServiceImpl.validateRegionName; +import static org.apache.geode.cache.lucene.internal.LuceneServiceImpl.validateCreateIndexCommandParams; import org.apache.commons.lang.StringUtils; import org.apache.geode.cache.Cache; @@ -67,6 +67,8 @@ public class LuceneCreateIndexFunction extends FunctionAdapter implements Intern memberId = cache.getDistributedSystem().getDistributedMember().getId(); LuceneService service = LuceneServiceProvider.get(cache); + validateCreateIndexCommandParams(indexInfo.getIndexName(), false); + String[] fields = indexInfo.getSearchableFieldNames(); String[] analyzerName = indexInfo.getFieldAnalyzers(); @@ -84,7 +86,7 @@ public class LuceneCreateIndexFunction extends FunctionAdapter implements Intern } } - validateRegionName(indexInfo.getRegionPath()); + validateCreateIndexCommandParams(indexInfo.getRegionPath(), true); indexFactory.create(indexInfo.getIndexName(), indexInfo.getRegionPath()); // TODO - update cluster configuration by returning a valid XmlEntity http://git-wip-us.apache.org/repos/asf/geode/blob/c793f74c/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java index 04359a3..5e9c4f9 100755 --- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java +++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java @@ -198,7 +198,7 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase { } @Test - public void createIndexShouldNotAcceptEmptyRegionNames() { + public void createIndexShouldNotAcceptBadIndexOrRegionNames() { final VM vm1 = Host.getHost(0).getVM(-1); vm1.invoke(() -> { getCache(); @@ -210,7 +210,7 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase { csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3"); String resultAsString = executeCommandAndLogResult(csb); - assertTrue(resultAsString.contains("Region names may not begin with a double-underscore:")); + assertTrue(resultAsString.contains("Parameter names may not begin with a double-underscore:")); csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX); csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME); @@ -218,8 +218,25 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase { csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3"); resultAsString = executeCommandAndLogResult(csb); - assertTrue(resultAsString - .contains("Region names may only be alphanumeric and may contain hyphens or underscores:")); + assertTrue(resultAsString.contains( + "Parameter names may only be alphanumeric, though they can contain hyphens or underscores:")); + + csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX); + csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, "\'__\'"); + csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME); + csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3"); + + resultAsString = executeCommandAndLogResult(csb); + assertTrue(resultAsString.contains("Parameter names may not begin with a double-underscore:")); + + csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX); + csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, "\' @@@*%\'"); + csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME); + csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3"); + + resultAsString = executeCommandAndLogResult(csb); + assertTrue(resultAsString.contains( + "Parameter names may only be alphanumeric, though they can contain hyphens or underscores:")); } @Test